Browse Source

+ wasm resource writer: create a symbol table (empty for now)

Nikolay Nikolov 1 year ago
parent
commit
49c1416409
1 changed files with 14 additions and 0 deletions
  1. 14 0
      packages/fcl-res/src/wasmwriter.pp

+ 14 - 0
packages/fcl-res/src/wasmwriter.pp

@@ -47,6 +47,8 @@ type
     FDataSegments: array [TWasmResourceDataSegment] of TMemoryStream;
     FWasmCustomSections: array [TWasmCustomSectionType] of TMemoryStream;
     FWasmLinkingSubsections: array [low(TWasmLinkingSubsectionType)..high(TWasmLinkingSubsectionType)] of TMemoryStream;
+    FWasmSymbolTable: TMemoryStream;
+    FWasmSymbolTableEntriesCount: Integer;
     function NextAligned(aBound, aValue : longword) : longword;
     procedure PrescanResourceTree;
     function PrescanNode(aNode : TResourceTreeNode; aNodeSize : longword) : longword;
@@ -58,6 +60,7 @@ type
     procedure WriteCustomSectionNames;
     procedure WriteImportSection;
     procedure WriteDataSegments;
+    procedure WriteSymbolTable;
   protected
     function GetExtensions : string; override;
     function GetDescription : string; override;
@@ -275,6 +278,12 @@ begin
   end;
 end;
 
+procedure TWasmResourceWriter.WriteSymbolTable;
+begin
+  WriteUleb(FWasmLinkingSubsections[WASM_SYMBOL_TABLE],FWasmSymbolTableEntriesCount);
+  FWasmLinkingSubsections[WASM_SYMBOL_TABLE].CopyFrom(FWasmSymbolTable,0);
+end;
+
 function TWasmResourceWriter.GetExtensions: string;
 begin
   Result:=fExtensions;
@@ -298,6 +307,8 @@ begin
   WriteImportSection;
   WriteDataSegments;
 
+  WriteSymbolTable;
+  WriteLinkingSubsection(WASM_SYMBOL_TABLE);
   WriteLinkingSubsection(WASM_SEGMENT_INFO);
 
   aStream.WriteBuffer(WasmModuleMagic,SizeOf(WasmModuleMagic));
@@ -325,6 +336,8 @@ begin
 {$ELSE FPC_BIG_ENDIAN}
   fOppositeEndianess := False;
 {$ENDIF FPC_BIG_ENDIAN}
+  FWasmSymbolTable:=TMemoryStream.Create;
+  FWasmSymbolTableEntriesCount:=0;
   for i in TWasmSectionID do
     FWasmSections[i] := TMemoryStream.Create;
   for j in TWasmResourceDataSegment do
@@ -350,6 +363,7 @@ begin
     FreeAndNil(FDataSegments[j]);
   for i in TWasmSectionID do
     FreeAndNil(FWasmSections[i]);
+  FreeAndNil(FWasmSymbolTable);
   FreeAndNil(fResStringTable);
   inherited Destroy;
 end;