瀏覽代碼

* refactored the handling of the frame pointer and base pointer to use local temps instead

git-svn-id: branches/wasm@46837 -
nickysn 4 年之前
父節點
當前提交
4a5e2dbd23
共有 2 個文件被更改,包括 22 次插入13 次删除
  1. 18 12
      compiler/wasm32/hlcgcpu.pas
  2. 4 1
      compiler/wasm32/symcpu.pas

+ 18 - 12
compiler/wasm32/hlcgcpu.pas

@@ -1626,12 +1626,12 @@ implementation
   procedure thlcgwasm.g_proc_entry(list: TAsmList; localsize: longint; nostackframe: boolean);
   procedure thlcgwasm.g_proc_entry(list: TAsmList; localsize: longint; nostackframe: boolean);
     var
     var
       functype: tai_functype;
       functype: tai_functype;
-      pd: tprocdef;
+      pd: tcpuprocdef;
       i: integer;
       i: integer;
       prm: tcpuparavarsym;
       prm: tcpuparavarsym;
       bt: TWasmBasicType;
       bt: TWasmBasicType;
     begin
     begin
-      pd:=current_procinfo.procdef;
+      pd:=tcpuprocdef(current_procinfo.procdef);
       functype:=tai_functype.create(pd.mangledname);
       functype:=tai_functype.create(pd.mangledname);
       if Assigned(pd.paras) and (pd.paras.Count>0) then
       if Assigned(pd.paras) and (pd.paras.Count>0) then
         begin
         begin
@@ -1670,6 +1670,9 @@ implementation
         end;
         end;
       list.Concat(functype);
       list.Concat(functype);
 
 
+      tg.gethltemp(list,voidpointertype,voidpointertype.size,tt_persistent,pd.frame_pointer_ref);
+      tg.gethltemp(list,voidpointertype,voidpointertype.size,tt_persistent,pd.base_pointer_ref);
+
       { the localsize is based on tg.lasttemp -> already in terms of stack
       { the localsize is based on tg.lasttemp -> already in terms of stack
         slots rather than bytes }
         slots rather than bytes }
       //list.concat(tai_directive.Create(asd_jlimit,'locals '+tostr(localsize)));
       //list.concat(tai_directive.Create(asd_jlimit,'locals '+tostr(localsize)));
@@ -1677,28 +1680,31 @@ implementation
         and it uses one stack slot }
         and it uses one stack slot }
       //if (current_procinfo.procdef.proctypeoption=potype_proginit) then
       //if (current_procinfo.procdef.proctypeoption=potype_proginit) then
         //fmaxevalstackheight:=max(1,fmaxevalstackheight);
         //fmaxevalstackheight:=max(1,fmaxevalstackheight);
-      list.Concat(tai_local.create(wbt_i32, FRAME_POINTER_SYM)); //TWasmBasicType
-      list.Concat(tai_local.create(wbt_i32, BASE_POINTER_SYM)); //TWasmBasicType
+      list.Concat(tai_local.create(wbt_i32,FRAME_POINTER_SYM)); //TWasmBasicType
+      list.Concat(tai_local.create(wbt_i32,BASE_POINTER_SYM)); //TWasmBasicType
 
 
-      list.Concat(taicpu.op_sym(a_get_global , current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_LABEL)));
-      list.Concat(taicpu.op_sym(a_set_local, current_asmdata.RefAsmSymbol(BASE_POINTER_SYM,AT_LABEL)));
+      list.Concat(taicpu.op_sym(a_get_global,current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_LABEL)));
+      list.Concat(taicpu.op_ref(a_set_local,pd.base_pointer_ref));
 
 
       if (localsize>0) then begin
       if (localsize>0) then begin
-        list.Concat(taicpu.op_sym(a_get_local, current_asmdata.RefAsmSymbol(BASE_POINTER_SYM,AT_LABEL)));
+        list.Concat(taicpu.op_ref(a_get_local,pd.base_pointer_ref));
         list.concat(taicpu.op_const(a_i32_const, localsize ));
         list.concat(taicpu.op_const(a_i32_const, localsize ));
         list.concat(taicpu.op_none(a_i32_sub));
         list.concat(taicpu.op_none(a_i32_sub));
-        list.Concat(taicpu.op_sym(a_set_local, current_asmdata.RefAsmSymbol(FRAME_POINTER_SYM,AT_LABEL)));
-        list.Concat(taicpu.op_sym(a_get_local, current_asmdata.RefAsmSymbol(FRAME_POINTER_SYM,AT_LABEL)));
-        list.Concat(taicpu.op_sym(a_set_global, current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_LABEL)));
+        list.Concat(taicpu.op_ref(a_set_local,pd.frame_pointer_ref));
+        list.Concat(taicpu.op_ref(a_get_local,pd.frame_pointer_ref));
+        list.Concat(taicpu.op_sym(a_set_global,current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_LABEL)));
       end;
       end;
 
 
       //list.concat(tai_directive.Create(asd_jlimit,'stack '+tostr(fmaxevalstackheight)));
       //list.concat(tai_directive.Create(asd_jlimit,'stack '+tostr(fmaxevalstackheight)));
     end;
     end;
 
 
   procedure thlcgwasm.g_proc_exit(list: TAsmList; parasize: longint; nostackframe: boolean);
   procedure thlcgwasm.g_proc_exit(list: TAsmList; parasize: longint; nostackframe: boolean);
+    var
+      pd: tcpuprocdef;
     begin
     begin
-      list.Concat(taicpu.op_sym(a_get_local, current_asmdata.RefAsmSymbol(BASE_POINTER_SYM,AT_LABEL)));
-      list.Concat(taicpu.op_sym(a_set_global , current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_LABEL)));
+      pd:=tcpuprocdef(current_procinfo.procdef);
+      list.Concat(taicpu.op_ref(a_get_local,pd.base_pointer_ref));
+      list.Concat(taicpu.op_sym(a_set_global,current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_LABEL)));
 
 
       list.concat(taicpu.op_none(a_return));
       list.concat(taicpu.op_none(a_return));
     end;
     end;

+ 4 - 1
compiler/wasm32/symcpu.pas

@@ -29,7 +29,8 @@ uses
   globtype,
   globtype,
   aasmdata,
   aasmdata,
   symtype,
   symtype,
-  symdef,symsym;
+  symdef,symsym,
+  cgutils;
 
 
 type
 type
   { defs }
   { defs }
@@ -98,6 +99,8 @@ type
   { tcpuprocdef }
   { tcpuprocdef }
 
 
   tcpuprocdef = class(tprocdef)
   tcpuprocdef = class(tprocdef)
+    frame_pointer_ref,
+    base_pointer_ref: treference;
     { generated assembler code; used by WebAssembly backend so it can afterwards
     { generated assembler code; used by WebAssembly backend so it can afterwards
       easily write out all methods grouped per class }
       easily write out all methods grouped per class }
     exprasmlist  : TAsmList;
     exprasmlist  : TAsmList;