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

git-svn-id: branches/wasm@46837 -
This commit is contained in:
nickysn 2020-09-11 14:35:51 +00:00
parent 921ec47bc0
commit 4a5e2dbd23
2 changed files with 22 additions and 13 deletions

View File

@ -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)));
@ -1681,14 +1684,14 @@ implementation
list.Concat(tai_local.create(wbt_i32,BASE_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_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_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_ref(a_set_local,pd.frame_pointer_ref));
list.Concat(taicpu.op_sym(a_get_local, current_asmdata.RefAsmSymbol(FRAME_POINTER_SYM,AT_LABEL))); 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))); list.Concat(taicpu.op_sym(a_set_global,current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_LABEL)));
end; end;
@ -1696,8 +1699,11 @@ implementation
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))); 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_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));

View File

@ -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;