mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-21 12:13:12 +02:00
* moved the imports/funcdef writing from the llvm-mc assembler writer to
twasmnodeutils.InsertObjectInfo. This way, the info it produces will be shared with the internal wasm object writer as well.
This commit is contained in:
parent
d19919aa13
commit
54481d7218
@ -40,8 +40,6 @@ interface
|
|||||||
|
|
||||||
TLLVMMachineCodePlaygroundAssembler=class(TGNUassembler)
|
TLLVMMachineCodePlaygroundAssembler=class(TGNUassembler)
|
||||||
protected
|
protected
|
||||||
procedure WriteImports;
|
|
||||||
|
|
||||||
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
|
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
|
||||||
public
|
public
|
||||||
constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
|
constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
|
||||||
@ -67,64 +65,6 @@ implementation
|
|||||||
{ TLLVMMachineCodePlaygroundAssembler }
|
{ TLLVMMachineCodePlaygroundAssembler }
|
||||||
|
|
||||||
|
|
||||||
procedure TLLVMMachineCodePlaygroundAssembler.WriteImports;
|
|
||||||
|
|
||||||
procedure WriteImportDll(list: TAsmList; proc: tprocdef);
|
|
||||||
begin
|
|
||||||
thlcgwasm(hlcg).g_procdef(list,proc);
|
|
||||||
list.Concat(tai_import_module.create(proc.mangledname,proc.import_dll^));
|
|
||||||
list.Concat(tai_import_name.create(proc.mangledname,proc.import_name^));
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
i : integer;
|
|
||||||
def : tdef;
|
|
||||||
proc : tprocdef;
|
|
||||||
list : TAsmList;
|
|
||||||
cur_unit: tused_unit;
|
|
||||||
begin
|
|
||||||
list:=TAsmList.Create;
|
|
||||||
for i:=0 to current_module.deflist.Count-1 do
|
|
||||||
begin
|
|
||||||
def:=tdef(current_module.deflist[i]);
|
|
||||||
{ since commit 48986 deflist might have NIL entries }
|
|
||||||
if assigned(def) and (def.typ=procdef) then
|
|
||||||
begin
|
|
||||||
proc := tprocdef(def);
|
|
||||||
if (po_external in proc.procoptions) and (po_has_importdll in proc.procoptions) then
|
|
||||||
WriteImportDll(list,proc);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
cur_unit:=tused_unit(usedunits.First);
|
|
||||||
while assigned(cur_unit) do
|
|
||||||
begin
|
|
||||||
if (cur_unit.u.moduleflags * [mf_init,mf_finalize])<>[] then
|
|
||||||
begin
|
|
||||||
if mf_init in cur_unit.u.moduleflags then
|
|
||||||
list.Concat(tai_functype.create(make_mangledname('INIT$',cur_unit.u.globalsymtable,''),TWasmFuncType.Create([],[])));
|
|
||||||
if mf_finalize in cur_unit.u.moduleflags then
|
|
||||||
list.Concat(tai_functype.create(make_mangledname('FINALIZE$',cur_unit.u.globalsymtable,''),TWasmFuncType.Create([],[])));
|
|
||||||
end;
|
|
||||||
for i:=0 to cur_unit.u.deflist.Count-1 do
|
|
||||||
begin
|
|
||||||
def:=tdef(cur_unit.u.deflist[i]);
|
|
||||||
if assigned(def) and (tdef(def).typ = procdef) then
|
|
||||||
begin
|
|
||||||
proc := tprocdef(def);
|
|
||||||
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)) and
|
|
||||||
((proc.paras.Count=0) or (proc.has_paraloc_info in [callerside,callbothsides])) then
|
|
||||||
thlcgwasm(hlcg).g_procdef(list,proc);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
cur_unit:=tused_unit(cur_unit.Next);
|
|
||||||
end;
|
|
||||||
WriteTree(list);
|
|
||||||
list.free;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
function TLLVMMachineCodePlaygroundAssembler.sectionname(atype: TAsmSectiontype; const aname: string; aorder: TAsmSectionOrder): string;
|
function TLLVMMachineCodePlaygroundAssembler.sectionname(atype: TAsmSectiontype; const aname: string; aorder: TAsmSectionOrder): string;
|
||||||
begin
|
begin
|
||||||
if (atype=sec_fpc) or (atype=sec_threadvar) then
|
if (atype=sec_fpc) or (atype=sec_threadvar) then
|
||||||
@ -143,8 +83,6 @@ implementation
|
|||||||
procedure TLLVMMachineCodePlaygroundAssembler.WriteAsmList;
|
procedure TLLVMMachineCodePlaygroundAssembler.WriteAsmList;
|
||||||
begin
|
begin
|
||||||
writer.AsmWriteLn(#9'.globaltype'#9+STACK_POINTER_SYM+', i32');
|
writer.AsmWriteLn(#9'.globaltype'#9+STACK_POINTER_SYM+', i32');
|
||||||
{ print all global procedures/functions }
|
|
||||||
WriteImports;
|
|
||||||
if ts_wasm_native_exceptions in current_settings.targetswitches then
|
if ts_wasm_native_exceptions in current_settings.targetswitches then
|
||||||
begin
|
begin
|
||||||
writer.AsmWriteLn(#9'.tagtype'#9'__FPC_exception');
|
writer.AsmWriteLn(#9'.tagtype'#9'__FPC_exception');
|
||||||
|
@ -39,11 +39,71 @@ interface
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
globtype,
|
||||||
|
cpubase,
|
||||||
|
aasmdata,aasmcpu,
|
||||||
|
hlcgobj,hlcgcpu,
|
||||||
|
symdef,symtype,symconst,
|
||||||
|
fmodule;
|
||||||
|
|
||||||
{ twasmnodeutils }
|
{ twasmnodeutils }
|
||||||
|
|
||||||
class procedure twasmnodeutils.InsertObjectInfo;
|
class procedure twasmnodeutils.InsertObjectInfo;
|
||||||
|
|
||||||
|
procedure WriteImportDll(list: TAsmList; proc: tprocdef);
|
||||||
|
begin
|
||||||
|
thlcgwasm(hlcg).g_procdef(list,proc);
|
||||||
|
list.Concat(tai_import_module.create(proc.mangledname,proc.import_dll^));
|
||||||
|
list.Concat(tai_import_name.create(proc.mangledname,proc.import_name^));
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
i : integer;
|
||||||
|
def : tdef;
|
||||||
|
proc : tprocdef;
|
||||||
|
list : TAsmList;
|
||||||
|
cur_unit: tused_unit;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
|
list:=current_asmdata.asmlists[al_start];
|
||||||
|
for i:=0 to current_module.deflist.Count-1 do
|
||||||
|
begin
|
||||||
|
def:=tdef(current_module.deflist[i]);
|
||||||
|
{ since commit 48986 deflist might have NIL entries }
|
||||||
|
if assigned(def) and (def.typ=procdef) then
|
||||||
|
begin
|
||||||
|
proc := tprocdef(def);
|
||||||
|
if (po_external in proc.procoptions) and (po_has_importdll in proc.procoptions) then
|
||||||
|
WriteImportDll(list,proc);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
cur_unit:=tused_unit(usedunits.First);
|
||||||
|
while assigned(cur_unit) do
|
||||||
|
begin
|
||||||
|
if (cur_unit.u.moduleflags * [mf_init,mf_finalize])<>[] then
|
||||||
|
begin
|
||||||
|
if mf_init in cur_unit.u.moduleflags then
|
||||||
|
list.Concat(tai_functype.create(make_mangledname('INIT$',cur_unit.u.globalsymtable,''),TWasmFuncType.Create([],[])));
|
||||||
|
if mf_finalize in cur_unit.u.moduleflags then
|
||||||
|
list.Concat(tai_functype.create(make_mangledname('FINALIZE$',cur_unit.u.globalsymtable,''),TWasmFuncType.Create([],[])));
|
||||||
|
end;
|
||||||
|
for i:=0 to cur_unit.u.deflist.Count-1 do
|
||||||
|
begin
|
||||||
|
def:=tdef(cur_unit.u.deflist[i]);
|
||||||
|
if assigned(def) and (tdef(def).typ = procdef) then
|
||||||
|
begin
|
||||||
|
proc := tprocdef(def);
|
||||||
|
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)) and
|
||||||
|
((proc.paras.Count=0) or (proc.has_paraloc_info in [callerside,callbothsides])) then
|
||||||
|
thlcgwasm(hlcg).g_procdef(list,proc);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
cur_unit:=tused_unit(cur_unit.Next);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user