No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BurstDisassembler.Core.Wasm.cs 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using System;
  2. #if UNITY_EDITOR || BURST_INTERNAL
  3. namespace Unity.Burst.Editor
  4. {
  5. internal partial class BurstDisassembler
  6. {
  7. internal class WasmAsmTokenKindProvider : AsmTokenKindProvider
  8. {
  9. private static readonly string[] Registers = new[]
  10. {
  11. "memory.", // add . to avoid parsing instruction portion as directive
  12. "local.",
  13. "global.",
  14. "i32.",
  15. "i64.",
  16. "f32.",
  17. "f64."
  18. };
  19. private static readonly string[] Qualifiers = new[]
  20. {
  21. "offset",
  22. "align",
  23. "eqz",
  24. "eq",
  25. "ne",
  26. "lt_s",
  27. "lt_u",
  28. "gt_s",
  29. "gt_u",
  30. "le_s",
  31. "le_u",
  32. "ge_s",
  33. "ge_u",
  34. "lt",
  35. "gt",
  36. "le",
  37. "ge",
  38. };
  39. private static readonly string[] Instructions = new[]
  40. {
  41. "if",
  42. "end",
  43. "block",
  44. "end_block",
  45. "end_loop",
  46. "end_function",
  47. "loop",
  48. "unreachable",
  49. "nop",
  50. "call",
  51. "call_indirect",
  52. "drop",
  53. "select",
  54. "get",
  55. "set",
  56. "tee",
  57. "load",
  58. "load8_s",
  59. "load8_u",
  60. "load16_s",
  61. "load16_u",
  62. "load32_s",
  63. "load32_u",
  64. "store",
  65. "store8",
  66. "store16",
  67. "store32",
  68. "size",
  69. "grow",
  70. "const",
  71. "clz",
  72. "ctz",
  73. "popcnt",
  74. "add",
  75. "sub",
  76. "mul",
  77. "div_s",
  78. "div_u",
  79. "rem_s",
  80. "rem_u",
  81. "and",
  82. "or",
  83. "xor",
  84. "shl",
  85. "shr_s",
  86. "shr_u",
  87. "rotl",
  88. "rotr",
  89. "abs",
  90. "neg",
  91. "ceil",
  92. "floor",
  93. "trunc",
  94. "sqrt",
  95. "div",
  96. "min",
  97. "max",
  98. "copysign",
  99. "wrap_i64",
  100. "trunc_f32_s",
  101. "trunc_f32_u",
  102. "trunc_f64_s",
  103. "trunc_f64_u",
  104. "extend_i32_s",
  105. "extend_i32_u",
  106. "convert_i32_s",
  107. "convert_i32_u",
  108. "convert_i64_s",
  109. "convert_i64_u",
  110. "demote_f64",
  111. "promote_f32",
  112. "reinterpret_f32",
  113. "reinterpret_f64",
  114. "reinterpret_i32",
  115. "reinterpret_i64",
  116. };
  117. private static readonly string[] BranchInstructions = new string[]
  118. {
  119. "br_if",
  120. };
  121. private static readonly string[] JumpInstructions = new string[]
  122. {
  123. "br",
  124. "br_table"
  125. };
  126. private static readonly string[] ReturnInstructions = new string[]
  127. {
  128. "return",
  129. };
  130. private static readonly string[] SimdInstructions = new string[]
  131. {
  132. };
  133. private WasmAsmTokenKindProvider() : base(
  134. Registers.Length +
  135. Qualifiers.Length +
  136. Instructions.Length +
  137. BranchInstructions.Length +
  138. JumpInstructions.Length +
  139. ReturnInstructions.Length +
  140. SimdInstructions.Length)
  141. {
  142. foreach (var register in Registers)
  143. {
  144. AddTokenKind(register, AsmTokenKind.Register);
  145. }
  146. foreach (var instruction in Qualifiers)
  147. {
  148. AddTokenKind(instruction, AsmTokenKind.Qualifier);
  149. }
  150. foreach (var instruction in Instructions)
  151. {
  152. AddTokenKind(instruction, AsmTokenKind.Instruction);
  153. }
  154. foreach (var instruction in BranchInstructions)
  155. {
  156. AddTokenKind(instruction, AsmTokenKind.BranchInstruction);
  157. }
  158. foreach (var instruction in JumpInstructions)
  159. {
  160. AddTokenKind(instruction, AsmTokenKind.JumpInstruction);
  161. }
  162. foreach (var instruction in ReturnInstructions)
  163. {
  164. AddTokenKind(instruction, AsmTokenKind.ReturnInstruction);
  165. }
  166. foreach (var instruction in SimdInstructions)
  167. {
  168. AddTokenKind(instruction, AsmTokenKind.InstructionSIMD);
  169. }
  170. }
  171. public override bool AcceptsCharAsIdentifierOrRegisterEnd(char c)
  172. {
  173. return c == '.';
  174. }
  175. public override bool IsInstructionOrRegisterOrIdentifier(char c)
  176. {
  177. // Wasm should not take '.' with it as this will take register.instruction combo as one.
  178. return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_' ||
  179. c == '@';
  180. }
  181. public override SIMDkind SimdKind(StringSlice instruction)
  182. {
  183. throw new NotImplementedException("WASM does not contain any SIMD instruction.");
  184. }
  185. public static readonly WasmAsmTokenKindProvider Instance = new WasmAsmTokenKindProvider();
  186. }
  187. }
  188. }
  189. #endif