* convert loop..end_loop blocks to flat list + branch instruction

This commit is contained in:
Nikolay Nikolov 2023-10-18 03:45:02 +03:00
parent 9584348c40
commit ce742b5b4d
2 changed files with 21 additions and 0 deletions

View File

@ -135,6 +135,7 @@ uses
destructor Destroy; override;
function getcopy:TLinkedListItem;override;
procedure Map(f: TAsmMapFunc; blockstack: twasmstruc_stack);override;
procedure ConvertToBr(list: TAsmList);
procedure ConvertToFlatList(l: TAsmList);override;
end;
@ -659,6 +660,13 @@ uses
blockstack.pop;
end;
procedure tai_wasmstruc_loop.ConvertToBr(list: TAsmList);
begin
list.concat(tai_label.create(GetLabel));
list.concatList(inner_asmlist);
list.concat(taicpu.op_sym(a_br,GetLabel));
end;
procedure tai_wasmstruc_loop.ConvertToFlatList(l: TAsmList);
begin
l.Concat(loop_instr);

View File

@ -41,6 +41,7 @@ interface
function ConvertBranchTargetNumbersToLabels(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
function ConvertIfToBrIf(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
function ConvertLoopToBr(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
{ used for allocating locals during the postprocess_code stage (i.e. after register allocation) }
function AllocWasmLocal(wbt: TWasmBasicType): Integer;
@ -389,6 +390,17 @@ implementation
end;
end;
function tcpuprocinfo.ConvertLoopToBr(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
begin
result.typ:=amfrtNoChange;
if (ai.typ=ait_wasm_structured_instruction) and (ai is tai_wasmstruc_loop) then
begin
result.typ:=amfrtNewList;
result.newlist:=TAsmList.Create;
tai_wasmstruc_loop(ai).ConvertToBr(result.newlist);
end;
end;
function tcpuprocinfo.AllocWasmLocal(wbt: TWasmBasicType): Integer;
begin
SetLength(FAllocatedLocals,Length(FAllocatedLocals)+1);
@ -656,6 +668,7 @@ implementation
map_structured_asmlist(asmlist,@ConvertBranchTargetNumbersToLabels);
map_structured_asmlist(asmlist,@ConvertIfToBrIf);
map_structured_asmlist(asmlist,@ConvertLoopToBr);
l2:=TAsmList.Create;
wasm_convert_to_flat_asmlist(asmlist,l2);