wasmbase.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. wcstName,
  44. wcstProducers,
  45. wcstTargetFeatures,
  46. wcstDebugFrame,
  47. wcstDebugInfo,
  48. wcstDebugLine,
  49. wcstDebugAbbrev,
  50. wcstDebugAranges,
  51. wcstDebugRanges,
  52. wcstDebugStr,
  53. wcstRelocDebugFrame,
  54. wcstRelocDebugInfo,
  55. wcstRelocDebugLine,
  56. wcstRelocDebugAbbrev,
  57. wcstRelocDebugAranges,
  58. wcstRelocDebugRanges,
  59. wcstRelocDebugStr);
  60. TWasmCustomDebugSectionType = wcstDebugFrame..wcstDebugStr;
  61. TWasmNameSubsectionType = (
  62. wnstModuleName = 0,
  63. wnstFunctionNames = 1,
  64. wnstLocalNames = 2,
  65. wnstLabelNames = 3, { extended name section }
  66. wnstTypeNames = 4, { gc proposal }
  67. wnstTableNames = 5, { extended name section }
  68. wnstMemoryNames = 6, { extended name section }
  69. wnstGlobalNames = 7, { extended name section }
  70. wnstElemNames = 8, { extended name section }
  71. wnstDataNames = 9, { extended name section }
  72. wnstFieldNames = 10, { gc proposal }
  73. wnstTagNames = 11 { extended name section }
  74. );
  75. const
  76. WasmCustomSectionName: array [TWasmCustomSectionType] of string =
  77. ('linking',
  78. 'reloc.CODE',
  79. 'reloc.DATA',
  80. 'name',
  81. 'producers',
  82. 'target_features',
  83. '.debug_frame',
  84. '.debug_info',
  85. '.debug_line',
  86. '.debug_abbrev',
  87. '.debug_aranges',
  88. '.debug_ranges',
  89. '.debug_str',
  90. 'reloc..debug_frame',
  91. 'reloc..debug_info',
  92. 'reloc..debug_line',
  93. 'reloc..debug_abbrev',
  94. 'reloc..debug_aranges',
  95. 'reloc..debug_ranges',
  96. 'reloc..debug_str');
  97. type
  98. TWasmRelocationType = (
  99. R_WASM_FUNCTION_INDEX_LEB = 0,
  100. R_WASM_TABLE_INDEX_SLEB = 1,
  101. R_WASM_TABLE_INDEX_I32 = 2,
  102. R_WASM_MEMORY_ADDR_LEB = 3,
  103. R_WASM_MEMORY_ADDR_SLEB = 4,
  104. R_WASM_MEMORY_ADDR_I32 = 5,
  105. R_WASM_TYPE_INDEX_LEB = 6,
  106. R_WASM_GLOBAL_INDEX_LEB = 7,
  107. R_WASM_FUNCTION_OFFSET_I32 = 8,
  108. R_WASM_SECTION_OFFSET_I32 = 9,
  109. R_WASM_TAG_INDEX_LEB = 10,
  110. R_WASM_GLOBAL_INDEX_I32 = 13,
  111. R_WASM_MEMORY_ADDR_LEB64 = 14,
  112. R_WASM_MEMORY_ADDR_SLEB64 = 15,
  113. R_WASM_MEMORY_ADDR_I64 = 16,
  114. R_WASM_TABLE_INDEX_SLEB64 = 18,
  115. R_WASM_TABLE_INDEX_I64 = 19,
  116. R_WASM_TABLE_NUMBER_LEB = 20,
  117. R_WASM_FUNCTION_OFFSET_I64 = 22,
  118. R_WASM_MEMORY_ADDR_LOCREL_I32 = 23,
  119. R_WASM_TABLE_INDEX_REL_SLEB64 = 24,
  120. R_WASM_FUNCTION_INDEX_I32 = 26);
  121. TWasmLinkingSubsectionType = (
  122. WASM_SEGMENT_INFO = 5,
  123. WASM_INIT_FUNCS = 6,
  124. WASM_COMDAT_INFO = 7,
  125. WASM_SYMBOL_TABLE = 8);
  126. TWasmSymbolType = (
  127. SYMTAB_FUNCTION = 0,
  128. SYMTAB_DATA = 1,
  129. SYMTAB_GLOBAL = 2,
  130. SYMTAB_SECTION = 3,
  131. SYMTAB_EVENT = 4,
  132. SYMTAB_TABLE = 5,
  133. SYMTAB_FPC_CUSTOM = 6);
  134. const
  135. { segment flags }
  136. WASM_SEG_FLAG_STRINGS = $01;
  137. WASM_SEG_FLAG_TLS = $02;
  138. { symbol flags }
  139. WASM_SYM_BINDING_WEAK = $01;
  140. WASM_SYM_BINDING_LOCAL = $02;
  141. WASM_SYM_VISIBILITY_HIDDEN = $04;
  142. WASM_SYM_UNDEFINED = $10;
  143. WASM_SYM_EXPORTED = $20;
  144. WASM_SYM_EXPLICIT_NAME = $40;
  145. WASM_SYM_NO_STRIP = $80;
  146. WASM_SYM_TLS = $100;
  147. implementation
  148. end.