+ write the non-external functions to the symbol table as well

This commit is contained in:
Nikolay Nikolov 2021-09-25 23:02:48 +03:00
parent 2805e44ccb
commit ad8ed4b48d

View File

@ -44,6 +44,7 @@ interface
TWasmObjSymbol = class(TObjSymbol)
ImportIndex: Integer;
FuncIndex: Integer;
constructor create(AList:TFPHashObjectList;const AName:string);
end;
@ -148,6 +149,7 @@ implementation
begin
inherited create(AList,AName);
ImportIndex:=-1;
FuncIndex:=-1;
end;
{****************************************************************************
@ -668,7 +670,7 @@ implementation
segment_count: Integer = 0;
cur_seg_ofs: qword = 0;
types_count,
imports_count, NextImportFunctionIndex: Integer;
imports_count, NextImportFunctionIndex, NextFunctionIndex: Integer;
import_functions_count: Integer = 0;
functions_count: Integer = 0;
objsym: TWasmObjSymbol;
@ -779,11 +781,14 @@ implementation
WriteUleb(FWasmSections[wsiFunction],functions_count);
WriteUleb(FWasmSections[wsiCode],functions_count);
NextFunctionIndex:=NextImportFunctionIndex;
for i:=0 to Data.ObjSymbolList.Count-1 do
begin
objsym:=TWasmObjSymbol(Data.ObjSymbolList[i]);
if objsym.typ=AT_FUNCTION then
begin
objsym.FuncIndex:=NextFunctionIndex;
Inc(NextFunctionIndex);
WriteUleb(FWasmSections[wsiFunction],TWasmObjSymbolExtraData(FData.FObjSymbolsExtraDataList.Find(objsym.Name)).TypeIdx);
WriteFunctionCode(FWasmSections[wsiCode],objsym);
end;
@ -801,6 +806,11 @@ implementation
end
else if objsym.typ=AT_FUNCTION then
begin
Inc(FWasmSymbolTableEntriesCount);
WriteByte(FWasmSymbolTable,Ord(SYMTAB_FUNCTION));
WriteUleb(FWasmSymbolTable,0);
WriteUleb(FWasmSymbolTable,objsym.FuncIndex);
WriteName(FWasmSymbolTable,objsym.Name);
end;
end;