Ignore:
Timestamp:
Feb 13, 2012, 12:26:12 PM (13 years ago)
Author:
chronos
Message:
  • Fixed: Compile and run C project using MinGW gcc.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        44backup
        55LazFuckIDE
         6compiled
  • trunk/Compiler/UCompiler.pas

    r25 r28  
    66
    77uses
    8   Classes, SysUtils, StrUtils, Registry, URegistry, SpecializedList;
     8  Classes, SysUtils, StrUtils, Registry, URegistry, SpecializedList,
     9  FileUtil, Process;
    910
    1011type
     
    2627    SourceExtension: string;
    2728    CompiledExtension: string;
     29    ProjectFileName: string;
    2830    constructor Create; virtual;
    2931    procedure OptimizeSource;
    3032    procedure Compile; virtual;
     33    procedure CompileToFile; virtual;
     34    procedure Run; virtual;
    3135  end;
    3236
     
    3943
    4044
     45resourcestring
     46  SCompilerNotFound = 'Compiler "%s" not found';
     47  SCompiledFileNotFound = 'Program compiled file "%s" not found';
     48
     49
    4150implementation
     51
    4252
    4353{ TCompilerList }
     
    99109end;
    100110
     111procedure TBrainFuckCompiler.CompileToFile;
     112var
     113  Process: TProcess;
     114  CompiledFile: string;
     115begin
     116  CompiledFile := ExtractFilePath(ProjectFileName) +
     117    'compiled' + DirectorySeparator + Name + DirectorySeparator +
     118    ExtractFileNameOnly(ProjectFileName) + SourceExtension;
     119  ForceDirectoriesUTF8(ExtractFilePath(CompiledFile));
     120  with TStringList.Create do
     121  try
     122    Text := Output;
     123    SaveToFile(CompiledFile);
     124  finally
     125    Free;
     126  end;
     127  if FileExistsUTF8(CompilerPath) then
     128  try
     129    Process := TProcess.Create(nil);
     130    Process.CurrentDirectory := ExtractFilePath(CompilerPath);
     131    Process.CommandLine := '"' + CompilerPath + '" "' + CompiledFile + '"';
     132    Process.Options := [poWaitOnExit];
     133    Process.Execute;
     134  finally
     135    Process.Free;
     136  end else raise Exception.Create(Format(SCompilerNotFound, [CompilerPath]));
     137end;
     138
     139procedure TBrainFuckCompiler.Run;
     140var
     141  CompiledFile: string;
     142  Process: TProcess;
     143begin
     144  CompiledFile := ExtractFilePath(ProjectFileName) +
     145    'compiled' + DirectorySeparator + Name + DirectorySeparator +
     146    ExtractFileNameOnly(ProjectFileName) + CompiledExtension;
     147  if FileExistsUTF8(CompiledFile) then
     148  try
     149    Process := TProcess.Create(nil);
     150    Process.CommandLine := '"' + CompiledFile + '"';
     151    Process.Options := [poWaitOnExit];
     152    Process.Execute;
     153  finally
     154    Process.Free;
     155  end else raise Exception.Create(Format(SCompiledFileNotFound, [CompiledFile]));
     156end;
     157
    101158
    102159
Note: See TracChangeset for help on using the changeset viewer.