Browse Source

* WebAssembly high level code generator: use the global.get and global.set
instructions to access references to symbols of type AT_WASM_GLOBAL

Nikolay Nikolov 3 years ago
parent
commit
f32ef29253
1 changed files with 19 additions and 3 deletions
  1. 19 3
      compiler/wasm32/hlcgcpu.pas

+ 19 - 3
compiler/wasm32/hlcgcpu.pas

@@ -1054,8 +1054,16 @@ implementation
           ref.index:=NR_NO;
           ref.index:=NR_NO;
         end;
         end;
 
 
-      // setting up memory offset
-      if ref.refaddr=addr_got_tls then
+      if assigned(ref.symbol) and (ref.symbol.typ=AT_WASM_GLOBAL) then
+        begin
+          if ref.base<>NR_NO then
+            internalerror(2022072601);
+          if ref.index<>NR_NO then
+            internalerror(2022072602);
+          if ref.offset<>0 then
+            internalerror(2022072603);
+        end
+      else if ref.refaddr=addr_got_tls then
         begin
         begin
           if not assigned(ref.symbol) then
           if not assigned(ref.symbol) then
             internalerror(2022071405);
             internalerror(2022071405);
@@ -2395,7 +2403,15 @@ implementation
       getputmemf32 : array [boolean] of TAsmOp = (a_f32_store, a_f32_load);
       getputmemf32 : array [boolean] of TAsmOp = (a_f32_store, a_f32_load);
       getputmemf64 : array [boolean] of TAsmOp = (a_f64_store, a_f64_load);
       getputmemf64 : array [boolean] of TAsmOp = (a_f64_store, a_f64_load);
     begin
     begin
-      if (ref.base<>NR_LOCAL_STACK_POINTER_REG) or assigned(ref.symbol) then
+      if assigned(ref.symbol) and (ref.symbol.typ=AT_WASM_GLOBAL) then
+        begin
+          if isload then
+            result:=a_global_get
+          else
+            result:=a_global_set;
+          finishandval:=-1;
+        end
+      else if (ref.base<>NR_LOCAL_STACK_POINTER_REG) or assigned(ref.symbol) then
         begin
         begin
           { -> either a global (static) field, or a regular field. If a regular
           { -> either a global (static) field, or a regular field. If a regular
             field, then ref.base contains the self pointer, otherwise
             field, then ref.base contains the self pointer, otherwise