* WebAssembly: refactored tai_local, so that it is a single directive,

containing multiple locals, instead of creating multiple tai_local directives,
  each containing a single local. No functional changes.
This commit is contained in:
Nikolay Nikolov 2024-09-15 00:48:59 +03:00
parent 05b67c7408
commit b9ca30165c
6 changed files with 54 additions and 35 deletions

View File

@ -839,6 +839,23 @@ implementation
end;
writer.AsmLn;
end;
procedure WriteWasmLocalDirective(hp: tai_local);
var
t: TWasmBasicType;
first: boolean=true;
begin
writer.AsmWrite(#9'.local'#9);
for t in tai_local(hp).locals do
begin
if first then
first:=false
else
writer.AsmWrite(', ');
writer.AsmWrite(gas_wasm_basic_type_str[t]);
end;
writer.AsmLn;
end;
{$endif WASM}
var
@ -1638,15 +1655,7 @@ implementation
{$ifdef WASM}
ait_local:
begin
if tai_local(hp).first then
writer.AsmWrite(#9'.local'#9)
else
writer.AsmWrite(', ');
writer.AsmWrite(gas_wasm_basic_type_str[tai_local(hp).bastyp]);
if tai_local(hp).last then
writer.AsmLn;
end;
WriteWasmLocalDirective(tai_local(hp));
ait_globaltype:
begin
writer.AsmWrite(#9'.globaltype'#9);

View File

@ -1206,9 +1206,11 @@ implementation
procedure TWasmObjData.DeclareLocal(al: tai_local);
var
ObjSymExtraData: TWasmObjSymbolExtraData;
t: TWasmBasicType;
begin
ObjSymExtraData:=TWasmObjSymbolExtraData(FObjSymbolsExtraDataList.Find(FLastFuncName));
ObjSymExtraData.AddLocal(al.bastyp);
for t in al.locals do
ObjSymExtraData.AddLocal(t);
end;
procedure TWasmObjData.symbolpairdefine(akind: TSymbolPairKind; const asym, avalue: string);

View File

@ -325,10 +325,10 @@ uses
{ tai_local }
tai_local = class(tai)
bastyp: TWasmBasicType;
first: boolean;
last: boolean;
constructor create(abasictype: TWasmBasicType);
locals: TWasmLocalsDynArray;
constructor create(alocals: TWasmLocalsDynArray);
procedure AddLocal(abasictype: TWasmBasicType);
procedure AddLocals(alocals: TWasmLocalsDynArray);
end;
{ tai_globaltype }
@ -1892,13 +1892,24 @@ uses
{ tai_local }
constructor tai_local.create(abasictype: TWasmBasicType);
constructor tai_local.create(alocals: TWasmLocalsDynArray);
begin
inherited Create;
bastyp := abasictype;
locals := Copy(alocals);
typ := ait_local;
end;
procedure tai_local.AddLocal(abasictype: TWasmBasicType);
begin
SetLength(locals,Length(locals)+1);
locals[high(locals)]:=abasictype;
end;
procedure tai_local.AddLocals(alocals: TWasmLocalsDynArray);
begin
locals:=Concat(locals,alocals);
end;
{ timpexp_ai }
constructor tai_export_name.create(const aextname, aintname: ansistring;

View File

@ -401,6 +401,7 @@ implementation
i,pos : longint;
InlineLevel : longint;
do_line : boolean;
t: TWasmBasicType;
const
WasmBasicTypeStr : array [TWasmBasicType] of string = ('unknown','i32','i64','f32','f64','funcref','externref','v128');
@ -621,10 +622,13 @@ implementation
ait_local :
begin
writer.AsmWrite(#9#9'(local ');
writer.AsmWrite( WasmBasicTypeStr[ tai_local(hp).bastyp ] );
writer.AsmWrite(')');
writer.AsmLn;
for t in tai_local(hp).locals do
begin
writer.AsmWrite(#9#9'(local ');
writer.AsmWrite( WasmBasicTypeStr[ t ] );
writer.AsmWrite(')');
writer.AsmLn;
end;
end;
else

View File

@ -140,6 +140,7 @@ uses
wbt_v128
);
TWasmResultType = array of TWasmBasicType;
TWasmLocalsDynArray = array of TWasmBasicType;
{ TWasmFuncType }

View File

@ -897,12 +897,11 @@ implementation
function prepare_locals: TAsmList;
var
local: tai_local;
first: Boolean;
l : TWasmLocal;
begin
result:=TAsmList.create;
local:=nil;
first:=true;
local:=tai_local.create([]);
result.Concat(local);
l:=ttgwasm(tg).localvars.first;
FFuncType:=findfirst_tai_functype(aktproccode).functype;
FLocals:=Copy(FFuncType.params);
@ -912,30 +911,23 @@ implementation
begin
SetLength(FLocals,Length(FLocals)+1);
FLocals[High(FLocals)]:=l.typ;
local:=tai_local.create(l.typ);
local.first:=first;
first:=false;
result.Concat(local);
local.AddLocal(l.typ);
l:=l.nextseq;
Inc(FFirstFreeLocal);
end;
end;
procedure add_extra_allocated_locals(localslist: TAsmList);
var
t: TWasmBasicType;
begin
for t in FAllocatedLocals do
localslist.Concat(tai_local.create(t));
if tai(localslist.First).typ<>ait_local then
internalerror(2024081501);
tai_local(localslist.First).AddLocals(FAllocatedLocals);
end;
procedure insert_localslist(destlist,localslist: TAsmList);
begin
if assigned(localslist) then
begin
tai_local(localslist.Last).last:=true;
destlist.insertListAfter(findfirst_tai_functype(destlist),localslist);
end;
destlist.insertListAfter(findfirst_tai_functype(destlist),localslist);
end;
procedure check_goto_br_instructions(list: TAsmList; out HasGotoBrInstructions: boolean);