Browse Source

[PATCH 076/188] update in parsing import and instruction set

From 84dfd866b7147bb26ecb582c2fd7375b88726b06 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Fri, 6 Mar 2020 16:09:21 -0500

git-svn-id: branches/wasm@46072 -
nickysn 5 years ago
parent
commit
e0cd939302
1 changed files with 41 additions and 3 deletions
  1. 41 3
      utils/wasmbin/watparser.pas

+ 41 - 3
utils/wasmbin/watparser.pas

@@ -201,8 +201,8 @@ var
   ci  : TWasmInstr;
   ci  : TWasmInstr;
 begin
 begin
   while sc.token=weInstr do begin
   while sc.token=weInstr do begin
-    sc.Next;
     ci := dst.AddInstr(sc.instrCode);
     ci := dst.AddInstr(sc.instrCode);
+    sc.Next;
     case INST_FLAGS[ci.code].Param of
     case INST_FLAGS[ci.code].Param of
       ipNone:; // do nothing
       ipNone:; // do nothing
 
 
@@ -214,6 +214,7 @@ begin
         if sc.token<>weNumber then
         if sc.token<>weNumber then
           ErrorExpectButFound(sc, 'number');
           ErrorExpectButFound(sc, 'number');
         ci.operandText := sc.resText;
         ci.operandText := sc.resText;
+        sc.Next;
       end;
       end;
 
 
       //ip2Leb,  // memory arguments, ask for offset + align
       //ip2Leb,  // memory arguments, ask for offset + align
@@ -311,6 +312,36 @@ begin
   ConsumeToken(sc, weCloseBrace);
   ConsumeToken(sc, weCloseBrace);
 end;
 end;
 
 
+
+procedure ParseImport(sc: TWatScanner; dst: TWasmImport);
+var
+  tk      : TWatToken;
+begin
+  if sc.token=weImport then
+    sc.Next;
+
+  if sc.token<>weString then
+    ErrorExpectButFound(sc, 'string');
+  dst.module := sc.resWasmString;
+  sc.Next;
+
+  if sc.token<>weString then
+    ErrorExpectButFound(sc, 'string');
+  dst.name := sc.resWasmString;
+  sc.Next;
+
+  ConsumeAnyOpenToken(sc, tk);
+  case tk of
+    weAsmSymbol: ;
+    weFunc: begin
+      ParseFunc(sc, dst.AddFunc);
+    end;
+  else
+    ErrorExpectButFound(sc, 'importdesc', TokenStr[sc.token]);
+  end;
+  ConsumeToken(sc, weCloseBrace);
+end;
+
 procedure ConsumeAsmSym(sc: TWatScanner; dst: TAsmSymList);
 procedure ConsumeAsmSym(sc: TWatScanner; dst: TAsmSymList);
 begin
 begin
   dst.Push(sc.asmCmd, sc.resText);
   dst.Push(sc.asmCmd, sc.resText);
@@ -319,9 +350,10 @@ end;
 
 
 procedure ParseModuleInt(sc: TWatScanner; dst: TWasmModule);
 procedure ParseModuleInt(sc: TWatScanner; dst: TWasmModule);
 var
 var
-  tk : TWatToken;
+  tk      : TWatToken;
   symlist : TAsmSymList;
   symlist : TAsmSymList;
-  f : TWasmFunc;
+  f       : TWasmFunc;
+  imp     : TWasmImport;
 begin
 begin
   if not ConsumeOpenToken(sc, weModule) then
   if not ConsumeOpenToken(sc, weModule) then
     ErrorExpectButFound(sc, 'module');
     ErrorExpectButFound(sc, 'module');
@@ -334,6 +366,12 @@ begin
       case tk of
       case tk of
         weAsmSymbol:
         weAsmSymbol:
           ConsumeAsmSym(sc, symlist);
           ConsumeAsmSym(sc, symlist);
+        weImport: begin
+          imp:=dst.AddImport;
+          symlist.ToLinkInfo(imp.LinkInfo);
+          ParseImport(sc, imp);
+          symlist.Clear;
+        end;
         weFunc: begin
         weFunc: begin
           f:=dst.AddFunc;
           f:=dst.AddFunc;
           symlist.ToLinkInfo(f.LinkInfo);
           symlist.ToLinkInfo(f.LinkInfo);