Browse Source

[PATCH 159/188] fix parameters search, added global search

From eea2255a62efc0bdc821898766143c6c1fb0fe66 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Fri, 27 Mar 2020 09:33:09 -0400

git-svn-id: branches/wasm@46155 -
nickysn 5 years ago
parent
commit
577bf4177c
1 changed files with 24 additions and 2 deletions
  1. 24 2
      utils/wasmbin/wasmmodule.pas

+ 24 - 2
utils/wasmbin/wasmmodule.pas

@@ -127,7 +127,7 @@ type
 
 
   TWasmFunc = class(TObject)
   TWasmFunc = class(TObject)
   public
   public
-    locals   :  TList;
+    locals   : TList;
     LinkInfo : TLinkInfo;
     LinkInfo : TLinkInfo;
     id       : string;
     id       : string;
     idNum    : Integer;     // reference number (after Normalization)
     idNum    : Integer;     // reference number (after Normalization)
@@ -268,6 +268,7 @@ type
 function WasmBasTypeToChar(b: byte): Char;
 function WasmBasTypeToChar(b: byte): Char;
 function WasmFuncTypeDescr(t: TWasmFuncType): string;
 function WasmFuncTypeDescr(t: TWasmFuncType): string;
 
 
+function FindGlobal(m: TWasmModule; const globIdx: string): integer;
 function FindFunc(m: TWasmModule; const funcIdx: string): integer;
 function FindFunc(m: TWasmModule; const funcIdx: string): integer;
 function FindParam(l: TList; const idx: string): Integer;
 function FindParam(l: TList; const idx: string): Integer;
 
 
@@ -896,7 +897,7 @@ begin
       Result:=i;
       Result:=i;
       Exit;
       Exit;
     end;
     end;
-  Result:=i;
+  Result:=-1;
 end;
 end;
 
 
 // finding functions by funcIdx
 // finding functions by funcIdx
@@ -921,6 +922,27 @@ begin
     end;
     end;
 end;
 end;
 
 
+function FindGlobal(m: TWasmModule; const globIdx: string): integer;
+var
+  i  : integer;
+  im : TWasmImport;
+begin
+  Result:=-1;
+  {for i:=0 to m.ImportCount-1 do begin
+    im:=m.GetImport(i);
+    if Assigned(im.fn) and (im.fn.id = funcIdx) then begin
+      Result:=im.fn.idNum;
+      Exit;
+    end;
+  end;}
+
+  for i:=0 to m.GlobalCount-1 do
+    if m.GetGlobal(i).id.id = globIdx then begin
+      Result:=m.GetGlobal(i).id.idNum;
+      Exit;
+    end;
+end;
+
 // only looking up for the by the type index name
 // only looking up for the by the type index name
 function FindFuncType(m: TWasmModule; const typeIdx: string): integer;
 function FindFuncType(m: TWasmModule; const typeIdx: string): integer;
 var
 var