Browse Source

+ wasm resource writer: implemented TWasmResourceWriter.WriteResStringTable

Nikolay Nikolov 1 year ago
parent
commit
2e553ab0e8
1 changed files with 25 additions and 0 deletions
  1. 25 0
      packages/fcl-res/src/wasmwriter.pp

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

@@ -52,6 +52,7 @@ type
     FWasmLinkingSubsections: array [low(TWasmLinkingSubsectionType)..high(TWasmLinkingSubsectionType)] of TMemoryStream;
     FWasmLinkingSubsections: array [low(TWasmLinkingSubsectionType)..high(TWasmLinkingSubsectionType)] of TMemoryStream;
     FWasmSymbolTable: TMemoryStream;
     FWasmSymbolTable: TMemoryStream;
     FWasmSymbolTableEntriesCount: Integer;
     FWasmSymbolTableEntriesCount: Integer;
+    procedure Align(aBound : integer; aStream : TStream);
     function NextAligned(aBound, aValue : longword) : longword;
     function NextAligned(aBound, aValue : longword) : longword;
     procedure PrescanResourceTree;
     procedure PrescanResourceTree;
     function PrescanNode(aNode : TResourceTreeNode; aNodeSize : longword) : longword;
     function PrescanNode(aNode : TResourceTreeNode; aNodeSize : longword) : longword;
@@ -61,6 +62,7 @@ type
     procedure WriteNodeInfos;
     procedure WriteNodeInfos;
     procedure WriteNodeInfo(aNode : TResourceTreeNode);
     procedure WriteNodeInfo(aNode : TResourceTreeNode);
     procedure WriteSubNodes(aNode : TResourceTreeNode);
     procedure WriteSubNodes(aNode : TResourceTreeNode);
+    procedure WriteResStringTable;
     procedure WriteWasmSection(aStream: TStream; wsid: TWasmSectionID);
     procedure WriteWasmSection(aStream: TStream; wsid: TWasmSectionID);
     procedure WriteWasmSectionIfNotEmpty(aStream: TStream; wsid: TWasmSectionID);
     procedure WriteWasmSectionIfNotEmpty(aStream: TStream; wsid: TWasmSectionID);
     procedure WriteWasmCustomSection(aStream: TStream; wcst: TWasmCustomSectionType);
     procedure WriteWasmCustomSection(aStream: TStream; wcst: TWasmCustomSectionType);
@@ -118,6 +120,21 @@ end;
 
 
 { TWasmResourceWriter }
 { TWasmResourceWriter }
 
 
+procedure TWasmResourceWriter.Align(aBound: integer; aStream: TStream);
+var topad,tmp : integer;
+    qw : qword;
+begin
+  qw:=0;
+  topad:=aBound-(aStream.Position mod aBound);
+  if topad<>aBound then
+    while topad>0 do
+    begin
+      if topad>8 then tmp:=8 else tmp:=topad;
+      aStream.WriteBuffer(qw,tmp);
+      dec(topad,tmp);
+    end;
+end;
+
 function TWasmResourceWriter.NextAligned(aBound, aValue: longword): longword;
 function TWasmResourceWriter.NextAligned(aBound, aValue: longword): longword;
 var topad : longword;
 var topad : longword;
 begin
 begin
@@ -307,6 +324,13 @@ begin
     WriteSubNodes(aNode.IDEntries[i]);
     WriteSubNodes(aNode.IDEntries[i]);
 end;
 end;
 
 
+procedure TWasmResourceWriter.WriteResStringTable;
+begin
+  if fResStringTable.Used then
+    fResStringTable.WriteToStream(FDataSegments[wrdsResources]);
+  Align(fDataAlignment,FDataSegments[wrdsResources]);
+end;
+
 procedure TWasmResourceWriter.WriteWasmSection(aStream: TStream;
 procedure TWasmResourceWriter.WriteWasmSection(aStream: TStream;
   wsid: TWasmSectionID);
   wsid: TWasmSectionID);
 var
 var
@@ -424,6 +448,7 @@ begin
   PrescanResourceTree;
   PrescanResourceTree;
   WriteResHeader(aResources);
   WriteResHeader(aResources);
   WriteNodeInfos;
   WriteNodeInfos;
+  WriteResStringTable;
 
 
   WriteImportSection;
   WriteImportSection;
   WriteDataSegments;
   WriteDataSegments;