|
@@ -40,8 +40,7 @@ const
|
|
|
AsmOutSize=32768;
|
|
|
|
|
|
type
|
|
|
- PAsmList=^TAsmList;
|
|
|
- TAsmList=object
|
|
|
+ TAssembler=class
|
|
|
private
|
|
|
procedure CreateSmartLinkPath(const s:string);
|
|
|
public
|
|
@@ -49,25 +48,30 @@ type
|
|
|
path : pathstr;
|
|
|
name : namestr;
|
|
|
asmfile, { current .s and .o file }
|
|
|
- objfile,
|
|
|
- as_bin : string;
|
|
|
+ objfile : string;
|
|
|
SmartAsm : boolean;
|
|
|
SmartFilesCount,
|
|
|
SmartHeaderCount : longint;
|
|
|
- place : TCutPlace; { special 'end' file for import dir ? }
|
|
|
+ Constructor Create(smart:boolean);
|
|
|
+ Destructor Destroy;override;
|
|
|
+ procedure WriteTree(p:TAAsmoutput);virtual;
|
|
|
+ procedure WriteAsmList;virtual;
|
|
|
+ procedure NextSmartName(place:tcutplace);
|
|
|
+ end;
|
|
|
+
|
|
|
+ TExternalAssembler=class(TAssembler)
|
|
|
+ protected
|
|
|
{outfile}
|
|
|
AsmSize,
|
|
|
AsmStartSize,
|
|
|
outcnt : longint;
|
|
|
outbuf : array[0..AsmOutSize-1] of char;
|
|
|
outfile : file;
|
|
|
- Constructor Init(smart:boolean);
|
|
|
- Destructor Done;
|
|
|
+ public
|
|
|
Function FindAssembler:string;
|
|
|
Function CallAssembler(const command,para:string):Boolean;
|
|
|
Function DoAssemble:boolean;
|
|
|
Procedure RemoveAsm;
|
|
|
- procedure NextSmartName;
|
|
|
Procedure AsmFlush;
|
|
|
Procedure AsmClear;
|
|
|
Procedure AsmWrite(const s:string);
|
|
@@ -77,8 +81,8 @@ type
|
|
|
procedure AsmCreate(Aplace:tcutplace);
|
|
|
procedure AsmClose;
|
|
|
procedure Synchronize;
|
|
|
- procedure WriteTree(p:TAAsmoutput);virtual;
|
|
|
- procedure WriteAsmList;virtual;
|
|
|
+ public
|
|
|
+ Constructor Create(smart:boolean);
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -132,7 +136,107 @@ uses
|
|
|
|
|
|
|
|
|
{*****************************************************************************
|
|
|
- TAsmList
|
|
|
+ TAssembler
|
|
|
+*****************************************************************************}
|
|
|
+
|
|
|
+Constructor TAssembler.Create(smart:boolean);
|
|
|
+begin
|
|
|
+{ load start values }
|
|
|
+ asmfile:=current_module.asmfilename^;
|
|
|
+ objfile:=current_module.objfilename^;
|
|
|
+ name:=FixFileName(current_module.modulename^);
|
|
|
+ SmartAsm:=smart;
|
|
|
+ SmartFilesCount:=0;
|
|
|
+ SmartHeaderCount:=0;
|
|
|
+ SmartLinkOFiles.Clear;
|
|
|
+{ Which path will be used ? }
|
|
|
+ if SmartAsm then
|
|
|
+ begin
|
|
|
+ path:=current_module.outputpath^+FixFileName(current_module.modulename^)+target_info.smartext;
|
|
|
+ CreateSmartLinkPath(path);
|
|
|
+ path:=FixPath(path,false);
|
|
|
+ end
|
|
|
+ else
|
|
|
+ path:=current_module.outputpath^;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+Destructor TAssembler.Destroy;
|
|
|
+begin
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+procedure TAssembler.WriteTree(p:TAAsmoutput);
|
|
|
+begin
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+procedure TAssembler.WriteAsmList;
|
|
|
+begin
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+procedure TAssembler.CreateSmartLinkPath(const s:string);
|
|
|
+var
|
|
|
+ dir : searchrec;
|
|
|
+begin
|
|
|
+ if PathExists(s) then
|
|
|
+ begin
|
|
|
+ { the path exists, now we clean only all the .o and .s files }
|
|
|
+ { .o files }
|
|
|
+ findfirst(s+dirsep+'*'+target_info.objext,anyfile,dir);
|
|
|
+ while (doserror=0) do
|
|
|
+ begin
|
|
|
+ RemoveFile(s+dirsep+dir.name);
|
|
|
+ findnext(dir);
|
|
|
+ end;
|
|
|
+ findclose(dir);
|
|
|
+ { .s files }
|
|
|
+ findfirst(s+dirsep+'*'+target_info.asmext,anyfile,dir);
|
|
|
+ while (doserror=0) do
|
|
|
+ begin
|
|
|
+ RemoveFile(s+dirsep+dir.name);
|
|
|
+ findnext(dir);
|
|
|
+ end;
|
|
|
+ findclose(dir);
|
|
|
+ end
|
|
|
+ else
|
|
|
+ begin
|
|
|
+ {$I-}
|
|
|
+ mkdir(s);
|
|
|
+ {$I+}
|
|
|
+ if ioresult<>0 then;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+procedure TAssembler.NextSmartName(place:tcutplace);
|
|
|
+var
|
|
|
+ s : string;
|
|
|
+begin
|
|
|
+ inc(SmartFilesCount);
|
|
|
+ if SmartFilesCount>999999 then
|
|
|
+ Message(asmw_f_too_many_asm_files);
|
|
|
+ case place of
|
|
|
+ cut_begin :
|
|
|
+ begin
|
|
|
+ inc(SmartHeaderCount);
|
|
|
+ s:=current_module.asmprefix^+tostr(SmartHeaderCount)+'h';
|
|
|
+ end;
|
|
|
+ cut_normal :
|
|
|
+ s:=current_module.asmprefix^+tostr(SmartHeaderCount)+'s';
|
|
|
+ cut_end :
|
|
|
+ s:=current_module.asmprefix^+tostr(SmartHeaderCount)+'t';
|
|
|
+ end;
|
|
|
+ AsmFile:=Path+FixFileName(s+tostr(SmartFilesCount)+target_info.asmext);
|
|
|
+ ObjFile:=Path+FixFileName(s+tostr(SmartFilesCount)+target_info.objext);
|
|
|
+ { insert in container so it can be cleared after the linking }
|
|
|
+ SmartLinkOFiles.Insert(Objfile);
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+{*****************************************************************************
|
|
|
+ TExternalAssembler
|
|
|
*****************************************************************************}
|
|
|
|
|
|
Function DoPipe:boolean;
|
|
@@ -148,11 +252,18 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
+Constructor TExternalAssembler.Create(smart:boolean);
|
|
|
+begin
|
|
|
+ inherited Create(smart);
|
|
|
+ Outcnt:=0;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
const
|
|
|
lastas : byte=255;
|
|
|
var
|
|
|
LastASBin : pathstr;
|
|
|
-Function TAsmList.FindAssembler:string;
|
|
|
+Function TExternalAssembler.FindAssembler:string;
|
|
|
var
|
|
|
asfound : boolean;
|
|
|
UtilExe : string;
|
|
@@ -179,7 +290,7 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-Function TAsmList.CallAssembler(const command,para:string):Boolean;
|
|
|
+Function TExternalAssembler.CallAssembler(const command,para:string):Boolean;
|
|
|
begin
|
|
|
callassembler:=true;
|
|
|
if not(cs_asm_extern in aktglobalswitches) then
|
|
@@ -205,7 +316,7 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TAsmList.RemoveAsm;
|
|
|
+procedure TExternalAssembler.RemoveAsm;
|
|
|
var
|
|
|
g : file;
|
|
|
begin
|
|
@@ -224,7 +335,7 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-Function TAsmList.DoAssemble:boolean;
|
|
|
+Function TExternalAssembler.DoAssemble:boolean;
|
|
|
var
|
|
|
s : string;
|
|
|
begin
|
|
@@ -254,36 +365,7 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TAsmList.NextSmartName;
|
|
|
-var
|
|
|
- s : string;
|
|
|
-begin
|
|
|
- inc(SmartFilesCount);
|
|
|
- if SmartFilesCount>999999 then
|
|
|
- Message(asmw_f_too_many_asm_files);
|
|
|
- case place of
|
|
|
- cut_begin :
|
|
|
- begin
|
|
|
- inc(SmartHeaderCount);
|
|
|
- s:=current_module.asmprefix^+tostr(SmartHeaderCount)+'h';
|
|
|
- end;
|
|
|
- cut_normal :
|
|
|
- s:=current_module.asmprefix^+tostr(SmartHeaderCount)+'s';
|
|
|
- cut_end :
|
|
|
- s:=current_module.asmprefix^+tostr(SmartHeaderCount)+'t';
|
|
|
- end;
|
|
|
- AsmFile:=Path+FixFileName(s+tostr(SmartFilesCount)+target_info.asmext);
|
|
|
- ObjFile:=Path+FixFileName(s+tostr(SmartFilesCount)+target_info.objext);
|
|
|
- { insert in container so it can be cleared after the linking }
|
|
|
- SmartLinkOFiles.Insert(Objfile);
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-{*****************************************************************************
|
|
|
- TAsmList AsmFile Writing
|
|
|
-*****************************************************************************}
|
|
|
-
|
|
|
-Procedure TAsmList.AsmFlush;
|
|
|
+Procedure TExternalAssembler.AsmFlush;
|
|
|
begin
|
|
|
if outcnt>0 then
|
|
|
begin
|
|
@@ -293,13 +375,13 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-Procedure TAsmList.AsmClear;
|
|
|
+Procedure TExternalAssembler.AsmClear;
|
|
|
begin
|
|
|
outcnt:=0;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-Procedure TAsmList.AsmWrite(const s:string);
|
|
|
+Procedure TExternalAssembler.AsmWrite(const s:string);
|
|
|
begin
|
|
|
if OutCnt+length(s)>=AsmOutSize then
|
|
|
AsmFlush;
|
|
@@ -309,14 +391,14 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-Procedure TAsmList.AsmWriteLn(const s:string);
|
|
|
+Procedure TExternalAssembler.AsmWriteLn(const s:string);
|
|
|
begin
|
|
|
AsmWrite(s);
|
|
|
AsmLn;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-Procedure TAsmList.AsmWritePChar(p:pchar);
|
|
|
+Procedure TExternalAssembler.AsmWritePChar(p:pchar);
|
|
|
var
|
|
|
i,j : longint;
|
|
|
begin
|
|
@@ -336,7 +418,7 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-Procedure TAsmList.AsmLn;
|
|
|
+Procedure TExternalAssembler.AsmLn;
|
|
|
begin
|
|
|
if OutCnt>=AsmOutSize-2 then
|
|
|
AsmFlush;
|
|
@@ -352,11 +434,10 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TAsmList.AsmCreate(Aplace:tcutplace);
|
|
|
+procedure TExternalAssembler.AsmCreate(Aplace:tcutplace);
|
|
|
begin
|
|
|
- place:=Aplace;
|
|
|
if SmartAsm then
|
|
|
- NextSmartName;
|
|
|
+ NextSmartName(Aplace);
|
|
|
{$ifdef unix}
|
|
|
if DoPipe then
|
|
|
begin
|
|
@@ -379,7 +460,7 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TAsmList.AsmClose;
|
|
|
+procedure TExternalAssembler.AsmClose;
|
|
|
var
|
|
|
f : file;
|
|
|
l : longint;
|
|
@@ -412,7 +493,7 @@ end;
|
|
|
|
|
|
|
|
|
{Touch Assembler and object time to ppu time is there is a ppufilename}
|
|
|
-procedure TAsmList.Synchronize;
|
|
|
+procedure TExternalAssembler.Synchronize;
|
|
|
begin
|
|
|
{Touch Assembler time to ppu time is there is a ppufilename}
|
|
|
if Assigned(current_module.ppufilename) then
|
|
@@ -424,89 +505,16 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TAsmList.WriteTree(p:TAAsmoutput);
|
|
|
-begin
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-procedure TAsmList.WriteAsmList;
|
|
|
-begin
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-procedure TAsmList.CreateSmartLinkPath(const s:string);
|
|
|
-var
|
|
|
- dir : searchrec;
|
|
|
-begin
|
|
|
- if PathExists(s) then
|
|
|
- begin
|
|
|
- { the path exists, now we clean only all the .o and .s files }
|
|
|
- { .o files }
|
|
|
- findfirst(s+dirsep+'*'+target_info.objext,anyfile,dir);
|
|
|
- while (doserror=0) do
|
|
|
- begin
|
|
|
- RemoveFile(s+dirsep+dir.name);
|
|
|
- findnext(dir);
|
|
|
- end;
|
|
|
- findclose(dir);
|
|
|
- { .s files }
|
|
|
- findfirst(s+dirsep+'*'+target_info.asmext,anyfile,dir);
|
|
|
- while (doserror=0) do
|
|
|
- begin
|
|
|
- RemoveFile(s+dirsep+dir.name);
|
|
|
- findnext(dir);
|
|
|
- end;
|
|
|
- findclose(dir);
|
|
|
- end
|
|
|
- else
|
|
|
- begin
|
|
|
- {$I-}
|
|
|
- mkdir(s);
|
|
|
- {$I+}
|
|
|
- if ioresult<>0 then;
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-Constructor TAsmList.Init(smart:boolean);
|
|
|
-begin
|
|
|
-{ load start values }
|
|
|
- asmfile:=current_module.asmfilename^;
|
|
|
- objfile:=current_module.objfilename^;
|
|
|
- name:=FixFileName(current_module.modulename^);
|
|
|
- OutCnt:=0;
|
|
|
- SmartFilesCount:=0;
|
|
|
- SmartLinkOFiles.Clear;
|
|
|
- place:=cut_normal;
|
|
|
- SmartAsm:=smart;
|
|
|
- SmartHeaderCount:=0;
|
|
|
-{ Which path will be used ? }
|
|
|
- if SmartAsm then
|
|
|
- begin
|
|
|
- path:=current_module.outputpath^+FixFileName(current_module.modulename^)+target_info.smartext;
|
|
|
- CreateSmartLinkPath(path);
|
|
|
- path:=FixPath(path,false);
|
|
|
- end
|
|
|
- else
|
|
|
- path:=current_module.outputpath^;
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-Destructor TAsmList.Done;
|
|
|
-begin
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
{*****************************************************************************
|
|
|
Generate Assembler Files Main Procedure
|
|
|
*****************************************************************************}
|
|
|
|
|
|
Procedure GenerateAsm(smart:boolean);
|
|
|
var
|
|
|
- a : PAsmList;
|
|
|
+ a : TExternalAssembler;
|
|
|
{$ifdef i386}
|
|
|
{$ifndef NoAg386Bin}
|
|
|
- b : Pi386binasmlist;
|
|
|
+ b : TInternalAssembler;
|
|
|
{$endif}
|
|
|
{$endif}
|
|
|
begin
|
|
@@ -521,16 +529,16 @@ begin
|
|
|
begin
|
|
|
case aktoutputformat of
|
|
|
as_i386_dbg :
|
|
|
- b:=new(pi386binasmlist,Init(og_dbg,smart));
|
|
|
+ b:=TInternalAssembler.Create(og_dbg,smart);
|
|
|
as_i386_coff :
|
|
|
- b:=new(pi386binasmlist,Init(og_coff,smart));
|
|
|
+ b:=TInternalAssembler.Create(og_coff,smart);
|
|
|
as_i386_pecoff :
|
|
|
- b:=new(pi386binasmlist,Init(og_pecoff,smart));
|
|
|
+ b:=TInternalAssembler.Create(og_pecoff,smart);
|
|
|
as_i386_elf :
|
|
|
- b:=new(pi386binasmlist,Init(og_elf,smart));
|
|
|
+ b:=TInternalAssembler.Create(og_elf,smart);
|
|
|
end;
|
|
|
- b^.WriteBin;
|
|
|
- dispose(b,done);
|
|
|
+ b.WriteBin;
|
|
|
+ b.Free;
|
|
|
if assigned(current_module.ppufilename) then
|
|
|
begin
|
|
|
if smart then
|
|
@@ -545,19 +553,19 @@ begin
|
|
|
as_i386_as,
|
|
|
as_i386_as_aout,
|
|
|
as_i386_asw :
|
|
|
- a:=new(pi386attasmlist,Init(smart));
|
|
|
+ a:=T386ATTAssembler.create(smart);
|
|
|
{$endif NoAg386Att}
|
|
|
{$ifndef NoAg386Nsm}
|
|
|
as_i386_nasmcoff,
|
|
|
as_i386_nasmwin32,
|
|
|
as_i386_nasmelf,
|
|
|
as_i386_nasmobj :
|
|
|
- a:=new(pi386nasmasmlist,Init(smart));
|
|
|
+ a:=T386NasmAssembler.Create(smart);
|
|
|
{$endif NoAg386Nsm}
|
|
|
{$ifndef NoAg386Int}
|
|
|
as_i386_masm,
|
|
|
as_i386_tasm :
|
|
|
- a:=new(pi386intasmlist,Init(smart));
|
|
|
+ a:=T386IntelAssembler.Create(smart);
|
|
|
{$endif NoAg386Int}
|
|
|
{$endif}
|
|
|
{$ifdef m68k}
|
|
@@ -568,11 +576,11 @@ begin
|
|
|
{$endif NoAg86KGas}
|
|
|
{$ifndef NoAg68kMot}
|
|
|
as_m68k_mot :
|
|
|
- a:=new(pm68kmotasmlist,Init(smart));
|
|
|
+ a:=new(pm68kmoTExternalAssembler,Init(smart));
|
|
|
{$endif NoAg86kMot}
|
|
|
{$ifndef NoAg68kMit}
|
|
|
as_m68k_mit :
|
|
|
- a:=new(pm68kmitasmlist,Init(smart));
|
|
|
+ a:=new(pm68kmiTExternalAssembler,Init(smart));
|
|
|
{$endif NoAg86KMot}
|
|
|
{$ifndef NoAg68kMpw}
|
|
|
as_m68k_mpw :
|
|
@@ -582,28 +590,31 @@ begin
|
|
|
else
|
|
|
Message(asmw_f_assembler_output_not_supported);
|
|
|
end;
|
|
|
- a^.AsmCreate(cut_normal);
|
|
|
- a^.WriteAsmList;
|
|
|
- a^.AsmClose;
|
|
|
- a^.DoAssemble;
|
|
|
- a^.synchronize;
|
|
|
- dispose(a,Done);
|
|
|
+ a.AsmCreate(cut_normal);
|
|
|
+ a.WriteAsmList;
|
|
|
+ a.AsmClose;
|
|
|
+ a.DoAssemble;
|
|
|
+ a.synchronize;
|
|
|
+ a.Free;
|
|
|
end;
|
|
|
|
|
|
|
|
|
Procedure OnlyAsm;
|
|
|
var
|
|
|
- a : PAsmList;
|
|
|
+ a : TExternalAssembler;
|
|
|
begin
|
|
|
- a:=new(pasmlist,Init(false));
|
|
|
- a^.DoAssemble;
|
|
|
- dispose(a,Done);
|
|
|
+ a:=TExternalAssembler.Create(false);
|
|
|
+ a.DoAssemble;
|
|
|
+ a.Free;
|
|
|
end;
|
|
|
|
|
|
end.
|
|
|
{
|
|
|
$Log$
|
|
|
- Revision 1.14 2001-02-26 08:08:16 michael
|
|
|
+ Revision 1.15 2001-03-05 21:39:11 peter
|
|
|
+ * changed to class with common TAssembler also for internal assembler
|
|
|
+
|
|
|
+ Revision 1.14 2001/02/26 08:08:16 michael
|
|
|
* bug correction: pipes must be closed by pclose (not close);
|
|
|
There was too many not closed processes under Linux before patch.
|
|
|
Test this by making a compiler under Linux with command
|