Browse Source

* fixed pushing of parameters on m68k

git-svn-id: trunk@5800 -
florian 18 years ago
parent
commit
d1b6522866
2 changed files with 43 additions and 23 deletions
  1. 16 16
      compiler/m68k/cgcpu.pas
  2. 27 7
      compiler/m68k/cpupara.pas

+ 16 - 16
compiler/m68k/cgcpu.pas

@@ -54,7 +54,7 @@ unit cgcpu;
         procedure a_load_reg_reg(list : TAsmList;fromsize,tosize : tcgsize;reg1,reg2 : tregister);override;
         procedure a_load_reg_reg(list : TAsmList;fromsize,tosize : tcgsize;reg1,reg2 : tregister);override;
         procedure a_load_ref_reg(list : TAsmList;fromsize,tosize : tcgsize;const ref : treference;register : tregister);override;
         procedure a_load_ref_reg(list : TAsmList;fromsize,tosize : tcgsize;const ref : treference;register : tregister);override;
         procedure a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);override;
         procedure a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);override;
-        
+
         procedure a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);override;
         procedure a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);override;
         procedure a_loadfpu_reg_reg(list: TAsmList; size: tcgsize; reg1, reg2: tregister); override;
         procedure a_loadfpu_reg_reg(list: TAsmList; size: tcgsize; reg1, reg2: tregister); override;
         procedure a_loadfpu_ref_reg(list: TAsmList; size: tcgsize; const ref: treference; reg: tregister); override;
         procedure a_loadfpu_ref_reg(list: TAsmList; size: tcgsize; const ref: treference; reg: tregister); override;
@@ -66,7 +66,7 @@ unit cgcpu;
         procedure a_parammm_reg(list: TAsmList; size: tcgsize; reg: tregister;const locpara : TCGPara;shuffle : pmmshuffle); override;
         procedure a_parammm_reg(list: TAsmList; size: tcgsize; reg: tregister;const locpara : TCGPara;shuffle : pmmshuffle); override;
 
 
         procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: tcgsize; a: aint; reg: TRegister); override;
         procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: tcgsize; a: aint; reg: TRegister); override;
-        procedure a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference); override;
+//        procedure a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference); override;
         procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); override;
         procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); override;
 
 
         procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
         procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
@@ -236,19 +236,18 @@ unit cgcpu;
         ref : treference;
         ref : treference;
       begin
       begin
         writeln('a_param_reg');
         writeln('a_param_reg');
-        
+
         { it's probably necessary to port this from x86 later, or provide an m68k solution (KB) }
         { it's probably necessary to port this from x86 later, or provide an m68k solution (KB) }
 {$WARNING FIX ME! check_register_size()}
 {$WARNING FIX ME! check_register_size()}
         // check_register_size(size,r);
         // check_register_size(size,r);
-        { remove "not" to trigger the location bug (KB) }
-        if not use_push(cgpara) then
+        if use_push(cgpara) then
           begin
           begin
             cgpara.check_simple_location;
             cgpara.check_simple_location;
             if tcgsize2size[cgpara.location^.size]>cgpara.alignment then
             if tcgsize2size[cgpara.location^.size]>cgpara.alignment then
               pushsize:=cgpara.location^.size
               pushsize:=cgpara.location^.size
             else
             else
               pushsize:=int_cgsize(cgpara.alignment);
               pushsize:=int_cgsize(cgpara.alignment);
-            
+
             reference_reset_base(ref, NR_STACK_POINTER_REG, 0);
             reference_reset_base(ref, NR_STACK_POINTER_REG, 0);
             ref.direction := dir_dec;
             ref.direction := dir_dec;
             list.concat(taicpu.op_reg_ref(A_MOVE,tcgsize2opsize[pushsize],makeregsize(list,r,pushsize),ref));
             list.concat(taicpu.op_reg_ref(A_MOVE,tcgsize2opsize[pushsize],makeregsize(list,r,pushsize),ref));
@@ -266,7 +265,7 @@ unit cgcpu;
         writeln('a_param_const');
         writeln('a_param_const');
 
 
         { remove "not" to trigger the location bug (KB) }
         { remove "not" to trigger the location bug (KB) }
-        if not use_push(cgpara) then
+        if use_push(cgpara) then
           begin
           begin
             cgpara.check_simple_location;
             cgpara.check_simple_location;
             if tcgsize2size[cgpara.location^.size]>cgpara.alignment then
             if tcgsize2size[cgpara.location^.size]>cgpara.alignment then
@@ -294,12 +293,12 @@ unit cgcpu;
         begin
         begin
           if not assigned(paraloc) then
           if not assigned(paraloc) then
             exit;
             exit;
-{$WARNING FIX ME!!! this also triggers location bug }    
+{$WARNING FIX ME!!! this also triggers location bug }
           {if (paraloc^.loc<>LOC_REFERENCE) or
           {if (paraloc^.loc<>LOC_REFERENCE) or
              (paraloc^.reference.index<>NR_STACK_POINTER_REG) or
              (paraloc^.reference.index<>NR_STACK_POINTER_REG) or
              (tcgsize2size[paraloc^.size]>sizeof(aint)) then
              (tcgsize2size[paraloc^.size]>sizeof(aint)) then
             internalerror(200501162);}
             internalerror(200501162);}
-            
+
           { Pushes are needed in reverse order, add the size of the
           { Pushes are needed in reverse order, add the size of the
             current location to the offset where to load from. This
             current location to the offset where to load from. This
             prevents wrong calculations for the last location when
             prevents wrong calculations for the last location when
@@ -313,15 +312,15 @@ unit cgcpu;
             pushsize:=paraloc^.size
             pushsize:=paraloc^.size
           else
           else
             pushsize:=int_cgsize(cgpara.alignment);
             pushsize:=int_cgsize(cgpara.alignment);
-            
+
           reference_reset_base(ref, NR_STACK_POINTER_REG, 0);
           reference_reset_base(ref, NR_STACK_POINTER_REG, 0);
           ref.direction := dir_dec;
           ref.direction := dir_dec;
-        
+
           if tcgsize2size[paraloc^.size]<cgpara.alignment then
           if tcgsize2size[paraloc^.size]<cgpara.alignment then
             begin
             begin
               tmpreg:=getintregister(list,pushsize);
               tmpreg:=getintregister(list,pushsize);
               a_load_ref_reg(list,paraloc^.size,pushsize,href,tmpreg);
               a_load_ref_reg(list,paraloc^.size,pushsize,href,tmpreg);
-              list.concat(taicpu.op_reg_ref(A_MOVE,tcgsize2opsize[pushsize],tmpreg,ref));              
+              list.concat(taicpu.op_reg_ref(A_MOVE,tcgsize2opsize[pushsize],tmpreg,ref));
             end
             end
           else
           else
               list.concat(taicpu.op_ref_ref(A_MOVE,tcgsize2opsize[pushsize],href,ref));
               list.concat(taicpu.op_ref_ref(A_MOVE,tcgsize2opsize[pushsize],href,ref));
@@ -334,8 +333,7 @@ unit cgcpu;
         writeln('a_param_ref');
         writeln('a_param_ref');
 
 
         { cgpara.size=OS_NO requires a copy on the stack }
         { cgpara.size=OS_NO requires a copy on the stack }
-        { remove "not" to trigger the location bug (KB) }
-        if not use_push(cgpara) then
+        if use_push(cgpara) then
           begin
           begin
             { Record copy? }
             { Record copy? }
             if (cgpara.size in [OS_NO,OS_F64]) or (size=OS_NO) then
             if (cgpara.size in [OS_NO,OS_F64]) or (size=OS_NO) then
@@ -497,8 +495,8 @@ unit cgcpu;
          { move to destination reference }
          { move to destination reference }
          list.concat(taicpu.op_reg_ref(A_MOVE,TCGSize2OpSize[fromsize],register,href));
          list.concat(taicpu.op_reg_ref(A_MOVE,TCGSize2OpSize[fromsize],register,href));
       end;
       end;
-      
-      
+
+
     procedure tcg68k.a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
     procedure tcg68k.a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
       var
       var
         aref: treference;
         aref: treference;
@@ -772,6 +770,7 @@ unit cgcpu;
          end;
          end;
       end;
       end;
 
 
+{
     procedure tcg68k.a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
     procedure tcg68k.a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
       var
       var
         opcode: tasmop;
         opcode: tasmop;
@@ -796,6 +795,7 @@ unit cgcpu;
             end;
             end;
         end;
         end;
       end;
       end;
+}
 
 
     procedure tcg68k.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister);
     procedure tcg68k.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister);
       var
       var

+ 27 - 7
compiler/m68k/cpupara.pas

@@ -30,6 +30,7 @@ unit cpupara;
     uses
     uses
       globtype,
       globtype,
       cpubase,
       cpubase,
+      aasmdata,
       symconst,symtype,symdef,symsym,
       symconst,symtype,symdef,symsym,
       parabase,paramgr,cgbase;
       parabase,paramgr,cgbase;
 
 
@@ -44,12 +45,13 @@ unit cpupara;
           function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
           function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
           function push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;override;
           function push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;override;
           procedure create_funcretloc_info(p : tabstractprocdef; side: tcallercallee);
           procedure create_funcretloc_info(p : tabstractprocdef; side: tcallercallee);
+          procedure createtempparaloc(list: TAsmList;calloption : tproccalloption;parasym : tparavarsym;var cgpara:TCGPara);override;
          private
          private
-           procedure init_values(var curintreg, curfloatreg: tsuperregister; var cur_stack_offset: aword);
-           function create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee; paras: tparalist;
+          procedure init_values(var curintreg, curfloatreg: tsuperregister; var cur_stack_offset: aword);
+          function create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee; paras: tparalist;
                                                var curintreg, curfloatreg: tsuperregister; var cur_stack_offset: aword):longint;
                                                var curintreg, curfloatreg: tsuperregister; var cur_stack_offset: aword):longint;
-           function parseparaloc(p : tparavarsym;const s : string) : boolean;override;
-           function parsefuncretloc(p : tabstractprocdef; const s : string) : boolean;override;
+          function parseparaloc(p : tparavarsym;const s : string) : boolean;override;
+          function parsefuncretloc(p : tabstractprocdef; const s : string) : boolean;override;
        end;
        end;
 
 
   implementation
   implementation
@@ -85,9 +87,9 @@ unit cpupara;
     function getparaloc(p : tdef) : tcgloc;
     function getparaloc(p : tdef) : tcgloc;
 
 
       begin
       begin
+         result:=LOC_REFERENCE;
          { Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
          { Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
            if push_addr_param for the def is true
            if push_addr_param for the def is true
-         }
          case p.typ of
          case p.typ of
             orddef:
             orddef:
               result:=LOC_REGISTER;
               result:=LOC_REGISTER;
@@ -138,6 +140,7 @@ unit cpupara;
             else
             else
               internalerror(2002071001);
               internalerror(2002071001);
          end;
          end;
+         }
       end;
       end;
 
 
 
 
@@ -284,7 +287,7 @@ unit cpupara;
 	stack_offset:=cur_stack_offset;
 	stack_offset:=cur_stack_offset;
 
 
         parasize:=0;
         parasize:=0;
-	
+
         for i:=0 to p.paras.count-1 do
         for i:=0 to p.paras.count-1 do
           begin
           begin
             hp:=tparavarsym(paras[i]);
             hp:=tparavarsym(paras[i]);
@@ -339,7 +342,7 @@ unit cpupara;
                     paralen := tcgsize2size[OS_ADDR];
                     paralen := tcgsize2size[OS_ADDR];
                   end;
                   end;
               end;
               end;
-              
+
             hp.paraloc[side].alignment:=std_param_align;
             hp.paraloc[side].alignment:=std_param_align;
             hp.paraloc[side].size:=paracgsize;
             hp.paraloc[side].size:=paracgsize;
             hp.paraloc[side].intsize:=paralen;
             hp.paraloc[side].intsize:=paralen;
@@ -539,6 +542,23 @@ unit cpupara;
         result:=true;
         result:=true;
       end;
       end;
 
 
+
+    procedure tm68kparamanager.createtempparaloc(list: TAsmList;calloption : tproccalloption;parasym : tparavarsym;var cgpara:TCGPara);
+      var
+        paraloc : pcgparalocation;
+      begin
+        paraloc:=parasym.paraloc[callerside].location;
+        { No need for temps when value is pushed }
+        if not(use_fixed_stack) and
+           assigned(paraloc) and
+           (paraloc^.loc=LOC_REFERENCE) and
+           (paraloc^.reference.index=NR_STACK_POINTER_REG) then
+          duplicateparaloc(list,calloption,parasym,cgpara)
+        else
+          inherited createtempparaloc(list,calloption,parasym,cgpara);
+      end;
+
+
 begin
 begin
   paramanager:=tm68kparamanager.create;
   paramanager:=tm68kparamanager.create;
 end.
 end.