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