2
0
Эх сурвалжийг харах

* parameter handling updated

mazen 23 жил өмнө
parent
commit
f170b21371

+ 6 - 1
compiler/ncgutil.pas

@@ -1315,6 +1315,7 @@ implementation
              { move register parameters which aren't regable into memory                                          }
              { move register parameters which aren't regable into memory                                          }
              { we do this after init_paras because it saves some code in init_paras if parameters are in register }
              { we do this after init_paras because it saves some code in init_paras if parameters are in register }
              { instead in memory                                                                                  }
              { instead in memory                                                                                  }
+{$IFNDEF SPARC}
              hp:=tparaitem(procinfo.procdef.para.first);
              hp:=tparaitem(procinfo.procdef.para.first);
              while assigned(hp) do
              while assigned(hp) do
                begin
                begin
@@ -1352,6 +1353,7 @@ implementation
                     end;
                     end;
                   hp:=tparaitem(hp.next);
                   hp:=tparaitem(hp.next);
                end;
                end;
+{$ENDIF SPARC}
           end;
           end;
 
 
         if (not inlined) then
         if (not inlined) then
@@ -1846,7 +1848,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.56  2002-10-16 19:01:43  peter
+  Revision 1.57  2002-11-03 20:22:40  mazen
+  * parameter handling updated
+
+  Revision 1.56  2002/10/16 19:01:43  peter
     + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
     + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
       implicit exception frames for procedures with initialized variables
       implicit exception frames for procedures with initialized variables
       and for constructors. The default is on for compatibility
       and for constructors. The default is on for compatibility

+ 14 - 31
compiler/sparc/cgcpu.pas

@@ -1,12 +1,4 @@
-{*****************************************************************************}
-{ File                   : cgcpu.pas                                          }
-{ Author                 : Mazen NEIFER                                       }
-{ Project                : Free Pascal Compiler (FPC)                         }
-{ Creation date          : 2002\04\26                                         }
-{ Licence                : GPL                                                }
-{ Bug report             : [email protected]                        }
-{*****************************************************************************}
-{
+{******************************************************************************
     $Id$
     $Id$
 
 
     Copyright (c) 1998-2000 by Florian Klaempfl
     Copyright (c) 1998-2000 by Florian Klaempfl
@@ -24,7 +16,7 @@
     You should have received a copy of the GNU General Public License
     You should have received a copy of the GNU General Public License
     along with this program;if not, write to the Free Software
     along with this program;if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************}
+ *****************************************************************************}
 UNIT cgcpu;
 UNIT cgcpu;
 {This unit implements the code generator for the SPARC architecture}
 {This unit implements the code generator for the SPARC architecture}
 {$INCLUDE fpcdefs.inc}
 {$INCLUDE fpcdefs.inc}
@@ -108,7 +100,7 @@ IMPLEMENTATION
 USES
 USES
   globtype,globals,verbose,systems,cutils,
   globtype,globals,verbose,systems,cutils,
   symdef,symsym,defbase,paramgr,
   symdef,symsym,defbase,paramgr,
-  rgobj,tgobj,rgcpu;
+  rgobj,tgobj,rgcpu,cpupi;
     { we implement the following routines because otherwise we can't }
     { we implement the following routines because otherwise we can't }
     { instantiate the class since it's abstract                      }
     { instantiate the class since it's abstract                      }
 procedure tcgSPARC.a_param_reg(list:TAasmOutput;size:tcgsize;r:tregister;CONST LocPara:TParaLocation);
 procedure tcgSPARC.a_param_reg(list:TAasmOutput;size:tcgsize;r:tregister;CONST LocPara:TParaLocation);
@@ -815,34 +807,22 @@ procedure tcgSPARC.g_flags2reg(list:TAasmOutput;Size:TCgSize;CONST f:tresflags;r
 
 
 { *********** entry/exit code and address loading ************ }
 { *********** entry/exit code and address loading ************ }
 
 
-procedure tcgSPARC.g_stackframe_entry(list:TAasmOutput;localsize:LongInt);
+procedure tcgSPARC.g_stackframe_entry(list:TAasmOutput;LocalSize:LongInt);
   var
   var
     href:TReference;
     href:TReference;
     i:integer;
     i:integer;
     again:tasmlabel;
     again:tasmlabel;
   begin
   begin
-{According the the SPARC ABI the standard stack frame must include :
-  *  16 word save for the in and local registers in case of overflow/underflow.
-this save area always must exist at the %o6+0,
-  *  software conventions requires space for the aggregate return value pointer, even if the word is not used,
-  *  althogh the first six words of arguments reside in registers, the standard
-stack frame reserves space for them. Arguments beond the sixth reside on the
-stack as in the Intel architecture,
-  * other areas depend on the compiler and the code being compiled. The
-standard calling sequence does not define a maximum stack frame size, nor does
-it restrict how a language system uses the "unspecified" areas of the standard
-stack frame.}
-    Dec(LocalSize,(16+1+5)*4);
 {Althogh the SPARC architecture require only word alignment, software
 {Althogh the SPARC architecture require only word alignment, software
 convention and the operating system require every stack frame to be double word
 convention and the operating system require every stack frame to be double word
 aligned}
 aligned}
-    LocalSize:=(LocalSize+3)and $FFFFFFFC;
-{Execute the SAVE instruction to get a new register window and get a new stack
-frame. In the "SAVE %i6,size,%i6" the first %i6 is related to the state before
-execution of the SAVE instrucion so it is the caller %i6, when the %i6 after
-execution of that instrucion is the called function stack pointer}
+    LocalSize:=(LocalSize+7)and $FFFFFFF8;
+{Execute the SAVE instruction to get a new register window and create a new
+stack frame. In the "SAVE %i6,size,%i6" the first %i6 is related to the state
+before execution of the SAVE instrucion so it is the caller %i6, when the %i6
+after execution of that instruction is the called function stack pointer}
     with list do
     with list do
-      concat(Taicpu.Op_reg_const_reg(A_SAVE,S_SW,Stack_Pointer_Reg,localsize,Stack_Pointer_Reg));
+      concat(Taicpu.Op_reg_const_reg(A_SAVE,S_SW,Stack_Pointer_Reg,LocalSize,Stack_Pointer_Reg));
   end;
   end;
 procedure tcgSPARC.g_restore_frame_pointer(list:TAasmOutput);
 procedure tcgSPARC.g_restore_frame_pointer(list:TAasmOutput);
   begin
   begin
@@ -1274,7 +1254,10 @@ BEGIN
 END.
 END.
 {
 {
   $Log$
   $Log$
-  Revision 1.19  2002-10-28 20:59:17  mazen
+  Revision 1.20  2002-11-03 20:22:40  mazen
+  * parameter handling updated
+
+  Revision 1.19  2002/10/28 20:59:17  mazen
   * TOpSize values changed S_L --> S_SW
   * TOpSize values changed S_L --> S_SW
 
 
   Revision 1.18  2002/10/22 13:43:01  mazen
   Revision 1.18  2002/10/22 13:43:01  mazen

+ 5 - 1
compiler/sparc/cpupara.pas

@@ -31,6 +31,7 @@ type
     (which must be an integer parameter)
     (which must be an integer parameter)
     @param(nr Parameter number of routine, starting from 1)}
     @param(nr Parameter number of routine, starting from 1)}
     function GetIntParaLoc(nr:longint):TParaLocation;override;
     function GetIntParaLoc(nr:longint):TParaLocation;override;
+    {Creates location information related to the parameter of the function}
     procedure create_param_loc_info(p:TAbstractProcDef);override;
     procedure create_param_loc_info(p:TAbstractProcDef);override;
     {Returns the location where the invisible parameter for structured function
     {Returns the location where the invisible parameter for structured function
     results will be passed.}
     results will be passed.}
@@ -282,7 +283,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.8  2002-10-13 21:46:07  mazen
+  Revision 1.9  2002-11-03 20:22:40  mazen
+  * parameter handling updated
+
+  Revision 1.8  2002/10/13 21:46:07  mazen
   * assembler output format fixed
   * assembler output format fixed
 
 
   Revision 1.7  2002/10/10 19:57:51  mazen
   Revision 1.7  2002/10/10 19:57:51  mazen

+ 28 - 11
compiler/sparc/cpupi.pas

@@ -34,6 +34,17 @@ type
     {max of space need for parameters, currently used by the PowerPC port only}
     {max of space need for parameters, currently used by the PowerPC port only}
     maxpushedparasize:aword;
     maxpushedparasize:aword;
     constructor create;override;
     constructor create;override;
+{According the the SPARC ABI the standard stack frame must include :
+  *  16 word save for the in and local registers in case of overflow/underflow.
+this save area always must exist at the %o6+0,
+  *  software conventions requires space for the aggregate return value pointer, even if the word is not used,
+  *  althogh the first six words of arguments reside in registers, the standard
+stack frame reserves space for them. Arguments beond the sixth reside on the
+stack as in the Intel architecture,
+  * other areas depend on the compiler and the code being compiled. The
+standard calling sequence does not define a maximum stack frame size, nor does
+it restrict how a language system uses the "unspecified" areas of the standard
+stack frame.}
     procedure after_header;override;
     procedure after_header;override;
     procedure after_pass1;override;
     procedure after_pass1;override;
   end;
   end;
@@ -50,26 +61,32 @@ constructor TSparcprocinfo.create;
 	end;
 	end;
 procedure TSparcprocinfo.after_header;
 procedure TSparcprocinfo.after_header;
 	begin
 	begin
-  	{ this value is necessary for nested procedures }
-		procdef.localst.address_fixup:=align(procdef.parast.datasize,16);
+  	{Reserve the stack for copying parameters passeѕ into registers}
+    procdef.parast.address_fixup:=(16+1)*4;
 	end;
 	end;
-procedure TSparcprocinfo.after_pass1;
+procedure TSparcProcInfo.after_pass1;
 	begin
 	begin
-		procdef.parast.address_fixup:=align(maxpushedparasize,16);
-	  WriteLn('Parameter copies start at: %i6+'+tostr(procdef.parast.address_fixup));
-    procdef.localst.address_fixup:=align(procdef.parast.address_fixup+procdef.parast.datasize,16);
-		WriteLn(strpnew('Locals start at: %o6+'+tostr(procdef.localst.address_fixup)));
-		procinfo.firsttemp_offset:=align(procdef.localst.address_fixup+procdef.localst.datasize,16);
-	  WriteLn('Temp. space start: %o6+'+tostr(procinfo.firsttemp_offset));
+    if(procdef.parast.datasize>6*4)
+    then
+      procdef.localst.address_fixup:=procdef.parast.datasize+(16+1)*4
+    else
+      procdef.localst.address_fixup:=6*4+(16+1)*4;
+		procinfo.firsttemp_offset:=procdef.localst.address_fixup+procdef.localst.datasize;
+	  WriteLn('Parameter copies start at: %i6-'+tostr(procdef.parast.address_fixup));
+		WriteLn('Locals start at: %o6-'+tostr(procdef.localst.address_fixup));
+	  WriteLn('Temp. space start: %o6-'+tostr(procinfo.firsttemp_offset));
 		tg.firsttemp:=procinfo.firsttemp_offset;
 		tg.firsttemp:=procinfo.firsttemp_offset;
 		tg.lasttemp:=procinfo.firsttemp_offset;
 		tg.lasttemp:=procinfo.firsttemp_offset;
 	end;
 	end;
 begin
 begin
-  cprocinfo:=TSparcprocinfo;
+  cprocinfo:=TSparcProcInfo;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.4  2002-10-20 19:01:38  mazen
+  Revision 1.5  2002-11-03 20:22:40  mazen
+  * parameter handling updated
+
+  Revision 1.4  2002/10/20 19:01:38  mazen
   + op_raddr_reg and op_caddr_reg added to fix functions prologue
   + op_raddr_reg and op_caddr_reg added to fix functions prologue
 
 
   Revision 1.3  2002/10/10 15:10:39  mazen
   Revision 1.3  2002/10/10 15:10:39  mazen