瀏覽代碼

+ implemented abi compliant handling of strucutured functions results on sparc platform

florian 20 年之前
父節點
當前提交
fcfbc935a1

+ 13 - 1
compiler/ncgcal.pas

@@ -69,6 +69,7 @@ interface
           procedure pop_parasize(pop_size:longint);virtual;
           procedure extra_interrupt_code;virtual;
           procedure extra_call_code;virtual;
+          procedure extra_post_call_code;virtual;
           procedure do_syscall;virtual;abstract;
        public
           procedure pass_2;override;
@@ -476,6 +477,11 @@ implementation
       end;
 
 
+    procedure tcgcallnode.extra_post_call_code;
+      begin
+      end;
+
+
     procedure tcgcallnode.pop_parasize(pop_size:longint);
       begin
       end;
@@ -896,6 +902,7 @@ implementation
                  { call method }
                  extra_call_code;
                  cg.a_call_reg(exprasmlist,pvreg);
+                 extra_post_call_code;
                end
              else
                begin
@@ -924,6 +931,7 @@ implementation
                         extra_interrupt_code;
                       extra_call_code;
                       cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
+                      extra_post_call_code;
                     end;
                end;
            end
@@ -961,6 +969,7 @@ implementation
                 extra_interrupt_code;
               extra_call_code;
               cg.a_call_reg(exprasmlist,pvreg);
+              extra_post_call_code;
            end;
 
          { Need to remove the parameters from the stack? }
@@ -1247,7 +1256,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.192  2005-01-04 16:36:51  peter
+  Revision 1.193  2005-01-07 16:22:54  florian
+    + implemented abi compliant handling of strucutured functions results on sparc platform
+
+  Revision 1.192  2005/01/04 16:36:51  peter
     * release temps in array constructor
 
   Revision 1.191  2005/01/02 16:58:48  peter

+ 5 - 2
compiler/parabase.pas

@@ -51,9 +51,9 @@ unit parabase;
        end;
 
        TCGPara = object
+          Location  : PCGParalocation;
           Alignment : ShortInt;
           Size      : TCGSize;  { Size of the parameter included in all locations }
-          Location  : PCGParalocation;
           constructor init;
           destructor  done;
           procedure   reset;
@@ -251,7 +251,10 @@ end.
 
 {
    $Log$
-   Revision 1.6  2004-11-22 22:01:19  peter
+   Revision 1.7  2005-01-07 16:22:54  florian
+     + implemented abi compliant handling of strucutured functions results on sparc platform
+
+   Revision 1.6  2004/11/22 22:01:19  peter
      * fixed varargs
      * replaced dynarray with tlist
 

+ 38 - 10
compiler/sparc/cgcpu.pas

@@ -121,7 +121,7 @@ implementation
   uses
     globals,verbose,systems,cutils,
     symdef,paramgr,
-    tgobj,cpupi;
+    tgobj,procinfo,cpupi;
 
 
 {****************************************************************************
@@ -952,19 +952,44 @@ implementation
 
 
     procedure TCgSparc.g_proc_exit(list : taasmoutput;parasize:longint;nostackframe:boolean);
+      var
+        hr : treference;
       begin
-        if nostackframe then
+        if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
           begin
-            { Here we need to use RETL instead of RET so it uses %o7 }
-            list.concat(Taicpu.op_none(A_RETL));
-            list.concat(Taicpu.op_none(A_NOP))
+            reference_reset(hr);
+            hr.offset:=12;
+            hr.refaddr:=addr_full;
+            if nostackframe then
+              begin
+                hr.base:=NR_O7;
+                list.concat(taicpu.op_ref_reg(A_JMPL,hr,NR_G0));
+                list.concat(Taicpu.op_none(A_NOP))
+              end
+            else
+              begin
+                { We use trivial restore in the delay slot of the JMPL instruction, as we
+                  already set result onto %i0 }
+                hr.base:=NR_I7;
+                list.concat(taicpu.op_ref_reg(A_JMPL,hr,NR_G0));
+                list.concat(Taicpu.op_none(A_RESTORE));
+              end;
           end
         else
           begin
-            { We use trivial restore in the delay slot of the JMPL instruction, as we
-              already set result onto %i0 }
-            list.concat(Taicpu.op_none(A_RET));
-            list.concat(Taicpu.op_none(A_RESTORE));
+            if nostackframe then
+              begin
+                { Here we need to use RETL instead of RET so it uses %o7 }
+                list.concat(Taicpu.op_none(A_RETL));
+                list.concat(Taicpu.op_none(A_NOP))
+              end
+            else
+              begin
+                { We use trivial restore in the delay slot of the JMPL instruction, as we
+                  already set result onto %i0 }
+                list.concat(Taicpu.op_none(A_RET));
+                list.concat(Taicpu.op_none(A_RESTORE));
+              end;
           end;
       end;
 
@@ -1316,7 +1341,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.100  2005-01-01 13:19:09  florian
+  Revision 1.101  2005-01-07 16:22:54  florian
+    + implemented abi compliant handling of strucutured functions results on sparc platform
+
+  Revision 1.100  2005/01/01 13:19:09  florian
     * improved code generation for OP_MUL/OP_IMUL
 
   Revision 1.99  2004/12/18 15:48:06  florian

+ 15 - 2
compiler/sparc/cpupara.pas

@@ -258,7 +258,17 @@ implementation
                   paraloc^.size:=OS_32
                 else
                   paraloc^.size:=paracgsize;
-                if (intparareg<=high(tparasupregs)) then
+                { ret in param? }
+                if vo_is_funcret in hp.varoptions then
+                  begin
+                    paraloc^.loc:=LOC_REFERENCE;
+                    if side=callerside then
+                      paraloc^.reference.index:=NR_STACK_POINTER_REG
+                    else
+                      paraloc^.reference.index:=NR_FRAME_POINTER_REG;
+                    paraloc^.reference.offset:=64;
+                  end
+                else if (intparareg<=high(tparasupregs)) then
                   begin
                     paraloc^.loc:=LOC_REGISTER;
                     paraloc^.register:=newreg(R_INTREGISTER,hparasupregs^[intparareg],R_SUBWHOLE);
@@ -317,7 +327,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.51  2004-11-22 22:01:19  peter
+  Revision 1.52  2005-01-07 16:22:54  florian
+    + implemented abi compliant handling of strucutured functions results on sparc platform
+
+  Revision 1.51  2004/11/22 22:01:19  peter
     * fixed varargs
     * replaced dynarray with tlist
 

+ 17 - 1
compiler/sparc/ncpucall.pas

@@ -31,20 +31,36 @@ interface
 
     type
        tsparccallnode = class(tcgcallnode)
+         procedure extra_post_call_code;override;
        end;
 
 
 implementation
 
     uses
+      cpubase,
+      aasmtai,
+      aasmcpu,
+      paramgr,
       ncal;
 
+
+    procedure tsparccallnode.extra_post_call_code;
+      begin
+        if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
+          exprasmlist.concat(taicpu.op_const(A_UNIMP,procdefinition.rettype.def.size and $fff));
+      end;
+
+
 begin
   ccallnode:=TSparcCallNode;
 end.
 {
   $Log$
-  Revision 1.14  2004-06-20 08:55:32  florian
+  Revision 1.15  2005-01-07 16:22:54  florian
+    + implemented abi compliant handling of strucutured functions results on sparc platform
+
+  Revision 1.14  2004/06/20 08:55:32  florian
     * logs truncated
 
 }

+ 5 - 2
compiler/sparc/opcode.inc

@@ -36,7 +36,7 @@ A_SWAP,A_SWAPA,A_Ticc,A_TADDcc,A_TSUBcc,A_TADDccTV,A_TSUBccTV,
 A_TA,A_Txx,
 A_UDIV,A_UDIVcc,
 A_UMUL,A_UMULcc,
-A_UNMP,
+A_UNIMP,
 A_WRASR,A_WRY,A_WRPSR,A_WRWIM,A_WRTBR,
 A_XNOR,A_XNORcc,
 A_XOR,A_XORcc,
@@ -74,7 +74,10 @@ A_FABSq
 
 {
         $Log$
-        Revision 1.15  2004-10-03 12:42:22  florian
+        Revision 1.16  2005-01-07 16:22:54  florian
+          + implemented abi compliant handling of strucutured functions results on sparc platform
+
+        Revision 1.15  2004/10/03 12:42:22  florian
           * made sqrt, sqr and abs internal for the sparc
 
         Revision 1.14  2004/06/20 08:55:32  florian

+ 5 - 2
compiler/sparc/strinst.inc

@@ -34,7 +34,7 @@
           'ta','t',
           'udiv','udivcc',
           'umul','umulcc',
-          'unmp',
+          'unimp',
           'wrasr','wry','wrpsr','wrwim','wrtbr',
           'xnor','xnorcc',
           'xor','xorcc',
@@ -70,7 +70,10 @@
           'fabsd','fabsq'
 {
         $Log$
-        Revision 1.14  2004-10-03 12:42:22  florian
+        Revision 1.15  2005-01-07 16:22:54  florian
+          + implemented abi compliant handling of strucutured functions results on sparc platform
+
+        Revision 1.14  2004/10/03 12:42:22  florian
           * made sqrt, sqr and abs internal for the sparc
 
         Revision 1.13  2004/06/20 08:55:32  florian