Ignore:
Timestamp:
Aug 20, 2024, 12:20:49 AM (5 weeks ago)
Author:
chronos
Message:
  • Fixed: All targets compilation and run.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/TargetC.pas

    r146 r161  
    1515    function GetMemoryCell: string;
    1616  public
     17    function GetCompileParams: TStringArray; override;
    1718    constructor Create; override;
    1819    procedure Compile; override;
    19     procedure CompileToFile; override;
    2020    procedure Run; override;
    2121  end;
     
    2323
    2424implementation
     25
     26uses
     27  Common;
    2528
    2629{ TTargetC }
     
    3639  CompilerPath := 'c:\Program Files\MinGW\bin\gcc.exe';
    3740  FCompiledExtension := '.exe';
    38   FRunExtension := '';
    3941  {$ENDIF}
    4042  {$IFDEF UNIX}
    4143  CompilerPath := '/usr/bin/gcc';
    4244  FCompiledExtension := '';
    43   FRunExtension := '';
    4445  {$ENDIF}
    4546end;
     
    5354    Result := Result + ' - ' + IntToStr(Abs(FProgram[FProgramIndex].RelIndex));
    5455  Result := Result + ']';
     56end;
     57
     58function TTargetC.GetCompileParams: TStringArray;
     59begin
     60  Result := [GetSourceFileName, '-o', GetCompileFileName];
    5561end;
    5662
     
    101107end;
    102108
    103 procedure TTargetC.CompileToFile;
    104 var
    105   Process: TProcess;
    106   CompiledFile: string;
    107 begin
    108   CompiledFile := ExtractFilePath(ProjectFileName) +
    109     CompiledDir + DirectorySeparator + Name + DirectorySeparator +
    110     ExtractFileNameOnly(ProjectFileName) + SourceExtension;
    111   ForceDirectoriesUTF8(ExtractFilePath(CompiledFile));
    112   with TStringList.Create do
    113   try
    114     Text := FTargetCode;
    115     SaveToFile(CompiledFile);
    116   finally
    117     Free;
    118   end;
    119   if FileExistsUTF8(CompilerPath) then
    120   try
    121     Process := TProcess.Create(nil);
    122     Process.CurrentDirectory := ExtractFilePath(CompilerPath);
    123     Process.Executable := LongFileName(CompilerPath);
    124     Process.Parameters.Add(LongFileName(CompiledFile));
    125     Process.Parameters.Add('-o');
    126     Process.Parameters.Add(LongFileName(ExtractFilePath(CompiledFile) + ExtractFileNameOnly(CompiledFile) + CompiledExtension));
    127     Process.Options := [poWaitOnExit];
    128     Process.Execute;
    129   finally
    130     Process.Free;
    131   end else raise Exception.Create(Format(SCompilerNotFound, [CompilerPath]));
    132 end;
    133 
    134109procedure TTargetC.Run;
    135110begin
Note: See TracChangeset for help on using the changeset viewer.