mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-08 02:07:53 +02:00
+ WebAssembly external asm writer: workaround for the 'missing functype' error,
produced by LLVM-MC versions 13 and above
This commit is contained in:
parent
9956cafa65
commit
5e327453a8
@ -71,6 +71,7 @@ interface
|
||||
destructor destroy; override;
|
||||
{$ifdef WASM}
|
||||
procedure WriteFuncType(functype: TWasmFuncType);
|
||||
procedure WriteFuncTypeDirective(hp:tai_functype);virtual;abstract;
|
||||
{$endif WASM}
|
||||
private
|
||||
setcount: longint;
|
||||
@ -815,16 +816,6 @@ implementation
|
||||
end;
|
||||
|
||||
{$ifdef WASM}
|
||||
procedure WriteFuncTypeDirective(hp:tai_functype);
|
||||
begin
|
||||
writer.AsmWrite(#9'.functype'#9);
|
||||
writer.AsmWrite(hp.funcname);
|
||||
writer.AsmWrite(' ');
|
||||
WriteFuncType(hp.functype);
|
||||
writer.AsmLn;
|
||||
end;
|
||||
|
||||
|
||||
procedure WriteTagType(hp: tai_tagtype);
|
||||
var
|
||||
wasm_basic_typ: TWasmBasicType;
|
||||
|
@ -348,7 +348,8 @@ uses
|
||||
tai_functype = class(tai)
|
||||
funcname: string;
|
||||
functype: TWasmFuncType;
|
||||
constructor create(const afuncname: string; afunctype: TWasmFuncType);
|
||||
is_forward: Boolean;
|
||||
constructor create(const afuncname: string; afunctype: TWasmFuncType; aisforward: Boolean);
|
||||
destructor destroy;override;
|
||||
end;
|
||||
|
||||
@ -1862,10 +1863,11 @@ uses
|
||||
|
||||
{ tai_functype }
|
||||
|
||||
constructor tai_functype.create(const afuncname: string; afunctype: TWasmFuncType);
|
||||
constructor tai_functype.create(const afuncname: string; afunctype: TWasmFuncType; aisforward: Boolean);
|
||||
begin
|
||||
inherited Create;
|
||||
typ:=ait_functype;
|
||||
is_forward:=aisforward;
|
||||
funcname:=afuncname;
|
||||
functype:=afunctype;
|
||||
end;
|
||||
|
@ -44,6 +44,7 @@ interface
|
||||
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
|
||||
public
|
||||
constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
|
||||
procedure WriteFuncTypeDirective(hp:tai_functype);override;
|
||||
end;
|
||||
|
||||
{ TLLVMMachineCodePlaygroundAssemblerV10 }
|
||||
@ -160,6 +161,19 @@ implementation
|
||||
end;
|
||||
|
||||
|
||||
procedure TLLVMMachineCodePlaygroundAssembler.WriteFuncTypeDirective(hp: tai_functype);
|
||||
begin
|
||||
if not hp.is_forward or (FLLVMMajorVersion>=13) then
|
||||
begin
|
||||
writer.AsmWrite(#9'.functype'#9);
|
||||
writer.AsmWrite(hp.funcname);
|
||||
writer.AsmWrite(' ');
|
||||
WriteFuncType(hp.functype);
|
||||
writer.AsmLn;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ TWASM32InstrWriter }
|
||||
|
||||
|
||||
|
@ -148,7 +148,7 @@ uses
|
||||
|
||||
{ Wasm-specific routines }
|
||||
|
||||
procedure g_procdef(list:TAsmList;pd: tprocdef);
|
||||
procedure g_procdef(list:TAsmList;pd: tprocdef;is_forward: Boolean);
|
||||
procedure g_maybe_checkforexceptions(list:TasmList); override;
|
||||
|
||||
procedure a_load_stack_reg(list : TAsmList;size: tdef;reg: tregister);
|
||||
@ -2058,7 +2058,7 @@ implementation
|
||||
pd: tcpuprocdef;
|
||||
begin
|
||||
pd:=tcpuprocdef(current_procinfo.procdef);
|
||||
g_procdef(list,pd);
|
||||
g_procdef(list,pd,false);
|
||||
|
||||
if not nostackframe then
|
||||
begin
|
||||
@ -2457,10 +2457,10 @@ implementation
|
||||
internalerror(2012090206);
|
||||
end;
|
||||
|
||||
procedure thlcgwasm.g_procdef(list: TAsmList; pd: tprocdef);
|
||||
procedure thlcgwasm.g_procdef(list: TAsmList; pd: tprocdef; is_forward: Boolean);
|
||||
begin
|
||||
if not pd.is_generic then
|
||||
list.Concat(tai_functype.create(pd.mangledname,tcpuprocdef(pd).create_functype));
|
||||
list.Concat(tai_functype.create(pd.mangledname,tcpuprocdef(pd).create_functype,is_forward));
|
||||
end;
|
||||
|
||||
procedure thlcgwasm.g_maybe_checkforexceptions(list: TasmList);
|
||||
|
@ -87,7 +87,7 @@ implementation
|
||||
|
||||
procedure WriteImportDll(list: TAsmList; proc: tprocdef);
|
||||
begin
|
||||
thlcgwasm(hlcg).g_procdef(list,proc);
|
||||
thlcgwasm(hlcg).g_procdef(list,proc,false);
|
||||
list.Concat(tai_import_module.create(proc.mangledname,proc.import_dll^));
|
||||
list.Concat(tai_import_name.create(proc.mangledname,proc.import_name^));
|
||||
end;
|
||||
@ -113,9 +113,9 @@ implementation
|
||||
if ((u.moduleflags * [mf_init,mf_finalize])<>[]) and assigned(u.globalsymtable) then
|
||||
begin
|
||||
if mf_init in u.moduleflags then
|
||||
list.Concat(tai_functype.create(make_mangledname('INIT$',u.globalsymtable,''),TWasmFuncType.Create([],[])));
|
||||
list.Concat(tai_functype.create(make_mangledname('INIT$',u.globalsymtable,''),TWasmFuncType.Create([],[]),false));
|
||||
if mf_finalize in u.moduleflags then
|
||||
list.Concat(tai_functype.create(make_mangledname('FINALIZE$',u.globalsymtable,''),TWasmFuncType.Create([],[])));
|
||||
list.Concat(tai_functype.create(make_mangledname('FINALIZE$',u.globalsymtable,''),TWasmFuncType.Create([],[]),false));
|
||||
end;
|
||||
for i:=0 to u.deflist.Count-1 do
|
||||
begin
|
||||
@ -126,7 +126,9 @@ implementation
|
||||
if (po_external in proc.procoptions) and (po_has_importdll in proc.procoptions) then
|
||||
WriteImportDll(list,proc)
|
||||
else if not proc.owner.iscurrentunit or (po_external in proc.procoptions) then
|
||||
thlcgwasm(hlcg).g_procdef(list,proc);
|
||||
thlcgwasm(hlcg).g_procdef(list,proc,false)
|
||||
else
|
||||
thlcgwasm(hlcg).g_procdef(list,proc,true);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -170,7 +172,7 @@ implementation
|
||||
if po_has_importdll in proc.procoptions then
|
||||
WriteImportDll(list,proc)
|
||||
else
|
||||
thlcgwasm(hlcg).g_procdef(list,proc);
|
||||
thlcgwasm(hlcg).g_procdef(list,proc,false);
|
||||
end;
|
||||
end;
|
||||
create_hlcodegen;
|
||||
|
Loading…
Reference in New Issue
Block a user