mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 02:49:21 +02:00
+ WebAssembly internal linker: write the global section in the linker map file
This commit is contained in:
parent
5a07867d20
commit
c005544f3d
@ -5015,7 +5015,10 @@ implementation
|
|||||||
exesec: TExeSection;
|
exesec: TExeSection;
|
||||||
globals_count, i: Integer;
|
globals_count, i: Integer;
|
||||||
objsec: TWasmObjSection;
|
objsec: TWasmObjSection;
|
||||||
|
mapstr: string;
|
||||||
begin
|
begin
|
||||||
|
if assigned(exemap) then
|
||||||
|
exemap.AddHeader('Global section');
|
||||||
exesec:=FindExeSection('.wasm_globals');
|
exesec:=FindExeSection('.wasm_globals');
|
||||||
if not assigned(exesec) then
|
if not assigned(exesec) then
|
||||||
internalerror(2024010112);
|
internalerror(2024010112);
|
||||||
@ -5031,6 +5034,8 @@ implementation
|
|||||||
WriteByte(FWasmSections[wsiGlobal],1)
|
WriteByte(FWasmSections[wsiGlobal],1)
|
||||||
else
|
else
|
||||||
WriteByte(FWasmSections[wsiGlobal],0);
|
WriteByte(FWasmSections[wsiGlobal],0);
|
||||||
|
if assigned(exemap) then
|
||||||
|
WriteStr(mapstr,' Global[',i,'] ',wasm_basic_type_str[objsec.MainFuncSymbol.LinkingData.GlobalType],' mutable=',objsec.MainFuncSymbol.LinkingData.GlobalIsMutable,' <',objsec.MainFuncSymbol.Name,'> - init ');
|
||||||
{ initializer expr }
|
{ initializer expr }
|
||||||
with objsec.MainFuncSymbol.LinkingData.GlobalInitializer do
|
with objsec.MainFuncSymbol.LinkingData.GlobalInitializer do
|
||||||
case typ of
|
case typ of
|
||||||
@ -5038,27 +5043,37 @@ implementation
|
|||||||
begin
|
begin
|
||||||
WriteByte(FWasmSections[wsiGlobal],$41); { i32.const }
|
WriteByte(FWasmSections[wsiGlobal],$41); { i32.const }
|
||||||
WriteSleb(FWasmSections[wsiGlobal],init_i32);
|
WriteSleb(FWasmSections[wsiGlobal],init_i32);
|
||||||
|
if assigned(exemap) then
|
||||||
|
mapstr:=mapstr+'i32='+tostr(init_i32);
|
||||||
end;
|
end;
|
||||||
wbt_i64:
|
wbt_i64:
|
||||||
begin
|
begin
|
||||||
WriteByte(FWasmSections[wsiGlobal],$42); { i64.const }
|
WriteByte(FWasmSections[wsiGlobal],$42); { i64.const }
|
||||||
WriteSleb(FWasmSections[wsiGlobal],init_i64);
|
WriteSleb(FWasmSections[wsiGlobal],init_i64);
|
||||||
|
if assigned(exemap) then
|
||||||
|
mapstr:=mapstr+'i64='+tostr(init_i64);
|
||||||
end;
|
end;
|
||||||
wbt_f32:
|
wbt_f32:
|
||||||
begin
|
begin
|
||||||
WriteByte(FWasmSections[wsiGlobal],$43); { f32.const }
|
WriteByte(FWasmSections[wsiGlobal],$43); { f32.const }
|
||||||
WriteF32LE(FWasmSections[wsiGlobal],init_f32);
|
WriteF32LE(FWasmSections[wsiGlobal],init_f32);
|
||||||
|
if assigned(exemap) then
|
||||||
|
WriteStr(mapstr,mapstr+'f32=',init_f32);
|
||||||
end;
|
end;
|
||||||
wbt_f64:
|
wbt_f64:
|
||||||
begin
|
begin
|
||||||
WriteByte(FWasmSections[wsiGlobal],$44); { f64.const }
|
WriteByte(FWasmSections[wsiGlobal],$44); { f64.const }
|
||||||
WriteF64LE(FWasmSections[wsiGlobal],init_f64);
|
WriteF64LE(FWasmSections[wsiGlobal],init_f64);
|
||||||
|
if assigned(exemap) then
|
||||||
|
WriteStr(mapstr,mapstr+'f64=',init_f64);
|
||||||
end;
|
end;
|
||||||
wbt_funcref,
|
wbt_funcref,
|
||||||
wbt_externref:
|
wbt_externref:
|
||||||
begin
|
begin
|
||||||
WriteByte(FWasmSections[wsiGlobal],$D0); { ref.null }
|
WriteByte(FWasmSections[wsiGlobal],$D0); { ref.null }
|
||||||
WriteByte(FWasmSections[wsiGlobal],encode_wasm_basic_type(typ));
|
WriteByte(FWasmSections[wsiGlobal],encode_wasm_basic_type(typ));
|
||||||
|
if assigned(exemap) then
|
||||||
|
mapstr:=mapstr+'ref.null '+wasm_basic_type_str[typ];
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
internalerror(2024010114);
|
internalerror(2024010114);
|
||||||
@ -5066,6 +5081,8 @@ implementation
|
|||||||
WriteByte(FWasmSections[wsiGlobal],$0B); { end }
|
WriteByte(FWasmSections[wsiGlobal],$0B); { end }
|
||||||
{ add entry for the name section }
|
{ add entry for the name section }
|
||||||
AddToGlobalNameMap(i,objsec.MainFuncSymbol.Name);
|
AddToGlobalNameMap(i,objsec.MainFuncSymbol.Name);
|
||||||
|
if assigned(exemap) then
|
||||||
|
exemap.Add(mapstr);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -163,6 +163,7 @@ uses
|
|||||||
WasmNumberTypes = [wbt_i32, wbt_i64, wbt_f32, wbt_f64];
|
WasmNumberTypes = [wbt_i32, wbt_i64, wbt_f32, wbt_f64];
|
||||||
WasmReferenceTypes = [wbt_funcref, wbt_externref];
|
WasmReferenceTypes = [wbt_funcref, wbt_externref];
|
||||||
WasmVectorTypes = [wbt_v128];
|
WasmVectorTypes = [wbt_v128];
|
||||||
|
wasm_basic_type_str : array [TWasmBasicType] of string = ('unknown','i32','i64','f32','f64','funcref','externref','v128');
|
||||||
|
|
||||||
{# First value of opcode enumeration }
|
{# First value of opcode enumeration }
|
||||||
firstop = low(tasmop);
|
firstop = low(tasmop);
|
||||||
@ -690,8 +691,6 @@ uses
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmFuncType.ToString: ansistring;
|
function TWasmFuncType.ToString: ansistring;
|
||||||
const
|
|
||||||
wasm_basic_type_str : array [TWasmBasicType] of string = ('unknown','i32','i64','f32','f64','funcref','externref','v128');
|
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user