wasmbase.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. {
  2. Copyright (c) 2021 by Nikolay Nikolov
  3. Contains WebAssembly binary module format definitions
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit wasmbase;
  18. {$i fpcdefs.inc}
  19. interface
  20. const
  21. WasmModuleMagic: array [0..3] of byte = ($00,$61,$73,$6D);
  22. WasmVersion: array [0..3] of byte = ($01,$00,$00,$00);
  23. type
  24. TWasmSectionID = (
  25. wsiCustom = 0,
  26. wsiType = 1,
  27. wsiImport = 2,
  28. wsiFunction = 3,
  29. wsiTable = 4,
  30. wsiMemory = 5,
  31. wsiGlobal = 6,
  32. wsiExport = 7,
  33. wsiStart = 8,
  34. wsiElement = 9,
  35. wsiCode = 10,
  36. wsiData = 11,
  37. wsiDataCount = 12,
  38. wsiTag = 13);
  39. TWasmCustomSectionType = (
  40. wcstLinking,
  41. wcstRelocCode,
  42. wcstRelocData,
  43. wcstProducers,
  44. wcstTargetFeatures);
  45. const
  46. WasmCustomSectionName: array [TWasmCustomSectionType] of string =
  47. ('linking',
  48. 'reloc.CODE',
  49. 'reloc.DATA',
  50. 'producers',
  51. 'target_features');
  52. type
  53. TWasmRelocationType = (
  54. R_WASM_FUNCTION_INDEX_LEB = 0,
  55. R_WASM_TABLE_INDEX_SLEB = 1,
  56. R_WASM_TABLE_INDEX_I32 = 2,
  57. R_WASM_MEMORY_ADDR_LEB = 3,
  58. R_WASM_MEMORY_ADDR_SLEB = 4,
  59. R_WASM_MEMORY_ADDR_I32 = 5,
  60. R_WASM_TYPE_INDEX_LEB = 6,
  61. R_WASM_GLOBAL_INDEX_LEB = 7,
  62. R_WASM_FUNCTION_OFFSET_I32 = 8,
  63. R_WASM_SECTION_OFFSET_I32 = 9,
  64. R_WASM_TAG_INDEX_LEB = 10,
  65. R_WASM_GLOBAL_INDEX_I32 = 13,
  66. R_WASM_MEMORY_ADDR_LEB64 = 14,
  67. R_WASM_MEMORY_ADDR_SLEB64 = 15,
  68. R_WASM_MEMORY_ADDR_I64 = 16,
  69. R_WASM_TABLE_INDEX_SLEB64 = 18,
  70. R_WASM_TABLE_INDEX_I64 = 19,
  71. R_WASM_TABLE_NUMBER_LEB = 20);
  72. TWasmLinkingSubsectionType = (
  73. WASM_SEGMENT_INFO = 5,
  74. WASM_INIT_FUNCS = 6,
  75. WASM_COMDAT_INFO = 7,
  76. WASM_SYMBOL_TABLE = 8);
  77. TWasmSymbolType = (
  78. SYMTAB_FUNCTION = 0,
  79. SYMTAB_DATA = 1,
  80. SYMTAB_GLOBAL = 2,
  81. SYMTAB_SECTION = 3,
  82. SYMTAB_EVENT = 4,
  83. SYMTAB_TABLE = 5);
  84. const
  85. { symbol flags }
  86. WASM_SYM_BINDING_WEAK = $01;
  87. WASM_SYM_BINDING_LOCAL = $02;
  88. WASM_SYM_VISIBILITY_HIDDEN = $04;
  89. WASM_SYM_UNDEFINED = $10;
  90. WASM_SYM_EXPORTED = $20;
  91. WASM_SYM_EXPLICIT_NAME = $40;
  92. WASM_SYM_NO_STRIP = $80;
  93. implementation
  94. end.