[PATCH 53/83] change import symbols writing to be based on unit definitions

From 5dfeb66f8a39593a4123764fb51d7bfe2e6d44e6 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <skalogryz.lists@gmail.com>
Date: Sat, 21 Sep 2019 14:21:23 -0400

git-svn-id: branches/wasm@45930 -
This commit is contained in:
nickysn 2020-07-29 18:59:57 +00:00
parent 8a9ff3345d
commit 92b1926aa3
2 changed files with 23 additions and 44 deletions

View File

@ -46,21 +46,7 @@ implementation
{ timportlibwasm }
procedure timportlibwasm.generatelib;
var
i,j : longint;
SmartFilesCount: Integer;
ImportLibrary : TImportLibrary;
ImportSymbol : TImportSymbol;
begin
for i:=0 to current_module.ImportLibraryList.Count-1 do
begin
ImportLibrary:=TImportLibrary(current_module.ImportLibraryList[i]);
for j:=0 to ImportLibrary.ImportSymbolList.Count-1 do
begin
ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList[j]);
current_asmdata.asmlists[al_imports].Concat(tai_impexp.create(ImportLibrary.Name, ImportSymbol.MangledName, ImportSymbol.Name, ie_Func));
end;
end;
end;
{ tlinkerwasm }

View File

@ -57,7 +57,7 @@ interface
procedure WriteSymtableVarSyms(st: TSymtable);
procedure WriteTempAlloc(p:TAsmList);
procedure WriteExports(p: TAsmList);
procedure WriteImports(p: TAsmList);
procedure WriteImports;
public
constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
procedure WriteTree(p:TAsmList);override;
@ -238,8 +238,7 @@ implementation
begin
if not assigned(tcpuprocdef(pd).exprasmlist) and
not(po_abstractmethod in pd.procoptions) and
(not is_javainterface(pd.struct) or
(pd.proctypeoption in [potype_unitinit,potype_unitfinalize])) then
((pd.proctypeoption in [potype_unitinit,potype_unitfinalize])) then
begin
exit;
end;
@ -556,7 +555,7 @@ implementation
writer.MarkEmpty;
writer.AsmWriteLn('(module ');
writer.AsmWriteLn('(import "env" "memory" (memory 0)) ;;');
WriteImports(current_asmdata.asmlists[al_imports]);
WriteImports;
{ print all global variables }
//current_asmdata.AsmSymbolDict
@ -602,7 +601,9 @@ implementation
own them }
if (not(st.symtabletype in [staticsymtable,globalsymtable]) or
(def.owner=st)) and
not(df_generic in def.defoptions) then
not(df_generic in def.defoptions) and
not (po_external in tprocdef(def).procoptions)
then
begin
WriteProcDef(tprocdef(def));
if assigned(tprocdef(def).localst) then
@ -759,35 +760,27 @@ implementation
end;
end;
procedure TWabtTextAssembler.WriteImports(p: TAsmList);
var
hp: tai;
x: tai_impexp;
begin
if not Assigned(p) then Exit;
hp:=tai(p.First);
while Assigned(hp) do begin
case hp.typ of
ait_importexport:
begin
x:=tai_impexp(hp);
writer.AsmWrite('(import "');
writer.AsmWrite(x.extmodule);
writer.AsmWrite('" "');
writer.AsmWrite(x.extname);
writer.AsmWrite('" (');
case x.symstype of
ie_Func: writer.AsmWrite('func');
procedure TWabtTextAssembler.WriteImports;
var
i : integer;
proc : tprocdef;
begin
for i:=0 to current_module.deflist.Count-1 do begin
//writeln('>def: ', tdef(current_module.deflist[i]).typ);
if tdef(current_module.deflist[i]).typ = procdef then begin
proc := tprocdef(current_module.deflist[i]);
if (po_external in proc.procoptions) and assigned(proc.import_dll) then begin
writer.AsmWrite('(import "');
writer.AsmWrite(proc.import_dll^);
writer.AsmWrite('" "');
writer.AsmWrite(proc.import_name^);
writer.AsmWrite('" ');
WriteProcDef(proc);
writer.AsmWriteLn(')');
end;
writer.AsmWrite(' ');
writer.AsmWrite(GetWasmName(x.intname));
writer.AsmWrite('))');
writer.AsmLn;
end;
end;
hp := tai_impexp(hp.Next);
end;
end;
{ TWatInstrWriter }