Răsfoiți Sursa

* as avr doesn't like $ in symbols, use ReplaceForbiddenChars to replace them

git-svn-id: branches/avr@17040 -
florian 14 ani în urmă
părinte
comite
26415e9903
2 a modificat fișierele cu 122 adăugiri și 63 ștergeri
  1. 53 6
      compiler/aggas.pas
  2. 69 57
      compiler/avr/agavrgas.pas

+ 53 - 6
compiler/aggas.pas

@@ -93,14 +93,16 @@ interface
        end;
 
 
+     function ReplaceForbiddenChars(const s: string): string;
+
+
 implementation
 
     uses
       SysUtils,
       cutils,cfileutl,systems,
       fmodule,finput,verbose,
-      itcpugas,cpubase
-      ;
+      itcpugas,cpubase;
 
     const
       line_length = 70;
@@ -217,6 +219,17 @@ implementation
         #9'.rva'#9,#9'.secrel32'#9,#9'.quad'#9,#9'.long'#9
       );
 
+    function ReplaceForbiddenChars(const s: string): string;
+      var
+      i : longint;
+      begin
+        Result:=s;
+        for i:=1 to Length(Result) do
+          if Result[i]='$' then
+            Result[i]:='s';
+      end;
+
+
 {****************************************************************************}
 {                          GNU Assembler writer                              }
 {****************************************************************************}
@@ -863,6 +876,9 @@ implementation
                                   end
                                else
                                  s:=tai_const(hp).sym.name;
+{$ifdef avr}
+                               s:=ReplaceForbiddenChars(s);
+{$endif avr}
                                if tai_const(hp).value<>0 then
                                  s:=s+tostr_with_plus(tai_const(hp).value);
                              end
@@ -1040,9 +1056,17 @@ implementation
                   if tai_label(hp).labsym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN] then
                    begin
                      AsmWrite('.globl'#9);
+{$ifdef avr}
+                     AsmWriteLn(ReplaceForbiddenChars(tai_label(hp).labsym.name));
+{$else avr}
                      AsmWriteLn(tai_label(hp).labsym.name);
+{$endif avr}
                    end;
+{$ifdef avr}
+                  AsmWrite(ReplaceForbiddenChars(tai_label(hp).labsym.name));
+{$else avr}
                   AsmWrite(tai_label(hp).labsym.name);
+{$endif avr}
                   AsmWriteLn(':');
                 end;
              end;
@@ -1052,17 +1076,24 @@ implementation
                if (tai_symbol(hp).sym.bind=AB_PRIVATE_EXTERN) then
                  begin
                    AsmWrite(#9'.private_extern ');
+{$ifdef avr}
+                   AsmWriteln(ReplaceForbiddenChars(tai_symbol(hp).sym.name));
+{$else avr}
                    AsmWriteln(tai_symbol(hp).sym.name);
+{$endif avr}
                  end;
                if (target_info.system = system_powerpc64_linux) and
                  (tai_symbol(hp).sym.typ = AT_FUNCTION) and (cs_profile in current_settings.moduleswitches) then
-                 begin
                  AsmWriteLn('.globl _mcount');
-               end;
+
                if tai_symbol(hp).is_global then
                 begin
                   AsmWrite('.globl'#9);
-                  AsmWriteLn(tai_symbol(hp).sym.name);
+{$ifdef avr}
+                  AsmWriteln(ReplaceForbiddenChars(tai_symbol(hp).sym.name));
+{$else avr}
+                  AsmWriteln(tai_symbol(hp).sym.name);
+{$endif avr}
                 end;
                if (target_info.system = system_powerpc64_linux) and
                  (tai_symbol(hp).sym.typ = AT_FUNCTION) then
@@ -1094,10 +1125,17 @@ implementation
                          AsmWriteLn(',' + sepChar + 'function');
                      end;
                  end;
+{$ifdef avr}
+               if not(tai_symbol(hp).has_value) then
+                 AsmWriteLn(ReplaceForbiddenChars(tai_symbol(hp).sym.name + ':'))
+               else
+                 AsmWriteLn(ReplaceForbiddenChars(tai_symbol(hp).sym.name + '=' + tostr(tai_symbol(hp).value)));
+{$else avr}
                if not(tai_symbol(hp).has_value) then
                  AsmWriteLn(tai_symbol(hp).sym.name + ':')
                else
                  AsmWriteLn(tai_symbol(hp).sym.name + '=' + tostr(tai_symbol(hp).value));
+{$endif avr}
              end;
 {$ifdef arm}
            ait_thumb_func:
@@ -1116,11 +1154,19 @@ implementation
                   AsmWrite(#9'.size'#9);
                   if (target_info.system = system_powerpc64_linux) and (tai_symbol_end(hp).sym.typ = AT_FUNCTION) then
                     AsmWrite('.');
+{$ifdef avr}
+                  AsmWrite(ReplaceForbiddenChars(tai_symbol_end(hp).sym.name));
+{$else avr}
                   AsmWrite(tai_symbol_end(hp).sym.name);
+{$endif avr}
                   AsmWrite(', '+s+' - ');
                   if (target_info.system = system_powerpc64_linux) and (tai_symbol_end(hp).sym.typ = AT_FUNCTION) then
                      AsmWrite('.');
+{$ifdef avr}
+                  AsmWriteLn(ReplaceForbiddenChars(tai_symbol_end(hp).sym.name));
+{$else avr}
                   AsmWriteLn(tai_symbol_end(hp).sym.name);
+{$endif avr}
                 end;
              end;
 
@@ -1140,7 +1186,8 @@ implementation
              end;
 
            ait_force_line,
-           ait_function_name : ;
+           ait_function_name :
+             ;
 
            ait_cutobject :
              begin

+ 69 - 57
compiler/avr/agavrgas.pas

@@ -68,69 +68,81 @@ unit agavrgas;
 {                  Helper routines for Instruction Writer                    }
 {****************************************************************************}
 
-    function getreferencestring(var ref : treference) : string;
-      var
-        s : string;
-      begin
-         with ref do
-          begin
-{$ifdef extdebug}
-            // if base=NR_NO then
-            //   internalerror(200308292);
-
-            // if ((index<>NR_NO) or (shiftmode<>SM_None)) and ((offset<>0) or (symbol<>nil)) then
-            //   internalerror(200308293);
-{$endif extdebug}
-
-            if assigned(symbol) then
-              begin
-                s:=symbol.name;
-                if offset<0 then
-                  s:=s+tostr(offset)
-                else if offset>0 then
-                  s:=s+'+'+tostr(offset);
-              end
-            else
-              begin
-                s:=gas_regname(base);
-              end;
 
-          end;
-        getreferencestring:=s;
-      end;
+    Procedure TAVRInstrWriter.WriteInstruction(hp : tai);
 
+      function getreferencestring(var ref : treference) : string;
+        var
+          s : string;
+        begin
+           with ref do
+            begin
+  {$ifdef extdebug}
+              // if base=NR_NO then
+              //   internalerror(200308292);
+
+              // if ((index<>NR_NO) or (shiftmode<>SM_None)) and ((offset<>0) or (symbol<>nil)) then
+              //   internalerror(200308293);
+  {$endif extdebug}
+
+              if assigned(symbol) or (offset<>0) then
+                begin
+                  if assigned(symbol) then
+                    s:=ReplaceForbiddenChars(symbol.name)
+                  else
+                     s:='';
+
+                  if offset<0 then
+                    s:=s+tostr(offset)
+                  else if offset>0 then
+                    s:=s+'+'+tostr(offset);
+                  case refaddr of
+                    addr_hi8:
+                      s:='hi8('+s+')';
+                    addr_lo8:
+                      s:='lo8('+s+')';
+                    else
+                      s:='('+s+')';
+                  end;
+                end
+              else
+                begin
+                  s:='('+gas_regname(base)+')';
+                end;
 
-    function getopstr(const o:toper) : string;
-      var
-        hs : string;
-        first : boolean;
-        r : tsuperregister;
-      begin
-        case o.typ of
-          top_reg:
-            getopstr:=gas_regname(o.reg);
-          top_const:
-            getopstr:=tostr(longint(o.val));
-          top_ref:
-            if o.ref^.refaddr=addr_full then
-              begin
-                hs:=o.ref^.symbol.name;
-                if o.ref^.offset>0 then
-                 hs:=hs+'+'+tostr(o.ref^.offset)
-                else
-                 if o.ref^.offset<0 then
-                  hs:=hs+tostr(o.ref^.offset);
-                getopstr:=hs;
-              end
-            else
-              getopstr:=getreferencestring(o.ref^);
-          else
-            internalerror(2002070604);
+            end;
+          getreferencestring:=s;
         end;
-      end;
 
 
-    Procedure TAVRInstrWriter.WriteInstruction(hp : tai);
+      function getopstr(const o:toper) : string;
+        var
+          hs : string;
+          first : boolean;
+          r : tsuperregister;
+        begin
+          case o.typ of
+            top_reg:
+              getopstr:=gas_regname(o.reg);
+            top_const:
+              getopstr:=tostr(longint(o.val));
+            top_ref:
+              if o.ref^.refaddr=addr_full then
+                begin
+                  hs:=o.ref^.symbol.name;
+                  if o.ref^.offset>0 then
+                   hs:=hs+'+'+tostr(o.ref^.offset)
+                  else
+                   if o.ref^.offset<0 then
+                    hs:=hs+tostr(o.ref^.offset);
+                  getopstr:=hs;
+                end
+              else
+                getopstr:=getreferencestring(o.ref^);
+            else
+              internalerror(2002070604);
+          end;
+        end;
     var op: TAsmOp;
         s: string;
         i: byte;