Browse Source

[PATCH 153/188] update normalizing elements

From 2e32be10ce985ebd1d3f5eb9fcc4cb4ee34077f6 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Thu, 26 Mar 2020 16:50:48 -0400

git-svn-id: branches/wasm@46149 -
nickysn 5 years ago
parent
commit
be37f0577e
2 changed files with 10 additions and 1 deletions
  1. 8 0
      utils/wasmbin/wasmnormalize.pas
  2. 2 1
      utils/wasmbin/wattest.lpr

+ 8 - 0
utils/wasmbin/wasmnormalize.pas

@@ -196,8 +196,15 @@ end;
 procedure NormalizeElems(m: TWasmModule);
 var
   i : integer;
+  e : TWasmElement;
+  l : TWasmInstrList;
 begin
+  //todo: resolve offsets
   for i:=0 to m.ElementCount-1 do begin
+    e := m.GetElement(i);
+    l := e.AddOffset;
+    if (l.Count=0) then l.AddInstr(INST_i32_const).operandText:='0';
+    NormalizeInst( m, nil, l);
   end;
 end;
 
@@ -211,6 +218,7 @@ var
 begin
   fnIdx := 0;
   NormalizeTable(m);
+  NormalizeElems(m);
   NormalizeImport(m, fnIdx);
 
   for i:=0 to m.FuncCount-1 do begin

+ 2 - 1
utils/wasmbin/wattest.lpr

@@ -3,7 +3,8 @@ program wattest;
 {$mode objfpc}{$H+}
 
 uses
-  SysUtils, Classes, watparser, watscanner, wasmmodule, wasmbinwriter;
+  SysUtils, Classes, watparser, watscanner, wasmmodule, wasmbinwriter,
+  wasmnormalize;
 
 procedure Traverse(p: TWatScanner);
 begin