mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 21:09:24 +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_MEMORY_ADDR_LEB,
|
||||
RELOC_MEMORY_ADDR_SLEB,
|
||||
RELOC_TYPE_INDEX_LEB,
|
||||
{$endif WASM32}
|
||||
{ Relative relocation }
|
||||
RELOC_RELATIVE,
|
||||
|
@ -57,6 +57,9 @@ interface
|
||||
{ TWasmObjRelocation }
|
||||
|
||||
TWasmObjRelocation = class(TObjRelocation)
|
||||
public
|
||||
TypeIndex: Integer;
|
||||
constructor CreateTypeIndex(ADataOffset:TObjSectionOfs; ATypeIndex: Integer);
|
||||
end;
|
||||
|
||||
{ TWasmObjSymbolExtraData }
|
||||
@ -273,6 +276,21 @@ implementation
|
||||
WriteUleb5(d,q);
|
||||
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
|
||||
****************************************************************************}
|
||||
@ -558,6 +576,16 @@ implementation
|
||||
Data:=NtoLE(Data);
|
||||
writebytes(Data,4);
|
||||
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
|
||||
internalerror(2021092501);
|
||||
end;
|
||||
@ -903,6 +931,8 @@ implementation
|
||||
end;
|
||||
RELOC_ABSOLUTE:
|
||||
;
|
||||
RELOC_TYPE_INDEX_LEB:
|
||||
;
|
||||
else
|
||||
internalerror(2021092510);
|
||||
end;
|
||||
@ -978,6 +1008,13 @@ implementation
|
||||
else
|
||||
internalerror(2021092609);
|
||||
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
|
||||
internalerror(2021092507);
|
||||
end;
|
||||
|
@ -149,6 +149,9 @@ uses
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
ogwasm;
|
||||
|
||||
{ tai_import_name }
|
||||
|
||||
constructor tai_import_name.create(const asymname, aimportname: string);
|
||||
@ -652,6 +655,22 @@ implementation
|
||||
internalerror(2021092022);
|
||||
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
|
||||
Writeln('Warning! Not implemented opcode, pass1: ', opcode);
|
||||
end;
|
||||
@ -1135,6 +1154,22 @@ implementation
|
||||
internalerror(2021092022);
|
||||
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
|
||||
Writeln('Warning! Not implemented opcode, pass2: ', opcode);
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user