Browse Source

+ introduced TWasmGlobalAsmSymbol subclass of TAsmSymbol. Use it for all
AT_WASM_GLOBAL symbols. This allows in the future to add extra data to the
TWasmGlobalAsmSymbol, such as the WebAssembly global type, which will aid in
WebAssembly validation and stack tracking.

Nikolay Nikolov 1 year ago
parent
commit
f4b9d51aff
3 changed files with 12 additions and 7 deletions
  1. 8 3
      compiler/wasm32/aasmcpu.pas
  2. 3 3
      compiler/wasm32/hlcgcpu.pas
  3. 1 1
      compiler/wasm32/nwasminl.pas

+ 8 - 3
compiler/wasm32/aasmcpu.pas

@@ -43,6 +43,11 @@ uses
     type
     type
       TWasmBasicTypeList = array of TWasmBasicType;
       TWasmBasicTypeList = array of TWasmBasicType;
 
 
+      { TWasmGlobalAsmSymbol }
+
+      TWasmGlobalAsmSymbol = class(TAsmSymbol)
+      end;
+
       { TWasmValueStack }
       { TWasmValueStack }
 
 
       TWasmValueStack = class
       TWasmValueStack = class
@@ -1652,7 +1657,7 @@ uses
     constructor tai_globaltype.create(const aglobalname: string; atype: TWasmBasicType; aimmutable: boolean);
     constructor tai_globaltype.create(const aglobalname: string; atype: TWasmBasicType; aimmutable: boolean);
       begin
       begin
         inherited Create;
         inherited Create;
-        sym:=current_asmdata.RefAsmSymbol(aglobalname,AT_WASM_GLOBAL);
+        sym:=current_asmdata.RefAsmSymbolByClass(TWasmGlobalAsmSymbol,aglobalname,AT_WASM_GLOBAL);
         typ:=ait_globaltype;
         typ:=ait_globaltype;
         globalname:=aglobalname;
         globalname:=aglobalname;
         gtype:=atype;
         gtype:=atype;
@@ -1664,7 +1669,7 @@ uses
     constructor tai_globaltype.create_local(const aglobalname: string; atype: TWasmBasicType; aimmutable: boolean; def: tdef);
     constructor tai_globaltype.create_local(const aglobalname: string; atype: TWasmBasicType; aimmutable: boolean; def: tdef);
       begin
       begin
         inherited Create;
         inherited Create;
-        sym:=current_asmdata.DefineAsmSymbol(aglobalname,AB_LOCAL,AT_WASM_GLOBAL,def);
+        sym:=current_asmdata.DefineAsmSymbolByClass(TWasmGlobalAsmSymbol,aglobalname,AB_LOCAL,AT_WASM_GLOBAL,def);
         typ:=ait_globaltype;
         typ:=ait_globaltype;
         globalname:=aglobalname;
         globalname:=aglobalname;
         gtype:=atype;
         gtype:=atype;
@@ -1676,7 +1681,7 @@ uses
     constructor tai_globaltype.create_global(const aglobalname: string; atype: TWasmBasicType; aimmutable: boolean; def: tdef);
     constructor tai_globaltype.create_global(const aglobalname: string; atype: TWasmBasicType; aimmutable: boolean; def: tdef);
       begin
       begin
         inherited Create;
         inherited Create;
-        sym:=current_asmdata.DefineAsmSymbol(aglobalname,AB_GLOBAL,AT_WASM_GLOBAL,def);
+        sym:=current_asmdata.DefineAsmSymbolByClass(TWasmGlobalAsmSymbol,aglobalname,AB_GLOBAL,AT_WASM_GLOBAL,def);
         typ:=ait_globaltype;
         typ:=ait_globaltype;
         globalname:=aglobalname;
         globalname:=aglobalname;
         gtype:=atype;
         gtype:=atype;

+ 3 - 3
compiler/wasm32/hlcgcpu.pas

@@ -2049,7 +2049,7 @@ implementation
 
 
       g_fingerprint(list);
       g_fingerprint(list);
 
 
-      list.Concat(taicpu.op_sym(a_global_get,current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_WASM_GLOBAL)));
+      list.Concat(taicpu.op_sym(a_global_get,current_asmdata.RefAsmSymbolByClass(TWasmGlobalAsmSymbol,STACK_POINTER_SYM,AT_WASM_GLOBAL)));
       incstack(list,1);
       incstack(list,1);
       list.Concat(taicpu.op_ref(a_local_set,pd.base_pointer_ref));
       list.Concat(taicpu.op_ref(a_local_set,pd.base_pointer_ref));
       decstack(list,1);
       decstack(list,1);
@@ -2065,7 +2065,7 @@ implementation
         decstack(list,1);
         decstack(list,1);
         list.Concat(taicpu.op_ref(a_local_get,pd.frame_pointer_ref));
         list.Concat(taicpu.op_ref(a_local_get,pd.frame_pointer_ref));
         incstack(list,1);
         incstack(list,1);
-        list.Concat(taicpu.op_sym(a_global_set,current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_WASM_GLOBAL)));
+        list.Concat(taicpu.op_sym(a_global_set,current_asmdata.RefAsmSymbolByClass(TWasmGlobalAsmSymbol,STACK_POINTER_SYM,AT_WASM_GLOBAL)));
         decstack(list,1);
         decstack(list,1);
       end;
       end;
     end;
     end;
@@ -2077,7 +2077,7 @@ implementation
       pd:=tcpuprocdef(current_procinfo.procdef);
       pd:=tcpuprocdef(current_procinfo.procdef);
       list.Concat(taicpu.op_ref(a_local_get,pd.base_pointer_ref));
       list.Concat(taicpu.op_ref(a_local_get,pd.base_pointer_ref));
       incstack(list,1);
       incstack(list,1);
-      list.Concat(taicpu.op_sym(a_global_set,current_asmdata.RefAsmSymbol(STACK_POINTER_SYM,AT_WASM_GLOBAL)));
+      list.Concat(taicpu.op_sym(a_global_set,current_asmdata.RefAsmSymbolByClass(TWasmGlobalAsmSymbol,STACK_POINTER_SYM,AT_WASM_GLOBAL)));
       decstack(list,1);
       decstack(list,1);
 
 
       list.concat(taicpu.op_none(a_return));
       list.concat(taicpu.op_none(a_return));

+ 1 - 1
compiler/wasm32/nwasminl.pas

@@ -544,7 +544,7 @@ implementation
 
 
     procedure twasminlinenode.second_tls_get(const SymStr: string);
     procedure twasminlinenode.second_tls_get(const SymStr: string);
       begin
       begin
-        current_asmdata.CurrAsmList.Concat(taicpu.op_sym(a_global_get,current_asmdata.RefAsmSymbol(SymStr,AT_WASM_GLOBAL)));
+        current_asmdata.CurrAsmList.Concat(taicpu.op_sym(a_global_get,current_asmdata.RefAsmSymbolByClass(TWasmGlobalAsmSymbol,SymStr,AT_WASM_GLOBAL)));
         thlcgwasm(hlcg).incstack(current_asmdata.CurrAsmList,1);
         thlcgwasm(hlcg).incstack(current_asmdata.CurrAsmList,1);
 
 
         location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
         location_reset(location,LOC_REGISTER,def_cgsize(resultdef));