wasmbase.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. const
  44. WasmCustomSectionName: array [TWasmCustomSectionType] of string =
  45. ('linking',
  46. 'reloc.CODE',
  47. 'reloc.DATA');
  48. type
  49. TWasmRelocationType = (
  50. R_WASM_FUNCTION_INDEX_LEB = 0,
  51. R_WASM_TABLE_INDEX_SLEB = 1,
  52. R_WASM_TABLE_INDEX_I32 = 2,
  53. R_WASM_MEMORY_ADDR_LEB = 3,
  54. R_WASM_MEMORY_ADDR_SLEB = 4,
  55. R_WASM_MEMORY_ADDR_I32 = 5,
  56. R_WASM_TYPE_INDEX_LEB = 6,
  57. R_WASM_GLOBAL_INDEX_LEB = 7,
  58. R_WASM_FUNCTION_OFFSET_I32 = 8,
  59. R_WASM_SECTION_OFFSET_I32 = 9,
  60. R_WASM_TAG_INDEX_LEB = 10,
  61. R_WASM_GLOBAL_INDEX_I32 = 13,
  62. R_WASM_MEMORY_ADDR_LEB64 = 14,
  63. R_WASM_MEMORY_ADDR_SLEB64 = 15,
  64. R_WASM_MEMORY_ADDR_I64 = 16,
  65. R_WASM_TABLE_INDEX_SLEB64 = 18,
  66. R_WASM_TABLE_INDEX_I64 = 19,
  67. R_WASM_TABLE_NUMBER_LEB = 20);
  68. TWasmLinkingSubsectionType = (
  69. WASM_SEGMENT_INFO = 5,
  70. WASM_INIT_FUNCS = 6,
  71. WASM_COMDAT_INFO = 7,
  72. WASM_SYMBOL_TABLE = 8);
  73. TWasmSymbolType = (
  74. SYMTAB_FUNCTION = 0,
  75. SYMTAB_DATA = 1,
  76. SYMTAB_GLOBAL = 2,
  77. SYMTAB_SECTION = 3,
  78. SYMTAB_EVENT = 4,
  79. SYMTAB_TABLE = 5);
  80. const
  81. { symbol flags }
  82. WASM_SYM_BINDING_WEAK = $01;
  83. WASM_SYM_BINDING_LOCAL = $02;
  84. WASM_SYM_VISIBILITY_HIDDEN = $04;
  85. WASM_SYM_UNDEFINED = $10;
  86. WASM_SYM_EXPORTED = $20;
  87. WASM_SYM_EXPLICIT_NAME = $40;
  88. WASM_SYM_NO_STRIP = $80;
  89. implementation
  90. end.