wasmbase.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. );
  66. const
  67. WasmCustomSectionName: array [TWasmCustomSectionType] of string =
  68. ('linking',
  69. 'reloc.CODE',
  70. 'reloc.DATA',
  71. 'name',
  72. 'producers',
  73. 'target_features',
  74. '.debug_frame',
  75. '.debug_info',
  76. '.debug_line',
  77. '.debug_abbrev',
  78. '.debug_aranges',
  79. '.debug_ranges',
  80. '.debug_str',
  81. 'reloc..debug_frame',
  82. 'reloc..debug_info',
  83. 'reloc..debug_line',
  84. 'reloc..debug_abbrev',
  85. 'reloc..debug_aranges',
  86. 'reloc..debug_ranges',
  87. 'reloc..debug_str');
  88. type
  89. TWasmRelocationType = (
  90. R_WASM_FUNCTION_INDEX_LEB = 0,
  91. R_WASM_TABLE_INDEX_SLEB = 1,
  92. R_WASM_TABLE_INDEX_I32 = 2,
  93. R_WASM_MEMORY_ADDR_LEB = 3,
  94. R_WASM_MEMORY_ADDR_SLEB = 4,
  95. R_WASM_MEMORY_ADDR_I32 = 5,
  96. R_WASM_TYPE_INDEX_LEB = 6,
  97. R_WASM_GLOBAL_INDEX_LEB = 7,
  98. R_WASM_FUNCTION_OFFSET_I32 = 8,
  99. R_WASM_SECTION_OFFSET_I32 = 9,
  100. R_WASM_TAG_INDEX_LEB = 10,
  101. R_WASM_GLOBAL_INDEX_I32 = 13,
  102. R_WASM_MEMORY_ADDR_LEB64 = 14,
  103. R_WASM_MEMORY_ADDR_SLEB64 = 15,
  104. R_WASM_MEMORY_ADDR_I64 = 16,
  105. R_WASM_TABLE_INDEX_SLEB64 = 18,
  106. R_WASM_TABLE_INDEX_I64 = 19,
  107. R_WASM_TABLE_NUMBER_LEB = 20,
  108. R_WASM_FUNCTION_OFFSET_I64 = 22,
  109. R_WASM_MEMORY_ADDR_LOCREL_I32 = 23,
  110. R_WASM_TABLE_INDEX_REL_SLEB64 = 24,
  111. R_WASM_FUNCTION_INDEX_I32 = 26);
  112. TWasmLinkingSubsectionType = (
  113. WASM_SEGMENT_INFO = 5,
  114. WASM_INIT_FUNCS = 6,
  115. WASM_COMDAT_INFO = 7,
  116. WASM_SYMBOL_TABLE = 8);
  117. TWasmSymbolType = (
  118. SYMTAB_FUNCTION = 0,
  119. SYMTAB_DATA = 1,
  120. SYMTAB_GLOBAL = 2,
  121. SYMTAB_SECTION = 3,
  122. SYMTAB_EVENT = 4,
  123. SYMTAB_TABLE = 5,
  124. SYMTAB_FPC_CUSTOM = 6);
  125. const
  126. { segment flags }
  127. WASM_SEG_FLAG_STRINGS = $01;
  128. WASM_SEG_FLAG_TLS = $02;
  129. { symbol flags }
  130. WASM_SYM_BINDING_WEAK = $01;
  131. WASM_SYM_BINDING_LOCAL = $02;
  132. WASM_SYM_VISIBILITY_HIDDEN = $04;
  133. WASM_SYM_UNDEFINED = $10;
  134. WASM_SYM_EXPORTED = $20;
  135. WASM_SYM_EXPLICIT_NAME = $40;
  136. WASM_SYM_NO_STRIP = $80;
  137. WASM_SYM_TLS = $100;
  138. implementation
  139. end.