+ added and implemented tcpuprocinfo.AllocWasmLocal

This commit is contained in:
Nikolay Nikolov 2023-10-18 00:48:45 +03:00
parent d911e462b2
commit edabca1447

View File

@ -27,7 +27,7 @@ interface
uses uses
cutils,globtype,aasmdata,aasmcpu,aasmtai, cutils,globtype,aasmdata,aasmcpu,aasmtai,
procinfo,cpuinfo, symtype,aasmbase,cgbase, procinfo,cpubase,cpuinfo, symtype,aasmbase,cgbase,
psub, cclasses; psub, cclasses;
type type
@ -36,7 +36,13 @@ interface
tcpuprocinfo=class(tcgprocinfo) tcpuprocinfo=class(tcgprocinfo)
private private
FFirstFreeLocal: Integer;
FAllocatedLocals: array of TWasmBasicType;
function ConvertBranchTargetNumbersToLabels(ai: tai; blockstack: twasmstruc_stack): tai; 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 public
{ label to the nearest local exception handler } { label to the nearest local exception handler }
CurrRaiseLabel : tasmlabel; CurrRaiseLabel : tasmlabel;
@ -52,7 +58,7 @@ interface
implementation implementation
uses uses
systems,verbose,globals,cpubase,tgcpu,cgexcept, systems,verbose,globals,tgcpu,cgexcept,
tgobj,paramgr,symconst,symdef,symtable,symcpu,cgutils,pass_2,parabase, tgobj,paramgr,symconst,symdef,symtable,symcpu,cgutils,pass_2,parabase,
fmodule,hlcgobj,hlcgcpu,defutil; fmodule,hlcgobj,hlcgcpu,defutil;
@ -371,6 +377,13 @@ implementation
instr.loadsymbol(0,l,0); instr.loadsymbol(0,l,0);
end; 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); constructor tcpuprocinfo.create(aparent: tprocinfo);
begin begin
inherited create(aparent); inherited create(aparent);
@ -642,11 +655,15 @@ implementation
l : TWasmLocal; l : TWasmLocal;
first, labels_resolved: Boolean; first, labels_resolved: Boolean;
local: tai_local; local: tai_local;
first_tai_functype: tai_functype;
begin begin
first_tai_functype:=findfirst_tai_functype(aktproccode);
templist:=TAsmList.create; templist:=TAsmList.create;
local:=nil; local:=nil;
first:=true; first:=true;
l:=ttgwasm(tg).localvars.first; l:=ttgwasm(tg).localvars.first;
FFirstFreeLocal:=Length(first_tai_functype.functype.params);
while Assigned(l) do while Assigned(l) do
begin begin
local:=tai_local.create(l.typ); local:=tai_local.create(l.typ);
@ -654,10 +671,11 @@ implementation
first:=false; first:=false;
templist.Concat(local); templist.Concat(local);
l:=l.nextseq; l:=l.nextseq;
Inc(FFirstFreeLocal);
end; end;
if assigned(local) then if assigned(local) then
local.last:=true; local.last:=true;
aktproccode.insertListAfter(findfirst_tai_functype(aktproccode),templist); aktproccode.insertListAfter(first_tai_functype,templist);
templist.Free; templist.Free;
replace_local_frame_pointer(aktproccode); replace_local_frame_pointer(aktproccode);