Преглед на файлове

* 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: trunk@46550 -

yury преди 5 години
родител
ревизия
6e777d8967
променени са 6 файла, в които са добавени 74 реда и са изтрити 157 реда
  1. 2 33
      compiler/aggas.pas
  2. 54 1
      compiler/assemble.pas
  3. 2 42
      compiler/jvm/agjasmin.pas
  4. 2 35
      compiler/llvm/agllvm.pas
  5. 7 23
      compiler/z80/agsdasz80.pas
  6. 7 23
      compiler/z80/agz80vasm.pas

+ 2 - 33
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);

+ 54 - 1
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;

+ 2 - 42
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;

+ 2 - 35
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;
 

+ 7 - 23
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);

+ 7 - 23
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);