ソースを参照

* Made ATT asm writer work with -sr

daniel 22 年 前
コミット
787fcc5797
3 ファイル変更95 行追加54 行削除
  1. 14 4
      compiler/aggas.pas
  2. 42 48
      compiler/x86/agx86att.pas
  3. 39 2
      compiler/x86/itx86att.pas

+ 14 - 4
compiler/aggas.pas

@@ -57,6 +57,11 @@ interface
         procedure WriteInstruction(hp: tai);  virtual; abstract;
       end;
 
+    const
+      regname_count=45;
+      regname_count_bsstart=32;   {Largest power of 2 out of regname_count.}
+
+
 implementation
 
     uses
@@ -75,9 +80,11 @@ implementation
   {$endif}
       ,gdb
 {$endif GDB}
+{$ifdef i386}
+      ,itx86att
+{$endif}
       ;
 
-
     const
       line_length = 70;
 
@@ -388,10 +395,10 @@ var
                if (cs_asm_regalloc in aktglobalswitches) then
                  begin
                    if Tai_Regalloc(hp).reg.enum=R_INTREGISTER then
-                     AsmWriteLn(target_asm.comment+'Register reg'+tostr(byte(tai_regalloc(hp).reg.number shr 8)-1)+
+                     AsmWriteLn(#9+target_asm.comment+'Register '+gas_regname(Tai_regalloc(hp).reg.number)+
                        allocstr[tai_regalloc(hp).allocation])
                    else
-                     AsmWriteLn(target_asm.comment+'Register '+std_reg2str[tai_regalloc(hp).reg.enum]+
+                     AsmWriteLn(#9+target_asm.comment+'Register '+std_reg2str[tai_regalloc(hp).reg.enum]+
                        allocstr[tai_regalloc(hp).allocation]);
                  end;
              end;
@@ -822,7 +829,10 @@ var
 end.
 {
   $Log$
-  Revision 1.27  2003-08-17 21:11:00  daniel
+  Revision 1.28  2003-08-18 11:49:47  daniel
+    * Made ATT asm writer work with -sr
+
+  Revision 1.27  2003/08/17 21:11:00  daniel
     * Now -sr works...
 
   Revision 1.26  2003/08/17 20:47:47  daniel

+ 42 - 48
compiler/x86/agx86att.pas

@@ -58,24 +58,27 @@ interface
  ****************************************************************************}
 
     procedure Tx86AttAssembler.WriteReference(var ref : treference);
+
+    var i,b,s:boolean;
+
       begin
         with ref do
          begin
            inc(offset,offsetfixup);
            offsetfixup:=0;
-           if segment.enum>lastreg then
-             internalerror(200301081);
-           if base.enum>lastreg then
-             internalerror(200301081);
-           if index.enum>lastreg then
-             internalerror(200301081);
+           s:=(segment.enum=R_NO) or ((segment.enum=R_INTREGISTER) and (segment.number=NR_NO));
+           b:=(base.enum=R_NO) or ((base.enum=R_INTREGISTER) and (base.number=NR_NO));
+           i:=(index.enum=R_NO) or ((index.enum=R_INTREGISTER) and (index.number=NR_NO));
 
            { have we a segment prefix ? }
            { These are probably not correctly handled under GAS }
            { should be replaced by coding the segment override  }
            { directly! - DJGPP FAQ                              }
-           if segment.enum<>R_NO then
-            AsmWrite(gas_reg2str[segment.enum]+':');
+           if not s then
+            if segment.enum=R_INTREGISTER then
+              asmwrite(gas_regname(segment.number)+':')
+            else
+              AsmWrite(gas_reg2str[segment.enum]+':');
            if assigned(symbol) then
              AsmWrite(symbol.name);
            if offset<0 then
@@ -88,23 +91,33 @@ interface
                else
                 AsmWrite(tostr(offset));
              end
-           else if (index.enum=R_NO) and (base.enum=R_NO) and not assigned(symbol) then
+           else if i and b and not assigned(symbol) then
              AsmWrite('0');
-           if (index.enum<>R_NO) and (base.enum=R_NO) then
+           if (not i) and (b) then
             begin
-              AsmWrite('(,'+gas_reg2str[index.enum]);
+              if index.enum=R_INTREGISTER then
+                AsmWrite('(,'+gas_regname(index.number))
+              else
+                AsmWrite('(,'+gas_reg2str[index.enum]);
               if scalefactor<>0 then
                AsmWrite(','+tostr(scalefactor)+')')
               else
                AsmWrite(')');
             end
            else
-            if (index.enum=R_NO) and (base.enum<>R_NO) then
-             AsmWrite('('+gas_reg2str[base.enum]+')')
+            if i and not b then
+             if base.enum=R_INTREGISTER then
+               AsmWrite('('+gas_regname(base.number)+')')
+             else
+               AsmWrite('('+gas_reg2str[base.enum]+')')
             else
-             if (index.enum<>R_NO) and (base.enum<>R_NO) then
+             if (not i) and (not b) then
               begin
-                AsmWrite('('+gas_reg2str[base.enum]+','+gas_reg2str[index.enum]);
+                if base.enum=R_INTREGISTER then
+                  {Assume if base is new notation, index is also.}
+                  AsmWrite('('+gas_regname(base.number)+','+gas_regname(index.number))
+                else
+                  AsmWrite('('+gas_reg2str[base.enum]+','+gas_reg2str[index.enum]);
                 if scalefactor<>0 then
                  AsmWrite(','+tostr(scalefactor));
                 AsmWrite(')');
@@ -118,9 +131,10 @@ interface
         case o.typ of
           top_reg :
             begin
-              if o.reg.enum>lastreg then
-                internalerror(200301081);
-              AsmWrite(gas_reg2str[o.reg.enum]);
+              if o.reg.enum=R_INTREGISTER then
+                AsmWrite(gas_regname(o.reg.number))
+              else
+                AsmWrite(gas_reg2str[o.reg.enum]);
             end;
           top_ref :
             WriteReference(o.ref^);
@@ -151,9 +165,10 @@ interface
         case o.typ of
           top_reg :
             begin
-              if o.reg.enum>lastreg then
-                internalerror(200301081);
-              AsmWrite('*'+gas_reg2str[o.reg.enum]);
+              if o.reg.enum=R_INTREGISTER then
+                AsmWrite('*'+gas_regname(o.reg.number))
+              else
+                AsmWrite('*'+gas_reg2str[o.reg.enum]);
             end;
           top_ref :
             begin
@@ -192,9 +207,9 @@ interface
         AsmWrite(#9+gas_op2str[op]+cond2str[taicpu(hp).condition]);
         { suffix needed ?  fnstsw,fldcw don't support suffixes
           with binutils 2.9.5 under linux }
-        if (Taicpu(hp).oper[0].typ=top_reg) and
+{        if (Taicpu(hp).oper[0].typ=top_reg) and
             (Taicpu(hp).oper[0].reg.enum>lastreg) then
-          internalerror(200301081);
+          internalerror(200301081);}
 
         if (not calljmp) and
             (gas_needsuffix[op]<>AttSufNONE) and
@@ -228,30 +243,6 @@ interface
         AsmLn;
       end;
 
-
-     function gas_regnum_search(const s:string):Tnewregister;
-
-     {Searches the register number that belongs to the register in s.
-      s must be in uppercase!.}
-
-     var i,p:byte;
-
-     begin
-        {Binary search.}
-        p:=0;
-        i:=regname_count_bsstart;
-        while i<>0 do
-          begin
-            if (p+i<regname_count) and (upper(gas_regname2regnum[p+i].name)<=s) then
-              p:=p+i;
-            i:=i shr 1;
-          end;
-        if upper(gas_regname2regnum[p].name)=s then
-          gas_regnum_search:=gas_regname2regnum[p].number
-        else
-          gas_regnum_search:=NR_NO;
-     end;
-
 {*****************************************************************************
                                   Initialize
 *****************************************************************************}
@@ -348,7 +339,10 @@ initialization
 end.
 {
   $Log$
-  Revision 1.3  2003-05-28 23:18:31  florian
+  Revision 1.4  2003-08-18 11:49:47  daniel
+    * Made ATT asm writer work with -sr
+
+  Revision 1.3  2003/05/28 23:18:31  florian
     * started to fix and clean up the sparc port
 
   Revision 1.2  2003/05/22 21:33:31  peter

+ 39 - 2
compiler/x86/itx86att.pas

@@ -144,11 +144,12 @@ interface
 {$endif x86_64}
 
      function gas_regnum_search(const s:string):Tnewregister;
+     function gas_regname(const r:Tnewregister):string;
 
 
 implementation
 
-     uses cutils;
+     uses cutils,verbose;
 
      function gas_regnum_search(const s:string):Tnewregister;
 
@@ -173,10 +174,46 @@ implementation
           gas_regnum_search:=NR_NO;
      end;
 
+    function gas_regname(const r:Tnewregister):string;
+
+    var i:byte;
+        nr:string[3];
+        sub:char;
+
+    begin
+      gas_regname:='';
+      for i:=0 to regname_count-1 do
+        if r=gas_regname2regnum[i].number then
+            gas_regname:=gas_regname2regnum[i].name;
+      {If not found, generate a systematic name.}
+      if gas_regname='' then
+        begin
+          str(r shr 8,nr);
+          case r and $ff of
+            R_SUBL:
+              sub:='l';
+            R_SUBH:
+              sub:='h';
+            R_SUBW:
+              sub:='w';
+            R_SUBD:
+              sub:='d';
+            R_SUBQ:
+              sub:='q';
+          else
+            internalerror(200303081);
+          end;
+          gas_regname:='%reg'+nr+sub;
+        end;
+    end;
+
 end.
 {
   $Log$
-  Revision 1.2  2003-07-06 15:31:21  daniel
+  Revision 1.3  2003-08-18 11:49:47  daniel
+    * Made ATT asm writer work with -sr
+
+  Revision 1.2  2003/07/06 15:31:21  daniel
     * Fixed register allocator. *Lots* of fixes.
 
   Revision 1.1  2003/05/22 21:33:08  peter