Browse Source

[PATCH 76/83] counting the exact number of functions needed (based on the number of elements in the table)

From 7074c4e53ee1889edb67b147fcb3bb9b99ea8a0b Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Tue, 29 Oct 2019 10:08:37 -0400

git-svn-id: branches/wasm@45953 -
nickysn 5 years ago
parent
commit
b665ac8a6d
1 changed files with 15 additions and 1 deletions
  1. 15 1
      compiler/wasm/agwat.pas

+ 15 - 1
compiler/wasm/agwat.pas

@@ -831,14 +831,28 @@ implementation
     var
     var
       hp: tai;
       hp: tai;
       x: tai_impexp;
       x: tai_impexp;
+      cnt: integer;
     begin
     begin
       if not Assigned(p) then Exit;
       if not Assigned(p) then Exit;
       hp:=tai(p.First);
       hp:=tai(p.First);
       if not Assigned(hp) then Exit;
       if not Assigned(hp) then Exit;
 
 
+      cnt := 0;
+      while Assigned(hp) do begin
+        case hp.typ of
+          ait_importexport:
+            inc(cnt);
+        end;
+        hp := tai_impexp(hp.Next);
+      end;
+
       // writting out table, so wat2wasm can create reallocation symbols
       // writting out table, so wat2wasm can create reallocation symbols
-      writer.AsmWrite(#9'(table 0 anyfunc)');
+
+      writer.AsmWrite(#9'(table ');
+      writer.AsmWrite(tostr(cnt));
+      writer.AsmWrite(' anyfunc)');
       writer.AsmWriteLn(#9'(elem 0 (i32.const 0) ');
       writer.AsmWriteLn(#9'(elem 0 (i32.const 0) ');
+      hp:=tai(p.First);
       while Assigned(hp) do begin
       while Assigned(hp) do begin
         case hp.typ of
         case hp.typ of
           ait_importexport:
           ait_importexport: