From ad8ed4b48d60ec8becdf5609d9b1a63cfbd1efdd Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Sat, 25 Sep 2021 23:02:48 +0300 Subject: [PATCH] + write the non-external functions to the symbol table as well --- compiler/ogwasm.pas | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/ogwasm.pas b/compiler/ogwasm.pas index 0013820357..8fd424154f 100644 --- a/compiler/ogwasm.pas +++ b/compiler/ogwasm.pas @@ -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;