Browse Source

[PATCH 142/188] adding mutable flag for global variables

From fdd0998697323727e0fbd4af6322eb305f1a8960 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Wed, 25 Mar 2020 11:24:36 -0400

git-svn-id: branches/wasm@46138 -
nickysn 5 years ago
parent
commit
39c720778f
2 changed files with 18 additions and 7 deletions
  1. 4 3
      utils/wasmbin/wasmmodule.pas
  2. 14 4
      utils/wasmbin/watparser.pas

+ 4 - 3
utils/wasmbin/wasmmodule.pas

@@ -114,9 +114,10 @@ type
 
   TWasmGlobal = class(TObject)
   public
-    id    : TWasmId;
-    tp    : byte; // byte;
-    value : TWasmInstrList;
+    id         : TWasmId;
+    tp         : byte;    // byte;
+    isMutable  : Boolean; // is mutable
+    value      : TWasmInstrList;
     LinkInfo   : TLinkInfo;
     ExportInfo : TExportInfo;
     function StartValue: TWasmInstrList;

+ 14 - 4
utils/wasmbin/watparser.pas

@@ -429,15 +429,25 @@ begin
       allowValue := false;
     end else if sc.token=weExport then begin
      // export
-    end else
-      ErrorExpectButFound(sc, 'import or export')
+    end;
   end;
 
-  if sc.token in WasmTypeTokens then begin
-    TokenTypeToValType(sc.token, dst.tp);
+  // parsing type. Global can be mutable type (mut i32)
+
+  if (sc.token=weOpenBrace) then sc.Next;
+  if sc.token = weMut then begin
+    dst.isMutable := true;
     sc.Next;
   end;
 
+  if (sc.token in WasmTypeTokens) then begin
+    TokenTypeToValType(sc.token, dst.tp);
+    sc.Next;
+  end else
+    ErrorExpectButFound(sc, 'type');
+
+  if dst.isMutable then ConsumeToken(sc, weCloseBrace);
+
   if allowValue and (sc.token = weOpenBrace) then begin
     sc.Next;
     ParseInstrList(sc, dst.StartValue);