Browse Source

+ allow referencing '$__stack_pointer' in WebAssembly inline asm as argument to
the global.get and global.set instructions. This will be used in the future to
implement the thread start routine in inline asm.

Nikolay Nikolov 1 year ago
parent
commit
0a9169eb67
2 changed files with 16 additions and 2 deletions
  1. 2 1
      compiler/wasm32/hlcgcpu.pas
  2. 14 1
      compiler/wasm32/rawasmtext.pas

+ 2 - 1
compiler/wasm32/hlcgcpu.pas

@@ -55,13 +55,14 @@ uses
                               (check d.size to determine which one of the two)
         }
       function is_methodptr_like_type(d:tdef): boolean;
-      function RefStackPointerSym: TWasmGlobalAsmSymbol;
      public
       fntypelookup : TWasmProcTypeLookup;
 
       constructor create;
       destructor Destroy; override;
 
+      function RefStackPointerSym: TWasmGlobalAsmSymbol;
+
       procedure incstack(list : TAsmList;slots: longint);
       procedure decstack(list : TAsmList;slots: longint);
 

+ 14 - 1
compiler/wasm32/rawasmtext.pas

@@ -87,6 +87,7 @@ Unit rawasmtext;
       procinfo,
       rabase,rautils,
       cgbase,cgutils,cgobj,
+      hlcgobj,hlcgcpu,
       { wasm }
       itcpuwasm
       ;
@@ -894,7 +895,19 @@ Unit rawasmtext;
                         result.operands[1].opr.val:=actinttoken;
                         Consume(AS_INTNUM);
                       end;
-                    {TODO:AS_ID}
+                    AS_ID:
+                      begin
+                        case actasmpattern of
+                          '$'+STACK_POINTER_SYM:
+                            begin
+                              result.ops:=1;
+                              result.operands[1].opr.typ:=OPR_SYMBOL;
+                              result.operands[1].opr.symbol:=thlcgwasm(hlcg).RefStackPointerSym;
+                            end;
+                          else
+                            internalerror(2024072002);
+                        end;
+                      end;
                     else
                       begin
                         { error: expected integer }