wasmbase.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. wcstDebugFrame,
  46. wcstDebugInfo,
  47. wcstDebugLine,
  48. wcstDebugAbbrev,
  49. wcstDebugAranges,
  50. wcstDebugRanges,
  51. wcstDebugStr,
  52. wcstRelocDebugFrame,
  53. wcstRelocDebugInfo,
  54. wcstRelocDebugLine,
  55. wcstRelocDebugAbbrev,
  56. wcstRelocDebugAranges,
  57. wcstRelocDebugRanges,
  58. wcstRelocDebugStr);
  59. TWasmCustomDebugSectionType = wcstDebugFrame..wcstDebugStr;
  60. const
  61. WasmCustomSectionName: array [TWasmCustomSectionType] of string =
  62. ('linking',
  63. 'reloc.CODE',
  64. 'reloc.DATA',
  65. 'producers',
  66. 'target_features',
  67. '.debug_frame',
  68. '.debug_info',
  69. '.debug_line',
  70. '.debug_abbrev',
  71. '.debug_aranges',
  72. '.debug_ranges',
  73. '.debug_str',
  74. 'reloc..debug_frame',
  75. 'reloc..debug_info',
  76. 'reloc..debug_line',
  77. 'reloc..debug_abbrev',
  78. 'reloc..debug_aranges',
  79. 'reloc..debug_ranges',
  80. 'reloc..debug_str');
  81. type
  82. TWasmRelocationType = (
  83. R_WASM_FUNCTION_INDEX_LEB = 0,
  84. R_WASM_TABLE_INDEX_SLEB = 1,
  85. R_WASM_TABLE_INDEX_I32 = 2,
  86. R_WASM_MEMORY_ADDR_LEB = 3,
  87. R_WASM_MEMORY_ADDR_SLEB = 4,
  88. R_WASM_MEMORY_ADDR_I32 = 5,
  89. R_WASM_TYPE_INDEX_LEB = 6,
  90. R_WASM_GLOBAL_INDEX_LEB = 7,
  91. R_WASM_FUNCTION_OFFSET_I32 = 8,
  92. R_WASM_SECTION_OFFSET_I32 = 9,
  93. R_WASM_TAG_INDEX_LEB = 10,
  94. R_WASM_GLOBAL_INDEX_I32 = 13,
  95. R_WASM_MEMORY_ADDR_LEB64 = 14,
  96. R_WASM_MEMORY_ADDR_SLEB64 = 15,
  97. R_WASM_MEMORY_ADDR_I64 = 16,
  98. R_WASM_TABLE_INDEX_SLEB64 = 18,
  99. R_WASM_TABLE_INDEX_I64 = 19,
  100. R_WASM_TABLE_NUMBER_LEB = 20);
  101. TWasmLinkingSubsectionType = (
  102. WASM_SEGMENT_INFO = 5,
  103. WASM_INIT_FUNCS = 6,
  104. WASM_COMDAT_INFO = 7,
  105. WASM_SYMBOL_TABLE = 8);
  106. TWasmSymbolType = (
  107. SYMTAB_FUNCTION = 0,
  108. SYMTAB_DATA = 1,
  109. SYMTAB_GLOBAL = 2,
  110. SYMTAB_SECTION = 3,
  111. SYMTAB_EVENT = 4,
  112. SYMTAB_TABLE = 5);
  113. const
  114. { segment flags }
  115. WASM_SEG_FLAG_STRINGS = $01;
  116. WASM_SEG_FLAG_TLS = $02;
  117. { symbol flags }
  118. WASM_SYM_BINDING_WEAK = $01;
  119. WASM_SYM_BINDING_LOCAL = $02;
  120. WASM_SYM_VISIBILITY_HIDDEN = $04;
  121. WASM_SYM_UNDEFINED = $10;
  122. WASM_SYM_EXPORTED = $20;
  123. WASM_SYM_EXPLICIT_NAME = $40;
  124. WASM_SYM_NO_STRIP = $80;
  125. WASM_SYM_TLS = $100;
  126. implementation
  127. end.