[PATCH 151/188] normalization of the table

From 67da2939ec2069adc780d0e59574e82b5db6d94c Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <skalogryz.lists@gmail.com>
Date: Thu, 26 Mar 2020 10:58:54 -0400

git-svn-id: branches/wasm@46147 -
This commit is contained in:
nickysn 2020-08-03 13:01:43 +00:00
parent 7e64176086
commit d972e6da92

View File

@ -950,6 +950,19 @@ begin
end; end;
end; end;
// searching back in the labels stack.
// returning the "number" of steps to jump back to the label
function GetJumpLabelIndex(const JumpToLbl: string; LblStack: TStrings): Integer;
var
i : integer;
begin
i:=LblStack.Count-1;
while (i>=0) and (LblStack[i]<>JumpToLbl) do
dec(i);
Result := LblStack.Count-i-1;
end;
// Normalizing instruction list, popuplating index reference ($index) // Normalizing instruction list, popuplating index reference ($index)
// with the actual numbers. (params, locals, globals, memory, functions index) // with the actual numbers. (params, locals, globals, memory, functions index)
// //
@ -961,7 +974,6 @@ var
ci : TWasmInstr; ci : TWasmInstr;
endNeed : Integer; endNeed : Integer;
lbl : TStringList; lbl : TStringList;
li : Integer;
const const
ValidResTypes = [VALTYPE_NONE,VALTYPE_I32,VALTYPE_I64,VALTYPE_F32,VALTYPE_F64]; ValidResTypes = [VALTYPE_NONE,VALTYPE_I32,VALTYPE_I64,VALTYPE_F32,VALTYPE_F64];
begin begin
@ -1011,13 +1023,15 @@ begin
ci.insttype.typeNum:=RegisterFuncType(m, ci.insttype); ci.insttype.typeNum:=RegisterFuncType(m, ci.insttype);
end; end;
INST_br, INST_br_if: begin INST_br, INST_br_if, INST_br_table: begin
if ci.operandIdx<>'' then begin
li:=lbl.Count-1; if ci.code = INST_br_table then
while (li>=0) and (lbl[li]<>ci.operandIdx) do for j:=0 to ci.vecTableCount-1 do
dec(li); if ci.vecTable[j].id <> '' then
ci.operandNum:=(lbl.Count-1)-li; ci.vecTable[j].idNum:=GetJumpLabelIndex(ci.vecTable[j].id, lbl);
end;
if ci.operandIdx<>'' then
ci.operandNum:=GetJumpLabelIndex(ci.operandIdx, lbl);
end; end;
INST_END: begin INST_END: begin