summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryury <yury@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-08-22 19:53:39 +0000
committeryury <yury@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-08-22 19:53:39 +0000
commit2c128acf576dd9eef30e9256f127ad8cc4c9db2c (patch)
tree9d10fd484639d317393d42f1953215cbd93b963b
parentf63b00bacfe9e81a38a0168adc866976de9fac25 (diff)
downloadfpc-2c128acf576dd9eef30e9256f127ad8cc4c9db2c.tar.gz
* ait_comment,ait_regalloc,ait_tempalloc,ait_varloc instructions produce only comments in the external assembler output. Moved handling of these instructions to TExternalAssembler.WriteComments().
This eliminates code duplication and improves maintainability. git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@46550 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--compiler/aggas.pas35
-rw-r--r--compiler/assemble.pas55
-rw-r--r--compiler/jvm/agjasmin.pas44
-rw-r--r--compiler/llvm/agllvm.pas37
-rw-r--r--compiler/z80/agsdasz80.pas30
-rw-r--r--compiler/z80/agz80vasm.pas30
6 files changed, 74 insertions, 157 deletions
diff --git a/compiler/aggas.pas b/compiler/aggas.pas
index 2a891490a0..089b5a3e23 100644
--- a/compiler/aggas.pas
+++ b/compiler/aggas.pas
@@ -837,38 +837,6 @@ implementation
case hp.typ of
- ait_comment :
- Begin
- writer.AsmWrite(asminfo^.comment);
- writer.AsmWritePChar(tai_comment(hp).str);
- writer.AsmLn;
- End;
-
- ait_regalloc :
- begin
- if (cs_asm_regalloc in current_settings.globalswitches) then
- begin
- writer.AsmWrite(#9+asminfo^.comment+'Register ');
- repeat
- writer.AsmWrite(std_regname(Tai_regalloc(hp).reg));
- if (hp.next=nil) or
- (tai(hp.next).typ<>ait_regalloc) or
- (tai_regalloc(hp.next).ratype<>tai_regalloc(hp).ratype) then
- break;
- hp:=tai(hp.next);
- writer.AsmWrite(',');
- until false;
- writer.AsmWrite(' ');
- writer.AsmWriteLn(regallocstr[tai_regalloc(hp).ratype]);
- end;
- end;
-
- ait_tempalloc :
- begin
- if (cs_asm_tempalloc in current_settings.globalswitches) then
- WriteTempalloc(tai_tempalloc(hp));
- end;
-
ait_align :
begin
doalign(tai_align_abstract(hp).aligntype,tai_align_abstract(hp).use_op,tai_align_abstract(hp).fillop,tai_align_abstract(hp).maxbytes,last_align,lasthp);
@@ -1581,7 +1549,8 @@ implementation
writer.AsmLn;
end;
else
- internalerror(2006012201);
+ if not WriteComments(hp) then
+ internalerror(2006012201);
end;
lasthp:=hp;
hp:=tai(hp.next);
diff --git a/compiler/assemble.pas b/compiler/assemble.pas
index 0b691e855c..b4b9f993b9 100644
--- a/compiler/assemble.pas
+++ b/compiler/assemble.pas
@@ -153,6 +153,7 @@ interface
procedure WriteSourceLine(hp: tailineinfo);
procedure WriteTempalloc(hp: tai_tempalloc);
procedure WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean);
+ function WriteComments(var hp: tai): boolean;
function single2str(d : single) : string; virtual;
function double2str(d : double) : string; virtual;
function extended2str(e : extended) : string; virtual;
@@ -264,7 +265,7 @@ Implementation
{$endif FPC_SOFT_FPUX80}
{$endif}
cscript,fmodule,verbose,
- cpuinfo,triplet,
+ cpubase,cpuinfo,triplet,
aasmcpu;
var
@@ -1195,6 +1196,58 @@ Implementation
end;
+ function TExternalAssembler.WriteComments(var hp: tai): boolean;
+ begin
+ result:=true;
+ case hp.typ of
+ ait_comment :
+ Begin
+ writer.AsmWrite(asminfo^.comment);
+ writer.AsmWritePChar(tai_comment(hp).str);
+ writer.AsmLn;
+ End;
+
+ ait_regalloc :
+ begin
+ if (cs_asm_regalloc in current_settings.globalswitches) then
+ begin
+ writer.AsmWrite(#9+asminfo^.comment+'Register ');
+ repeat
+ writer.AsmWrite(std_regname(Tai_regalloc(hp).reg));
+ if (hp.next=nil) or
+ (tai(hp.next).typ<>ait_regalloc) or
+ (tai_regalloc(hp.next).ratype<>tai_regalloc(hp).ratype) then
+ break;
+ hp:=tai(hp.next);
+ writer.AsmWrite(',');
+ until false;
+ writer.AsmWrite(' ');
+ writer.AsmWriteLn(regallocstr[tai_regalloc(hp).ratype]);
+ end;
+ end;
+
+ ait_tempalloc :
+ begin
+ if (cs_asm_tempalloc in current_settings.globalswitches) then
+ WriteTempalloc(tai_tempalloc(hp));
+ end;
+
+ ait_varloc:
+ begin
+ { ait_varloc is present here only when register allocation is not done ( -sr option ) }
+ if tai_varloc(hp).newlocationhi<>NR_NO then
+ writer.AsmWriteLn(asminfo^.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
+ std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation))
+ else
+ writer.AsmWriteLn(asminfo^.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
+ std_regname(tai_varloc(hp).newlocation));
+ end;
+ else
+ result:=false;
+ end;
+ end;
+
+
procedure TExternalAssembler.WriteTree(p:TAsmList);
begin
end;
diff --git a/compiler/jvm/agjasmin.pas b/compiler/jvm/agjasmin.pas
index ca039256bc..bdffd19a25 100644
--- a/compiler/jvm/agjasmin.pas
+++ b/compiler/jvm/agjasmin.pas
@@ -362,47 +362,6 @@ implementation
case hp.typ of
- ait_comment :
- Begin
- writer.AsmWrite(asminfo^.comment);
- writer.AsmWritePChar(tai_comment(hp).str);
- writer.AsmLn;
- End;
-
- ait_regalloc :
- begin
- if (cs_asm_regalloc in current_settings.globalswitches) then
- begin
- writer.AsmWrite(#9+asminfo^.comment+'Register ');
- repeat
- writer.AsmWrite(std_regname(Tai_regalloc(hp).reg));
- if (hp.next=nil) or
- (tai(hp.next).typ<>ait_regalloc) or
- (tai_regalloc(hp.next).ratype<>tai_regalloc(hp).ratype) then
- break;
- hp:=tai(hp.next);
- writer.AsmWrite(',');
- until false;
- writer.AsmWrite(' ');
- writer.AsmWriteLn(regallocstr[tai_regalloc(hp).ratype]);
- end;
- end;
-
- ait_tempalloc :
- begin
- if (cs_asm_tempalloc in current_settings.globalswitches) then
- begin
- {$ifdef EXTDEBUG}
- if assigned(tai_tempalloc(hp).problem) then
- writer.AsmWriteLn(asminfo^.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
- tostr(tai_tempalloc(hp).tempsize)+' '+tai_tempalloc(hp).problem^)
- else
- {$endif EXTDEBUG}
- writer.AsmWriteLn(asminfo^.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
- tostr(tai_tempalloc(hp).tempsize)+' '+tempallocstr[tai_tempalloc(hp).allocation]);
- end;
- end;
-
ait_align :
begin
@@ -538,7 +497,8 @@ implementation
writer.AsmWriteLn(tai_jcatch(hp).handlerlab.name);
end;
else
- internalerror(2010122707);
+ if not WriteComments(hp) then
+ internalerror(2010122707);
end;
hp:=tai(hp.next);
end;
diff --git a/compiler/llvm/agllvm.pas b/compiler/llvm/agllvm.pas
index 36d70adca3..4b6bf441b8 100644
--- a/compiler/llvm/agllvm.pas
+++ b/compiler/llvm/agllvm.pas
@@ -1166,40 +1166,6 @@ implementation
ch: ansichar;
begin
case hp.typ of
- ait_comment :
- begin
- writer.AsmWrite(asminfo^.comment);
- writer.AsmWritePChar(tai_comment(hp).str);
- if fdecllevel<>0 then
- internalerror(2015090601);
- writer.AsmLn;
- end;
-
- ait_regalloc :
- begin
- if (cs_asm_regalloc in current_settings.globalswitches) then
- begin
- writer.AsmWrite(#9+asminfo^.comment+'Register ');
- repeat
- writer.AsmWrite(std_regname(Tai_regalloc(hp).reg));
- if (hp.next=nil) or
- (tai(hp.next).typ<>ait_regalloc) or
- (tai_regalloc(hp.next).ratype<>tai_regalloc(hp).ratype) then
- break;
- hp:=tai(hp.next);
- writer.AsmWrite(',');
- until false;
- writer.AsmWrite(' ');
- writer.AsmWriteLn(regallocstr[tai_regalloc(hp).ratype]);
- end;
- end;
-
- ait_tempalloc :
- begin
- if (cs_asm_tempalloc in current_settings.globalswitches) then
- WriteTempalloc(tai_tempalloc(hp));
- end;
-
ait_align,
ait_section :
begin
@@ -1494,7 +1460,8 @@ implementation
WriteTypedConstData(tai_abstracttypedconst(hp),false);
end
else
- internalerror(2019012010);
+ if not WriteComments(hp) then
+ internalerror(2019012010);
end;
end;
diff --git a/compiler/z80/agsdasz80.pas b/compiler/z80/agsdasz80.pas
index 64993ea1c9..bb1cd6dfe0 100644
--- a/compiler/z80/agsdasz80.pas
+++ b/compiler/z80/agsdasz80.pas
@@ -587,23 +587,6 @@ unit agsdasz80;
end;*)
end;
case hp.typ of
- ait_comment :
- begin
- writer.AsmWrite(asminfo^.comment);
- writer.AsmWritePChar(tai_comment(hp).str);
- writer.AsmLn;
- end;
- ait_regalloc :
- begin
- if (cs_asm_regalloc in current_settings.globalswitches) then
- writer.AsmWriteLn(#9#9+asminfo^.comment+'Register '+std_regname(tai_regalloc(hp).reg)+' '+
- regallocstr[tai_regalloc(hp).ratype]);
- end;
- ait_tempalloc :
- begin
- if (cs_asm_tempalloc in current_settings.globalswitches) then
- WriteTempalloc(tai_tempalloc(hp));
- end;
ait_section :
begin
if tai_section(hp).sectype<>sec_none then
@@ -862,12 +845,13 @@ unit agsdasz80;
ait_force_line,
ait_function_name : ;
else
- begin
- writer.AsmWrite(asminfo^.comment);
- writer.AsmWrite('WARNING: not yet implemented in assembler output: ');
- Str(hp.typ,s);
- writer.AsmWriteLn(s);
- end;
+ if not WriteComments(hp) then
+ begin
+ writer.AsmWrite(asminfo^.comment);
+ writer.AsmWrite('WARNING: not yet implemented in assembler output: ');
+ Str(hp.typ,s);
+ writer.AsmWriteLn(s);
+ end;
end;
lasthp:=hp;
hp:=tai(hp.next);
diff --git a/compiler/z80/agz80vasm.pas b/compiler/z80/agz80vasm.pas
index c4308ef270..46e8b3014f 100644
--- a/compiler/z80/agz80vasm.pas
+++ b/compiler/z80/agz80vasm.pas
@@ -621,23 +621,6 @@ unit agz80vasm;
end;*)
end;
case hp.typ of
- ait_comment :
- begin
- writer.AsmWrite(asminfo^.comment);
- writer.AsmWritePChar(tai_comment(hp).str);
- writer.AsmLn;
- end;
- ait_regalloc :
- begin
- if (cs_asm_regalloc in current_settings.globalswitches) then
- writer.AsmWriteLn(#9#9+asminfo^.comment+'Register '+std_regname(tai_regalloc(hp).reg)+' '+
- regallocstr[tai_regalloc(hp).ratype]);
- end;
- ait_tempalloc :
- begin
- if (cs_asm_tempalloc in current_settings.globalswitches) then
- WriteTempalloc(tai_tempalloc(hp));
- end;
ait_section :
begin
if tai_section(hp).sectype<>sec_none then
@@ -893,12 +876,13 @@ unit agz80vasm;
ait_force_line,
ait_function_name : ;
else
- begin
- writer.AsmWrite(asminfo^.comment);
- writer.AsmWrite('WARNING: not yet implemented in assembler output: ');
- Str(hp.typ,s);
- writer.AsmWriteLn(s);
- end;
+ if not WriteComments(hp) then
+ begin
+ writer.AsmWrite(asminfo^.comment);
+ writer.AsmWrite('WARNING: not yet implemented in assembler output: ');
+ Str(hp.typ,s);
+ writer.AsmWriteLn(s);
+ end;
end;
lasthp:=hp;
hp:=tai(hp.next);