From edabca144788a9651c22e624301346aa95b1d9dc Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Wed, 18 Oct 2023 00:48:45 +0300 Subject: [PATCH] + added and implemented tcpuprocinfo.AllocWasmLocal --- compiler/wasm32/cpupi.pas | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/compiler/wasm32/cpupi.pas b/compiler/wasm32/cpupi.pas index 00245080dc..de023c7e26 100644 --- a/compiler/wasm32/cpupi.pas +++ b/compiler/wasm32/cpupi.pas @@ -27,7 +27,7 @@ interface uses cutils,globtype,aasmdata,aasmcpu,aasmtai, - procinfo,cpuinfo, symtype,aasmbase,cgbase, + procinfo,cpubase,cpuinfo, symtype,aasmbase,cgbase, psub, cclasses; type @@ -36,7 +36,13 @@ interface tcpuprocinfo=class(tcgprocinfo) private + FFirstFreeLocal: Integer; + FAllocatedLocals: array of TWasmBasicType; + function ConvertBranchTargetNumbersToLabels(ai: tai; blockstack: twasmstruc_stack): tai; + + { used for allocating locals during the postprocess_code stage (i.e. after register allocation) } + function AllocWasmLocal(wbt: TWasmBasicType): Integer; public { label to the nearest local exception handler } CurrRaiseLabel : tasmlabel; @@ -52,7 +58,7 @@ interface implementation uses - systems,verbose,globals,cpubase,tgcpu,cgexcept, + systems,verbose,globals,tgcpu,cgexcept, tgobj,paramgr,symconst,symdef,symtable,symcpu,cgutils,pass_2,parabase, fmodule,hlcgobj,hlcgcpu,defutil; @@ -371,6 +377,13 @@ implementation instr.loadsymbol(0,l,0); end; + function tcpuprocinfo.AllocWasmLocal(wbt: TWasmBasicType): Integer; + begin + SetLength(FAllocatedLocals,Length(FAllocatedLocals)+1); + FAllocatedLocals[High(FAllocatedLocals)]:=wbt; + result:=High(FAllocatedLocals)+FFirstFreeLocal; + end; + constructor tcpuprocinfo.create(aparent: tprocinfo); begin inherited create(aparent); @@ -642,11 +655,15 @@ implementation l : TWasmLocal; first, labels_resolved: Boolean; local: tai_local; + first_tai_functype: tai_functype; begin + first_tai_functype:=findfirst_tai_functype(aktproccode); + templist:=TAsmList.create; local:=nil; first:=true; l:=ttgwasm(tg).localvars.first; + FFirstFreeLocal:=Length(first_tai_functype.functype.params); while Assigned(l) do begin local:=tai_local.create(l.typ); @@ -654,10 +671,11 @@ implementation first:=false; templist.Concat(local); l:=l.nextseq; + Inc(FFirstFreeLocal); end; if assigned(local) then local.last:=true; - aktproccode.insertListAfter(findfirst_tai_functype(aktproccode),templist); + aktproccode.insertListAfter(first_tai_functype,templist); templist.Free; replace_local_frame_pointer(aktproccode);