Browse Source

* fixed several issues with nested procedures

florian 22 years ago
parent
commit
7ec9711f9a

+ 26 - 7
compiler/powerpc/cgcpu.pas

@@ -963,6 +963,13 @@ const
         r.enum:=R_INTREGISTER;
         r.enum:=R_INTREGISTER;
         r.number:=NR_R0;
         r.number:=NR_R0;
         a_reg_alloc(list,r);
         a_reg_alloc(list,r);
+
+        if aktprocdef.parast.symtablelevel>1 then
+          begin
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_R11;
+             a_reg_alloc(list,r);
+          end;
         { allocate registers containing reg parameters }
         { allocate registers containing reg parameters }
         r.enum := R_INTREGISTER;
         r.enum := R_INTREGISTER;
         for regcounter2 := RS_R3 to RS_R10 do
         for regcounter2 := RS_R3 to RS_R10 do
@@ -1011,7 +1018,7 @@ const
         if usesfpr or usesgpr then
         if usesfpr or usesgpr then
           begin
           begin
              r.enum:=R_INTREGISTER;
              r.enum:=R_INTREGISTER;
-             r.number:=NR_R11;
+             r.number:=NR_R12;
              a_reg_alloc(list,r);
              a_reg_alloc(list,r);
              { save end of fpr save area }
              { save end of fpr save area }
              list.concat(taicpu.op_reg_reg(A_MR,r,rsp));
              list.concat(taicpu.op_reg_reg(A_MR,r,rsp));
@@ -1063,7 +1070,7 @@ const
 
 
              { compute end of gpr save area }
              { compute end of gpr save area }
              r.enum:=R_INTREGISTER;
              r.enum:=R_INTREGISTER;
-             r.number:=NR_R11;
+             r.number:=NR_R12;
              list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,-(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
              list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,-(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
           end;
           end;
 
 
@@ -1080,13 +1087,13 @@ const
                a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
                a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
              }
              }
              r.enum:=R_INTREGISTER;
              r.enum:=R_INTREGISTER;
-             r.number:=NR_R11;
+             r.number:=NR_R12;
              reference_reset_base(href,r,-((NR_R31-firstreggpr.number) shr 8+1)*4);
              reference_reset_base(href,r,-((NR_R31-firstreggpr.number) shr 8+1)*4);
              list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
              list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
           end;
           end;
 
 
         r.enum:=R_INTREGISTER;
         r.enum:=R_INTREGISTER;
-        r.number:=NR_R11;
+        r.number:=NR_R12;
         if usesfpr or usesgpr then
         if usesfpr or usesgpr then
           a_reg_dealloc(list,r);
           a_reg_dealloc(list,r);
 
 
@@ -1113,6 +1120,15 @@ const
           new_reference(STACK_POINTER_REG,LA_CR)));
           new_reference(STACK_POINTER_REG,LA_CR)));
         a_reg_dealloc(list,R_0); }
         a_reg_dealloc(list,R_0); }
         { now comes the AltiVec context save, not yet implemented !!! }
         { now comes the AltiVec context save, not yet implemented !!! }
+
+        { if we're in a nested procedure, we've to save R11 }
+        if aktprocdef.parast.symtablelevel>2 then
+          begin
+             r.enum:=R_INTREGISTER;
+             r.number:=NR_R11;
+             reference_reset_base(href,rsp,procinfo.framepointer_offset);
+             list.concat(taicpu.op_reg_ref(A_STW,r,href));
+          end;
       end;
       end;
 
 
     procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
     procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
@@ -1165,7 +1181,7 @@ const
              r.enum:=R_INTREGISTER;
              r.enum:=R_INTREGISTER;
              r.number:=NR_STACK_POINTER_REG;
              r.number:=NR_STACK_POINTER_REG;
              r2.enum:=R_INTREGISTER;
              r2.enum:=R_INTREGISTER;
-             r2.number:=NR_R11;
+             r2.number:=NR_R12;
              if usesfpr then
              if usesfpr then
                list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize-(ord(R_F31)-ord(firstregfpu.enum)+1)*8))
                list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize-(ord(R_F31)-ord(firstregfpu.enum)+1)*8))
              else
              else
@@ -1185,7 +1201,7 @@ const
           begin
           begin
              { address of fpr save area to r11 }
              { address of fpr save area to r11 }
              r.enum:=R_INTREGISTER;
              r.enum:=R_INTREGISTER;
-             r.number:=NR_R11;
+             r.number:=NR_R12;
              list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
              list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
              {
              {
              if (procinfo.flags and pi_do_call)<>0 then
              if (procinfo.flags and pi_do_call)<>0 then
@@ -2337,7 +2353,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.80  2003-04-23 22:18:01  peter
+  Revision 1.81  2003-04-24 11:24:00  florian
+    * fixed several issues with nested procedures
+
+  Revision 1.80  2003/04/23 22:18:01  peter
     * fixes to get rtl compiled
     * fixes to get rtl compiled
 
 
   Revision 1.79  2003/04/23 12:35:35  florian
   Revision 1.79  2003/04/23 12:35:35  florian

+ 5 - 2
compiler/powerpc/cpunode.pas

@@ -30,7 +30,7 @@ unit cpunode;
 
 
     uses
     uses
        { generic nodes }
        { generic nodes }
-       ncgbas,ncgld,ncgflw,ncgcnv,ncgmem,ncgcon,ncgcal,ncgset,ncginl,
+       ncgbas,ncgld,ncgflw,ncgcnv,ncgmem,ncgcon,ncgcal,ncgset,ncginl,ncgopt,
        { to be able to only parts of the generic code,
        { to be able to only parts of the generic code,
          the processor specific nodes must be included
          the processor specific nodes must be included
          after the generic one (FK)
          after the generic one (FK)
@@ -52,7 +52,10 @@ unit cpunode;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.15  2002-08-13 21:40:58  florian
+  Revision 1.16  2003-04-24 11:24:00  florian
+    * fixed several issues with nested procedures
+
+  Revision 1.15  2002/08/13 21:40:58  florian
     * more fixes for ppc calling conventions
     * more fixes for ppc calling conventions
 
 
   Revision 1.14  2002/08/11 11:39:12  jonas
   Revision 1.14  2002/08/11 11:39:12  jonas

+ 6 - 3
compiler/powerpc/cpupi.pas

@@ -66,7 +66,7 @@ unit cpupi;
     procedure tppcprocinfo.after_header;
     procedure tppcprocinfo.after_header;
       begin
       begin
          procdef.parast.address_fixup:=0;
          procdef.parast.address_fixup:=0;
-         if assigned(procdef.localst) and (procdef.localst.symtablelevel>1) then
+         if assigned(procdef.parast) and (procdef.parast.symtablelevel>1) then
            begin
            begin
               procinfo.framepointer_offset:=procdef.parast.address_fixup;
               procinfo.framepointer_offset:=procdef.parast.address_fixup;
               inc(procdef.parast.address_fixup,4);
               inc(procdef.parast.address_fixup,4);
@@ -111,7 +111,7 @@ unit cpupi;
 //             Already done with an "inc" above now, not sure if it's correct (JM)
 //             Already done with an "inc" above now, not sure if it's correct (JM)
              procdef.localst.address_fixup:=procdef.parast.address_fixup+procdef.parast.datasize;
              procdef.localst.address_fixup:=procdef.parast.address_fixup+procdef.parast.datasize;
 
 
-{ 
+{
              Already done with an "inc" above, should be correct (JM)
              Already done with an "inc" above, should be correct (JM)
              if assigned(procdef.funcretsym) and
              if assigned(procdef.funcretsym) and
                not(paramanager.ret_in_param(procdef.rettype.def,procdef.proccalloption)) then
                not(paramanager.ret_in_param(procdef.rettype.def,procdef.proccalloption)) then
@@ -136,7 +136,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.8  2003-04-06 16:39:11  jonas
+  Revision 1.9  2003-04-24 11:24:00  florian
+    * fixed several issues with nested procedures
+
+  Revision 1.8  2003/04/06 16:39:11  jonas
     * don't generate entry/exit code for assembler procedures
     * don't generate entry/exit code for assembler procedures
 
 
   Revision 1.7  2003/04/05 21:09:32  jonas
   Revision 1.7  2003/04/05 21:09:32  jonas

+ 10 - 2
compiler/powerpc/nppccal.pas

@@ -89,7 +89,12 @@ implementation
            but it cannot be more !! }
            but it cannot be more !! }
        else if (lexlevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
        else if (lexlevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
          begin
          begin
-            // cg.a_param_reg(exprasmlist,OS_ADDR,procinfo.framepointer,paramanager.getframepointerloc(procinfo.procdef));
+            { pass the same framepointer as the current procedure got }
+            hregister1.enum:=R_INTREGISTER;
+            hregister1.number:=NR_R1;
+            hregister2.enum:=R_INTREGISTER;
+            hregister2.number:=NR_R11;
+            exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,hregister2,hregister1,procinfo.framepointer_offset));
          end
          end
        else if (lexlevel>(tprocdef(procdefinition).parast.symtablelevel)) then
        else if (lexlevel>(tprocdef(procdefinition).parast.symtablelevel)) then
          begin
          begin
@@ -116,7 +121,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.6  2003-04-23 12:35:35  florian
+  Revision 1.7  2003-04-24 11:24:00  florian
+    * fixed several issues with nested procedures
+
+  Revision 1.6  2003/04/23 12:35:35  florian
     * fixed several issues with powerpc
     * fixed several issues with powerpc
     + applied a patch from Jonas for nested function calls (PowerPC only)
     + applied a patch from Jonas for nested function calls (PowerPC only)
     * ...
     * ...