mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-04 19:30:32 +02:00
+ support the call_indirect instruction and the R_WASM_TYPE_INDEX_LEB
relocation that it requires in the internal wasm object writer
This commit is contained in:
parent
bd6bbb6cf4
commit
9fa2e2934b
@ -116,6 +116,7 @@ interface
|
|||||||
RELOC_FUNCTION_INDEX_LEB,
|
RELOC_FUNCTION_INDEX_LEB,
|
||||||
RELOC_MEMORY_ADDR_LEB,
|
RELOC_MEMORY_ADDR_LEB,
|
||||||
RELOC_MEMORY_ADDR_SLEB,
|
RELOC_MEMORY_ADDR_SLEB,
|
||||||
|
RELOC_TYPE_INDEX_LEB,
|
||||||
{$endif WASM32}
|
{$endif WASM32}
|
||||||
{ Relative relocation }
|
{ Relative relocation }
|
||||||
RELOC_RELATIVE,
|
RELOC_RELATIVE,
|
||||||
|
@ -57,6 +57,9 @@ interface
|
|||||||
{ TWasmObjRelocation }
|
{ TWasmObjRelocation }
|
||||||
|
|
||||||
TWasmObjRelocation = class(TObjRelocation)
|
TWasmObjRelocation = class(TObjRelocation)
|
||||||
|
public
|
||||||
|
TypeIndex: Integer;
|
||||||
|
constructor CreateTypeIndex(ADataOffset:TObjSectionOfs; ATypeIndex: Integer);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TWasmObjSymbolExtraData }
|
{ TWasmObjSymbolExtraData }
|
||||||
@ -273,6 +276,21 @@ implementation
|
|||||||
WriteUleb5(d,q);
|
WriteUleb5(d,q);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{****************************************************************************
|
||||||
|
TWasmObjRelocation
|
||||||
|
****************************************************************************}
|
||||||
|
|
||||||
|
constructor TWasmObjRelocation.CreateTypeIndex(ADataOffset: TObjSectionOfs; ATypeIndex: Integer);
|
||||||
|
begin
|
||||||
|
DataOffset:=ADataOffset;
|
||||||
|
Symbol:=nil;
|
||||||
|
OrgSize:=0;
|
||||||
|
Group:=nil;
|
||||||
|
ObjSection:=nil;
|
||||||
|
ftype:=ord(RELOC_TYPE_INDEX_LEB);
|
||||||
|
TypeIndex:=ATypeIndex;
|
||||||
|
end;
|
||||||
|
|
||||||
{****************************************************************************
|
{****************************************************************************
|
||||||
TWasmObjSymbol
|
TWasmObjSymbol
|
||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
@ -558,6 +576,16 @@ implementation
|
|||||||
Data:=NtoLE(Data);
|
Data:=NtoLE(Data);
|
||||||
writebytes(Data,4);
|
writebytes(Data,4);
|
||||||
end;
|
end;
|
||||||
|
RELOC_TYPE_INDEX_LEB:
|
||||||
|
begin
|
||||||
|
if len<>5 then
|
||||||
|
internalerror(2021092612);
|
||||||
|
if assigned(p) then
|
||||||
|
internalerror(2021092613);
|
||||||
|
objreloc:=TWasmObjRelocation.CreateTypeIndex(CurrObjSec.Size,Data);
|
||||||
|
CurrObjSec.ObjRelocations.Add(objreloc);
|
||||||
|
WriteUleb5(CurrObjSec,Data);
|
||||||
|
end;
|
||||||
else
|
else
|
||||||
internalerror(2021092501);
|
internalerror(2021092501);
|
||||||
end;
|
end;
|
||||||
@ -903,6 +931,8 @@ implementation
|
|||||||
end;
|
end;
|
||||||
RELOC_ABSOLUTE:
|
RELOC_ABSOLUTE:
|
||||||
;
|
;
|
||||||
|
RELOC_TYPE_INDEX_LEB:
|
||||||
|
;
|
||||||
else
|
else
|
||||||
internalerror(2021092510);
|
internalerror(2021092510);
|
||||||
end;
|
end;
|
||||||
@ -978,6 +1008,13 @@ implementation
|
|||||||
else
|
else
|
||||||
internalerror(2021092609);
|
internalerror(2021092609);
|
||||||
end;
|
end;
|
||||||
|
RELOC_TYPE_INDEX_LEB:
|
||||||
|
begin
|
||||||
|
Inc(relcount^);
|
||||||
|
WriteByte(relout,Ord(R_WASM_TYPE_INDEX_LEB));
|
||||||
|
WriteUleb(relout,objrel.DataOffset+objsec.FileSectionOfs);
|
||||||
|
WriteUleb(relout,objrel.TypeIndex);
|
||||||
|
end;
|
||||||
else
|
else
|
||||||
internalerror(2021092507);
|
internalerror(2021092507);
|
||||||
end;
|
end;
|
||||||
|
@ -149,6 +149,9 @@ uses
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
ogwasm;
|
||||||
|
|
||||||
{ tai_import_name }
|
{ tai_import_name }
|
||||||
|
|
||||||
constructor tai_import_name.create(const asymname, aimportname: string);
|
constructor tai_import_name.create(const asymname, aimportname: string);
|
||||||
@ -652,6 +655,22 @@ implementation
|
|||||||
internalerror(2021092022);
|
internalerror(2021092022);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
a_call_indirect:
|
||||||
|
begin
|
||||||
|
if ops<>1 then
|
||||||
|
internalerror(2021092610);
|
||||||
|
with oper[0]^ do
|
||||||
|
case typ of
|
||||||
|
top_functype:
|
||||||
|
begin
|
||||||
|
TWasmObjData(objdata).AddFuncType(functype);
|
||||||
|
result:=6+
|
||||||
|
UlebSize(0);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
internalerror(2021092611);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
else
|
else
|
||||||
Writeln('Warning! Not implemented opcode, pass1: ', opcode);
|
Writeln('Warning! Not implemented opcode, pass1: ', opcode);
|
||||||
end;
|
end;
|
||||||
@ -1135,6 +1154,22 @@ implementation
|
|||||||
internalerror(2021092022);
|
internalerror(2021092022);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
a_call_indirect:
|
||||||
|
begin
|
||||||
|
if ops<>1 then
|
||||||
|
internalerror(2021092610);
|
||||||
|
with oper[0]^ do
|
||||||
|
case typ of
|
||||||
|
top_functype:
|
||||||
|
begin
|
||||||
|
WriteByte($11);
|
||||||
|
objdata.writeReloc(TWasmObjData(objdata).AddFuncType(functype),5,nil,RELOC_TYPE_INDEX_LEB);
|
||||||
|
WriteUleb(0);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
internalerror(2021092611);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
else
|
else
|
||||||
Writeln('Warning! Not implemented opcode, pass2: ', opcode);
|
Writeln('Warning! Not implemented opcode, pass2: ', opcode);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user