WasmParseTree.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Wasm
  7. {
  8. namespace WasmTypes
  9. {
  10. enum WasmType
  11. {
  12. // based on binary format encoding values
  13. Void = 0,
  14. I32 = 1,
  15. I64 = 2,
  16. F32 = 3,
  17. F64 = 4,
  18. Limit,
  19. Any
  20. };
  21. bool IsLocalType(WasmTypes::WasmType type);
  22. uint32 GetTypeByteSize(WasmType type);
  23. const char16* GetTypeName(WasmType type);
  24. }
  25. namespace ExternalKinds
  26. {
  27. enum ExternalKind
  28. {
  29. Function = 0,
  30. Table = 1,
  31. Memory = 2,
  32. Global = 3,
  33. Limit
  34. };
  35. }
  36. namespace FunctionIndexTypes
  37. {
  38. enum Type
  39. {
  40. Invalid = -1,
  41. ImportThunk,
  42. Function,
  43. Import
  44. };
  45. bool CanBeExported(Type funcType);
  46. }
  47. namespace GlobalReferenceTypes
  48. {
  49. enum Type
  50. {
  51. Invalid, Const, LocalReference, ImportedReference
  52. };
  53. }
  54. struct WasmOpCodeSignatures
  55. {
  56. #define WASM_SIGNATURE(id, nTypes, ...) static const WasmTypes::WasmType id[nTypes]; DebugOnly(static const int n##id = nTypes;)
  57. #include "WasmBinaryOpCodes.h"
  58. };
  59. enum WasmOp : byte
  60. {
  61. #define WASM_OPCODE(opname, opcode, sig, nyi) wb##opname = opcode,
  62. #include "WasmBinaryOpCodes.h"
  63. };
  64. struct WasmConstLitNode
  65. {
  66. union
  67. {
  68. float f32;
  69. double f64;
  70. int32 i32;
  71. int64 i64;
  72. };
  73. };
  74. struct WasmVarNode
  75. {
  76. uint32 num;
  77. union
  78. {
  79. LPCUTF8 exportName;
  80. };
  81. };
  82. struct WasmMemOpNode
  83. {
  84. uint32 offset;
  85. uint8 alignment;
  86. };
  87. struct WasmBrNode
  88. {
  89. uint32 depth;
  90. };
  91. struct WasmBrTableNode
  92. {
  93. uint32 numTargets;
  94. uint32* targetTable;
  95. uint32 defaultTarget;
  96. };
  97. struct WasmCallNode
  98. {
  99. uint32 num; // function id
  100. FunctionIndexTypes::Type funcType;
  101. };
  102. struct WasmBlock
  103. {
  104. WasmTypes::WasmType sig;
  105. };
  106. struct WasmNode
  107. {
  108. WasmOp op;
  109. union
  110. {
  111. WasmBlock block;
  112. WasmBrNode br;
  113. WasmBrTableNode brTable;
  114. WasmCallNode call;
  115. WasmConstLitNode cnst;
  116. WasmMemOpNode mem;
  117. WasmVarNode var;
  118. };
  119. };
  120. struct WasmExport
  121. {
  122. uint32 index;
  123. uint32 nameLength;
  124. const char16* name;
  125. ExternalKinds::ExternalKind kind;
  126. };
  127. struct WasmImport
  128. {
  129. ExternalKinds::ExternalKind kind;
  130. uint32 modNameLen;
  131. const char16* modName;
  132. uint32 importNameLen;
  133. const char16* importName;
  134. };
  135. struct CustomSection
  136. {
  137. const char16* name;
  138. charcount_t nameLength;
  139. const byte* payload;
  140. uint32 payloadSize;
  141. };
  142. }