浏览代码

+ added units wasmconsts and wasmtypes

Nikolay Nikolov 1 年之前
父节点
当前提交
55e55cf247

+ 8 - 0
packages/fcl-res/fpmake.pp

@@ -116,10 +116,18 @@ begin
           AddInclude('elfsubwriter.inc');
           AddInclude('elfdefaulttarget.inc');
         end;
+    T:=P.Targets.AddUnit('wasmtypes.pp');
+    T:=P.Targets.AddUnit('wasmconsts.pp');
+      with T.Dependencies do
+        begin
+          AddUnit('wasmtypes');
+        end;
     T:=P.Targets.AddUnit('wasmwriter.pp');
       with T.Dependencies do
         begin
           AddUnit('resource');
+          AddUnit('wasmconsts');
+          AddUnit('wasmtypes');
         end;
     T:=P.Targets.AddUnit('externaltypes.pp');
     T:=P.Targets.AddUnit('externalreader.pp');

+ 3 - 0
packages/fcl-res/namespaced/System.Resources.WebAssembly.Consts.pp

@@ -0,0 +1,3 @@
+unit System.Resources.WebAssembly.Consts;
+{$DEFINE FPC_DOTTEDUNITS}
+{$i wasmconsts.pp}

+ 3 - 0
packages/fcl-res/namespaced/System.Resources.WebAssembly.Types.pp

@@ -0,0 +1,3 @@
+unit System.Resources.WebAssembly.Types;
+{$DEFINE FPC_DOTTEDUNITS}
+{$i wasmtypes.pp}

+ 2 - 0
packages/fcl-res/namespaces.lst

@@ -41,3 +41,5 @@ src/machowriter.pp=namespaced/System.Resources.Macho.Writer.pp
 src/resource.pp=namespaced/System.Resources.Resource.pp
 src/resfactory.pp=namespaced/System.Resources.Factory.pp
 src/wasmwriter.pp=namespaced/System.Resources.WebAssembly.Writer.pp
+src/wasmconsts.pp=namespaced/System.Resources.WebAssembly.Consts.pp
+src/wasmtypes.pp=namespaced/System.Resources.WebAssembly.Types.pp

+ 75 - 0
packages/fcl-res/src/wasmconsts.pp

@@ -0,0 +1,75 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2024 by Nikolay Nikolov
+
+    Constants used by the WebAssembly resource reader and writer
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{$IFNDEF FPC_DOTTEDUNITS}
+unit wasmconsts;
+{$ENDIF FPC_DOTTEDUNITS}
+
+{$MODE OBJFPC}
+
+interface
+
+{$IFDEF FPC_DOTTEDUNITS}
+uses
+  System.Resources.WebAssembly.Types;
+{$ELSE FPC_DOTTEDUNITS}
+uses
+  wasmtypes;
+{$ENDIF FPC_DOTTEDUNITS}
+
+const
+  WasmModuleMagic: array [0..3] of byte = ($00,$61,$73,$6D);
+  WasmVersion: array [0..3] of byte = ($01,$00,$00,$00);
+
+  WasmCustomSectionName: array [TWasmCustomSectionType] of string =
+    ('linking',
+     'reloc.CODE',
+     'reloc.DATA',
+     'producers',
+     'target_features',
+
+     '.debug_frame',
+     '.debug_info',
+     '.debug_line',
+     '.debug_abbrev',
+     '.debug_aranges',
+     '.debug_ranges',
+     '.debug_str',
+
+     'reloc..debug_frame',
+     'reloc..debug_info',
+     'reloc..debug_line',
+     'reloc..debug_abbrev',
+     'reloc..debug_aranges',
+     'reloc..debug_ranges',
+     'reloc..debug_str');
+
+  { segment flags }
+  WASM_SEG_FLAG_STRINGS = $01;
+  WASM_SEG_FLAG_TLS     = $02;
+
+  { symbol flags }
+  WASM_SYM_BINDING_WEAK      = $01;
+  WASM_SYM_BINDING_LOCAL     = $02;
+  WASM_SYM_VISIBILITY_HIDDEN = $04;
+  WASM_SYM_UNDEFINED         = $10;
+  WASM_SYM_EXPORTED          = $20;
+  WASM_SYM_EXPLICIT_NAME     = $40;
+  WASM_SYM_NO_STRIP          = $80;
+  WASM_SYM_TLS               = $100;
+
+implementation
+
+end.

+ 102 - 0
packages/fcl-res/src/wasmtypes.pp

@@ -0,0 +1,102 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2024 by Nikolay Nikolov
+
+    Types used by the WebAssembly resource reader and writer
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{$IFNDEF FPC_DOTTEDUNITS}
+unit wasmtypes;
+{$ENDIF FPC_DOTTEDUNITS}
+
+{$MODE OBJFPC}
+
+interface
+
+type
+  TWasmSectionID = (
+    wsiCustom    = 0,
+    wsiType      = 1,
+    wsiImport    = 2,
+    wsiFunction  = 3,
+    wsiTable     = 4,
+    wsiMemory    = 5,
+    wsiGlobal    = 6,
+    wsiExport    = 7,
+    wsiStart     = 8,
+    wsiElement   = 9,
+    wsiCode      = 10,
+    wsiData      = 11,
+    wsiDataCount = 12,
+    wsiTag       = 13);
+
+  TWasmCustomSectionType = (
+    wcstLinking,
+    wcstRelocCode,
+    wcstRelocData,
+    wcstProducers,
+    wcstTargetFeatures,
+
+    wcstDebugFrame,
+    wcstDebugInfo,
+    wcstDebugLine,
+    wcstDebugAbbrev,
+    wcstDebugAranges,
+    wcstDebugRanges,
+    wcstDebugStr,
+
+    wcstRelocDebugFrame,
+    wcstRelocDebugInfo,
+    wcstRelocDebugLine,
+    wcstRelocDebugAbbrev,
+    wcstRelocDebugAranges,
+    wcstRelocDebugRanges,
+    wcstRelocDebugStr);
+
+  TWasmCustomDebugSectionType = wcstDebugFrame..wcstDebugStr;
+
+  TWasmRelocationType = (
+    R_WASM_FUNCTION_INDEX_LEB  = 0,
+    R_WASM_TABLE_INDEX_SLEB    = 1,
+    R_WASM_TABLE_INDEX_I32     = 2,
+    R_WASM_MEMORY_ADDR_LEB     = 3,
+    R_WASM_MEMORY_ADDR_SLEB    = 4,
+    R_WASM_MEMORY_ADDR_I32     = 5,
+    R_WASM_TYPE_INDEX_LEB      = 6,
+    R_WASM_GLOBAL_INDEX_LEB    = 7,
+    R_WASM_FUNCTION_OFFSET_I32 = 8,
+    R_WASM_SECTION_OFFSET_I32  = 9,
+    R_WASM_TAG_INDEX_LEB       = 10,
+    R_WASM_GLOBAL_INDEX_I32    = 13,
+    R_WASM_MEMORY_ADDR_LEB64   = 14,
+    R_WASM_MEMORY_ADDR_SLEB64  = 15,
+    R_WASM_MEMORY_ADDR_I64     = 16,
+    R_WASM_TABLE_INDEX_SLEB64  = 18,
+    R_WASM_TABLE_INDEX_I64     = 19,
+    R_WASM_TABLE_NUMBER_LEB    = 20);
+
+  TWasmLinkingSubsectionType = (
+    WASM_SEGMENT_INFO = 5,
+    WASM_INIT_FUNCS   = 6,
+    WASM_COMDAT_INFO  = 7,
+    WASM_SYMBOL_TABLE = 8);
+
+  TWasmSymbolType   = (
+    SYMTAB_FUNCTION = 0,
+    SYMTAB_DATA     = 1,
+    SYMTAB_GLOBAL   = 2,
+    SYMTAB_SECTION  = 3,
+    SYMTAB_EVENT    = 4,
+    SYMTAB_TABLE    = 5);
+
+implementation
+
+end.

+ 2 - 6
packages/fcl-res/src/wasmwriter.pp

@@ -24,10 +24,10 @@ interface
 
 {$IFDEF FPC_DOTTEDUNITS}
 uses
-  System.Classes, System.SysUtils, System.Resources.Resource;
+  System.Classes, System.SysUtils, System.Resources.Resource, System.Resources.WebAssembly.Consts, System.Resources.WebAssembly.Types;
 {$ELSE FPC_DOTTEDUNITS}
 uses
-  Classes, SysUtils, resource;
+  Classes, SysUtils, resource, wasmconsts, wasmtypes;
 {$ENDIF FPC_DOTTEDUNITS}
 
 type
@@ -48,10 +48,6 @@ type
 
 implementation
 
-const
-  WasmModuleMagic: array [0..3] of byte = ($00,$61,$73,$6D);
-  WasmVersion: array [0..3] of byte = ($01,$00,$00,$00);
-
 { TWasmResourceWriter }
 
 function TWasmResourceWriter.GetExtensions: string;