Browse Source

[PATCH 154/188] normalizing table limit, if set to zero, making
minmax to element

From b13b522b323f3a996b3548a7e15eb0c432a844a7 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Thu, 26 Mar 2020 16:59:02 -0400

git-svn-id: branches/wasm@46150 -

nickysn 5 years ago
parent
commit
e4674b03b4
1 changed files with 21 additions and 0 deletions
  1. 21 0
      utils/wasmbin/wasmnormalize.pas

+ 21 - 0
utils/wasmbin/wasmnormalize.pas

@@ -193,6 +193,26 @@ begin
   end;
   end;
 end;
 end;
 
 
+procedure NormalizeTableLimit(m: TWasmModule);
+var
+  i       : integer;
+  elCount : integer;
+  t       : TWasmTable;
+begin
+  elCount:=0;
+  for i:=0 to m.ElementCount-1 do
+    inc(elCount, m.GetElement(i).funcCount );
+
+  for i:=0 to m.TableCount-1 do begin
+    t := m.GetTable(i);
+    if (t.min=0) and (t.max=0) then begin
+      t.min := elCount;
+      t.max := elCount;
+      Break;
+    end;
+  end;
+end;
+
 procedure NormalizeElems(m: TWasmModule);
 procedure NormalizeElems(m: TWasmModule);
 var
 var
   i : integer;
   i : integer;
@@ -220,6 +240,7 @@ begin
   NormalizeTable(m);
   NormalizeTable(m);
   NormalizeElems(m);
   NormalizeElems(m);
   NormalizeImport(m, fnIdx);
   NormalizeImport(m, fnIdx);
+  NormalizeTableLimit(m);
 
 
   for i:=0 to m.FuncCount-1 do begin
   for i:=0 to m.FuncCount-1 do begin
     f:=m.GetFunc(i);
     f:=m.GetFunc(i);