Browse Source

[PATCH 184/188] update writing binary import section for entities
other than function update table normalization to hard-code the element type

From 545def919260e7d90ec3b948f242022378607079 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Thu, 9 Apr 2020 14:08:42 -0400

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

nickysn 5 years ago
parent
commit
addfbaf889
2 changed files with 15 additions and 0 deletions
  1. 13 0
      utils/wasmbin/wasmbinwriter.pas
  2. 2 0
      utils/wasmbin/wasmnormalize.pas

+ 13 - 0
utils/wasmbin/wasmbinwriter.pas

@@ -692,6 +692,8 @@ var
   sc : TSectionRec;
   sc : TSectionRec;
   i  : integer;
   i  : integer;
   im : TWasmImport;
   im : TWasmImport;
+const
+  isMutableFlag : array [boolean] of byte = (global_const, global_mut);
 begin
 begin
   SectionBegin(SECT_IMPORT, sc);
   SectionBegin(SECT_IMPORT, sc);
 
 
@@ -704,6 +706,17 @@ begin
     if Assigned(im.fn) then begin
     if Assigned(im.fn) then begin
       dst.WriteByte(IMPDESC_FUNC);
       dst.WriteByte(IMPDESC_FUNC);
       WriteU32(dst, im.fn.functype.typeNum);
       WriteU32(dst, im.fn.functype.typeNum);
+    end else if Assigned(im.mem) then begin
+      dst.WriteByte(IMPDESC_MEM);
+      WriteLimit(dst, im.mem.min, im.mem.max)
+    end else if Assigned(im.table) then begin
+      dst.WriteByte(IMPDESC_TABLE);
+      dst.WriteByte(im.table.elemsType);
+      WriteLimit(dst, im.table.min, im.table.max);
+    end else if Assigned(im.glob) then begin
+      dst.WriteByte(IMPDESC_GLOBAL);
+      dst.WriteByte(im.glob.tp);
+      dst.WriteByte(isMutableFlag[im.glob.isMutable]);
     end;
     end;
   end;
   end;
   SectionEnd(sc);
   SectionEnd(sc);

+ 2 - 0
utils/wasmbin/wasmnormalize.pas

@@ -222,6 +222,8 @@ begin
     de := m.AddElement;
     de := m.AddElement;
     de.tableId.idNum := t.id.idNum;
     de.tableId.idNum := t.id.idNum;
 
 
+    if t.elemsType = 0 then t.elemsType := ELEMTYPE_FUNC;
+
     de.funcCount:=se.funcCount;
     de.funcCount:=se.funcCount;
     if se.funcCount>0 then begin
     if se.funcCount>0 then begin
       SetLength(de.funcs, de.funcCount);
       SetLength(de.funcs, de.funcCount);