Browse Source

* Handle possible relocation types in assembler reader using a single AS_RELTYPE token, rather than with individual tokens for each case. Since possible relocations are target-dependent, this will allow to support any amount of them without modifying the base tattreader class.

git-svn-id: trunk@33117 -
sergei 9 năm trước cách đây
mục cha
commit
cc3e09ee46
3 tập tin đã thay đổi với 22 bổ sung22 xóa
  1. 10 10
      compiler/mips/racpugas.pas
  2. 2 2
      compiler/raatt.pas
  3. 10 10
      compiler/sparc/racpugas.pas

+ 10 - 10
compiler/mips/racpugas.pas

@@ -26,11 +26,13 @@ Unit racpugas;
 Interface
 
   uses
+    cgbase,
     rautils,
     raatt;
 
   type
     tMipsReader = class(tattreader)
+      actrel: trefaddr;
       function is_asmopcode(const s: string):boolean;override;
       procedure BuildOperand(oper : TOperand);
       procedure BuildOpCode(instr : TInstruction);
@@ -58,7 +60,7 @@ Interface
       rabase,
       rgbase,
       itcpugas,
-      cgbase,cgobj
+      cgobj
       ;
 
 
@@ -91,7 +93,6 @@ Interface
         len:=1;
         actasmpattern[len]:='%';
         c:=current_scanner.asmgetchar;
-        { to be a register there must be a letter and not a number }
         while c in ['a'..'z','A'..'Z','0'..'9'] do
           Begin
             inc(len);
@@ -100,12 +101,15 @@ Interface
           end;
          actasmpattern[0]:=chr(len);
          uppervar(actasmpattern);
+         actrel:=addr_no;
          if (actasmpattern='%HI') then
-           actasmtoken:=AS_HI
+           actrel:=addr_high
          else if (actasmpattern='%LO')then
-           actasmtoken:=AS_LO
+           actrel:=addr_low
          else
            Message(asmr_e_invalid_reference_syntax);
+         if actrel<>addr_no then
+           actasmtoken:=AS_RELTYPE;
       end;
 
 
@@ -253,16 +257,12 @@ Interface
                 gotplus:=false;
               end;
 
-            AS_HI,
-            AS_LO:
+            AS_RELTYPE:
               begin
                 { Low or High part of a constant (or constant
                   memory location) }
                 oper.InitRef;
-                if actasmtoken=AS_LO then
-                  oper.opr.ref.refaddr:=addr_low
-                else
-                  oper.opr.ref.refaddr:=addr_high;
+                oper.opr.ref.refaddr:=actrel;
                 Consume(actasmtoken);
                 Consume(AS_LPAREN);
                 BuildConstSymbolExpression(false, true,false,l,tempstr,tempsymtyp);

+ 2 - 2
compiler/raatt.pas

@@ -57,7 +57,7 @@ unit raatt;
         AS_SET,AS_WEAK,AS_SECTION,AS_END,
         {------------------ Assembler Operators  --------------------}
         AS_TYPE,AS_SIZEOF,AS_VMTOFFSET,AS_MOD,AS_SHL,AS_SHR,AS_NOT,AS_AND,AS_OR,AS_XOR,AS_NOR,AS_AT,
-        AS_LO,AS_HI,
+        AS_RELTYPE, // common token for relocation types
         {------------------ Target-specific directive ---------------}
         AS_TARGET_DIRECTIVE
         );
@@ -82,7 +82,7 @@ unit raatt;
         '.asciz','.lcomm','.comm','.single','.double','.tfloat','.tcfloat',
         '.data','.text','.init','.fini','.rva',
         '.set','.weak','.section','END',
-        'TYPE','SIZEOF','VMTOFFSET','%','<<','>>','!','&','|','^','~','@','lo','hi',
+        'TYPE','SIZEOF','VMTOFFSET','%','<<','>>','!','&','|','^','~','@','reltype',
         'directive');
 
     type

+ 10 - 10
compiler/sparc/racpugas.pas

@@ -26,10 +26,11 @@ Unit racpugas;
 Interface
 
   uses
-    raatt,racpu;
+    cgbase,raatt,racpu;
 
   type
     tSparcReader = class(tattreader)
+      actrel: trefaddr;
       function is_asmopcode(const s: string):boolean;override;
       procedure handleopcode;override;
       procedure BuildReference(oper : tSparcoperand);
@@ -56,7 +57,7 @@ Interface
       scanner,
       procinfo,
       rabase,rautils,
-      cgbase,cgobj
+      cgobj
       ;
 
 
@@ -153,12 +154,15 @@ Interface
          uppervar(actasmpattern);
          if is_register(actasmpattern) then
            exit;
+         actrel:=addr_no;
          if (actasmpattern='%HI') then
-           actasmtoken:=AS_HI
+           actrel:=addr_high
          else if (actasmpattern='%LO')then
-           actasmtoken:=AS_LO
+           actrel:=addr_low
          else
            Message(asmr_e_invalid_register);
+         if (actrel<>addr_no) then
+           actasmtoken:=AS_RELTYPE;
       end;
 
 
@@ -292,16 +296,12 @@ Interface
                 gotplus:=false;
               end;
 
-            AS_HI,
-            AS_LO:
+            AS_RELTYPE:
               begin
                 { Low or High part of a constant (or constant
                   memory location) }
                 oper.InitRef;
-                if actasmtoken=AS_LO then
-                  oper.opr.ref.refaddr:=addr_low
-                else
-                  oper.opr.ref.refaddr:=addr_high;
+                oper.opr.ref.refaddr:=actrel;
                 Consume(actasmtoken);
                 Consume(AS_LPAREN);
                 BuildConstSymbolExpression(false, true,false,l,tempstr,tempsymtyp);