mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 16:49:20 +02:00
+ also support immutable wasm globals in the wasm assembler writer (both internal and external)
This commit is contained in:
parent
7b31549119
commit
b46c010f82
@ -1640,7 +1640,10 @@ implementation
|
|||||||
writer.AsmWrite(#9'.globaltype'#9);
|
writer.AsmWrite(#9'.globaltype'#9);
|
||||||
writer.AsmWrite(tai_globaltype(hp).globalname);
|
writer.AsmWrite(tai_globaltype(hp).globalname);
|
||||||
writer.AsmWrite(', ');
|
writer.AsmWrite(', ');
|
||||||
writer.AsmWriteLn(gas_wasm_basic_type_str[tai_globaltype(hp).gtype]);
|
writer.AsmWrite(gas_wasm_basic_type_str[tai_globaltype(hp).gtype]);
|
||||||
|
if tai_globaltype(hp).immutable then
|
||||||
|
writer.AsmWrite(', immutable');
|
||||||
|
writer.AsmLn;
|
||||||
end;
|
end;
|
||||||
ait_functype:
|
ait_functype:
|
||||||
WriteFuncTypeDirective(tai_functype(hp));
|
WriteFuncTypeDirective(tai_functype(hp));
|
||||||
|
@ -70,6 +70,7 @@ interface
|
|||||||
ImportName: string;
|
ImportName: string;
|
||||||
ExportName: string;
|
ExportName: string;
|
||||||
GlobalType: TWasmBasicType;
|
GlobalType: TWasmBasicType;
|
||||||
|
GlobalIsImmutable: Boolean;
|
||||||
Locals: array of TWasmBasicType;
|
Locals: array of TWasmBasicType;
|
||||||
constructor Create(HashObjectList: TFPHashObjectList; const s: TSymStr);
|
constructor Create(HashObjectList: TFPHashObjectList; const s: TSymStr);
|
||||||
procedure AddLocal(bastyp: TWasmBasicType);
|
procedure AddLocal(bastyp: TWasmBasicType);
|
||||||
@ -660,6 +661,7 @@ implementation
|
|||||||
begin
|
begin
|
||||||
ObjSymExtraData:=AddOrCreateObjSymbolExtraData(gt.globalname);
|
ObjSymExtraData:=AddOrCreateObjSymbolExtraData(gt.globalname);
|
||||||
ObjSymExtraData.GlobalType:=gt.gtype;
|
ObjSymExtraData.GlobalType:=gt.gtype;
|
||||||
|
ObjSymExtraData.GlobalIsImmutable:=gt.immutable;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TWasmObjData.DeclareFuncType(ft: tai_functype);
|
procedure TWasmObjData.DeclareFuncType(ft: tai_functype);
|
||||||
@ -1259,7 +1261,10 @@ implementation
|
|||||||
WriteName(FWasmSections[wsiImport],objsym.Name);
|
WriteName(FWasmSections[wsiImport],objsym.Name);
|
||||||
WriteByte(FWasmSections[wsiImport],$03); { global }
|
WriteByte(FWasmSections[wsiImport],$03); { global }
|
||||||
WriteWasmBasicType(FWasmSections[wsiImport],objsym.ExtraData.GlobalType);
|
WriteWasmBasicType(FWasmSections[wsiImport],objsym.ExtraData.GlobalType);
|
||||||
WriteByte(FWasmSections[wsiImport],$01); { var }
|
if objsym.ExtraData.GlobalIsImmutable then
|
||||||
|
WriteByte(FWasmSections[wsiImport],$00) { const }
|
||||||
|
else
|
||||||
|
WriteByte(FWasmSections[wsiImport],$01); { var }
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{ import functions }
|
{ import functions }
|
||||||
@ -1314,7 +1319,10 @@ implementation
|
|||||||
Inc(NextGlobalIndex);
|
Inc(NextGlobalIndex);
|
||||||
objsym.ExtraData:=TWasmObjSymbolExtraData(FData.FObjSymbolsExtraDataList.Find(objsym.Name));
|
objsym.ExtraData:=TWasmObjSymbolExtraData(FData.FObjSymbolsExtraDataList.Find(objsym.Name));
|
||||||
WriteWasmBasicType(FWasmSections[wsiGlobal],objsym.ExtraData.GlobalType);
|
WriteWasmBasicType(FWasmSections[wsiGlobal],objsym.ExtraData.GlobalType);
|
||||||
WriteByte(FWasmSections[wsiGlobal],$01); { 0=const, 1=var }
|
if objsym.ExtraData.GlobalIsImmutable then
|
||||||
|
WriteByte(FWasmSections[wsiGlobal],$00) { const }
|
||||||
|
else
|
||||||
|
WriteByte(FWasmSections[wsiGlobal],$01); { var }
|
||||||
{ init expr }
|
{ init expr }
|
||||||
case objsym.ExtraData.GlobalType of
|
case objsym.ExtraData.GlobalType of
|
||||||
wbt_i32:
|
wbt_i32:
|
||||||
|
@ -109,7 +109,8 @@ uses
|
|||||||
tai_globaltype = class(tai)
|
tai_globaltype = class(tai)
|
||||||
globalname: string;
|
globalname: string;
|
||||||
gtype: TWasmBasicType;
|
gtype: TWasmBasicType;
|
||||||
constructor create(const aglobalname:string; atype: TWasmBasicType);
|
immutable: boolean;
|
||||||
|
constructor create(const aglobalname:string; atype: TWasmBasicType; aimmutable: boolean);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ tai_functype }
|
{ tai_functype }
|
||||||
@ -158,12 +159,13 @@ uses
|
|||||||
|
|
||||||
{ tai_globaltype }
|
{ tai_globaltype }
|
||||||
|
|
||||||
constructor tai_globaltype.create(const aglobalname: string; atype: TWasmBasicType);
|
constructor tai_globaltype.create(const aglobalname: string; atype: TWasmBasicType; aimmutable: boolean);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
typ:=ait_globaltype;
|
typ:=ait_globaltype;
|
||||||
globalname:=aglobalname;
|
globalname:=aglobalname;
|
||||||
gtype:=atype;
|
gtype:=atype;
|
||||||
|
immutable:=aimmutable;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ tai_import_name }
|
{ tai_import_name }
|
||||||
|
@ -69,7 +69,7 @@ implementation
|
|||||||
|
|
||||||
list:=current_asmdata.asmlists[al_start];
|
list:=current_asmdata.asmlists[al_start];
|
||||||
|
|
||||||
list.Concat(tai_globaltype.create(STACK_POINTER_SYM,wbt_i32));
|
list.Concat(tai_globaltype.create(STACK_POINTER_SYM,wbt_i32,false));
|
||||||
|
|
||||||
if ts_wasm_native_exceptions in current_settings.targetswitches then
|
if ts_wasm_native_exceptions in current_settings.targetswitches then
|
||||||
list.Concat(tai_tagtype.create('__FPC_exception', []));
|
list.Concat(tai_tagtype.create('__FPC_exception', []));
|
||||||
|
Loading…
Reference in New Issue
Block a user