Line data Source code
1 : // Copyright 2015 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "src/wasm/wasm-opcodes.h"
6 : #include "src/messages.h"
7 : #include "src/runtime/runtime.h"
8 : #include "src/signature.h"
9 :
10 : namespace v8 {
11 : namespace internal {
12 : namespace wasm {
13 :
14 : #define CASE_OP(name, str) \
15 : case kExpr##name: \
16 : return str;
17 : #define CASE_I32_OP(name, str) CASE_OP(I32##name, "i32." str)
18 : #define CASE_I64_OP(name, str) CASE_OP(I64##name, "i64." str)
19 : #define CASE_F32_OP(name, str) CASE_OP(F32##name, "f32." str)
20 : #define CASE_F64_OP(name, str) CASE_OP(F64##name, "f64." str)
21 : #define CASE_F32x4_OP(name, str) CASE_OP(F32x4##name, "f32x4." str)
22 : #define CASE_I32x4_OP(name, str) CASE_OP(I32x4##name, "i32x4." str)
23 : #define CASE_I16x8_OP(name, str) CASE_OP(I16x8##name, "i16x8." str)
24 : #define CASE_I8x16_OP(name, str) CASE_OP(I8x16##name, "i8x16." str)
25 : #define CASE_S128_OP(name, str) CASE_OP(S128##name, "s128." str)
26 : #define CASE_S32x4_OP(name, str) CASE_OP(S32x4##name, "s32x4." str)
27 : #define CASE_S16x8_OP(name, str) CASE_OP(S16x8##name, "s16x8." str)
28 : #define CASE_S8x16_OP(name, str) CASE_OP(S8x16##name, "s8x16." str)
29 : #define CASE_S1x4_OP(name, str) CASE_OP(S1x4##name, "s1x4." str)
30 : #define CASE_S1x8_OP(name, str) CASE_OP(S1x8##name, "s1x8." str)
31 : #define CASE_S1x16_OP(name, str) CASE_OP(S1x16##name, "s1x16." str)
32 : #define CASE_INT_OP(name, str) CASE_I32_OP(name, str) CASE_I64_OP(name, str)
33 : #define CASE_FLOAT_OP(name, str) CASE_F32_OP(name, str) CASE_F64_OP(name, str)
34 : #define CASE_ALL_OP(name, str) CASE_FLOAT_OP(name, str) CASE_INT_OP(name, str)
35 : #define CASE_SIMD_OP(name, str) \
36 : CASE_F32x4_OP(name, str) CASE_I32x4_OP(name, str) CASE_I16x8_OP(name, str) \
37 : CASE_I8x16_OP(name, str)
38 : #define CASE_SIMDI_OP(name, str) \
39 : CASE_I32x4_OP(name, str) CASE_I16x8_OP(name, str) CASE_I8x16_OP(name, str)
40 : #define CASE_SIGN_OP(TYPE, name, str) \
41 : CASE_##TYPE##_OP(name##S, str "_s") CASE_##TYPE##_OP(name##U, str "_u")
42 : #define CASE_ALL_SIGN_OP(name, str) \
43 : CASE_FLOAT_OP(name, str) CASE_SIGN_OP(INT, name, str)
44 : #define CASE_CONVERT_OP(name, RES, SRC, src_suffix, str) \
45 : CASE_##RES##_OP(U##name##SRC, str "_u/" src_suffix) \
46 : CASE_##RES##_OP(S##name##SRC, str "_s/" src_suffix)
47 : #define CASE_L32_OP(name, str) \
48 : CASE_SIGN_OP(I32, name##8, str "8") \
49 : CASE_SIGN_OP(I32, name##16, str "16") \
50 : CASE_I32_OP(name, str "32")
51 :
52 21849 : const char* WasmOpcodes::OpcodeName(WasmOpcode opcode) {
53 21849 : switch (opcode) {
54 : // clang-format off
55 :
56 : // Standard opcodes
57 13 : CASE_INT_OP(Eqz, "eqz")
58 121 : CASE_ALL_OP(Eq, "eq")
59 61 : CASE_ALL_OP(Ne, "ne")
60 121 : CASE_ALL_OP(Add, "add")
61 121 : CASE_ALL_OP(Sub, "sub")
62 121 : CASE_ALL_OP(Mul, "mul")
63 121 : CASE_ALL_SIGN_OP(Lt, "lt")
64 61 : CASE_ALL_SIGN_OP(Gt, "gt")
65 121 : CASE_ALL_SIGN_OP(Le, "le")
66 61 : CASE_ALL_SIGN_OP(Ge, "ge")
67 13 : CASE_INT_OP(Clz, "clz")
68 13 : CASE_INT_OP(Ctz, "ctz")
69 13 : CASE_INT_OP(Popcnt, "popcnt")
70 121 : CASE_ALL_SIGN_OP(Div, "div")
71 124 : CASE_SIGN_OP(INT, Rem, "rem")
72 125 : CASE_INT_OP(And, "and")
73 124 : CASE_INT_OP(Ior, "or")
74 124 : CASE_INT_OP(Xor, "xor")
75 124 : CASE_INT_OP(Shl, "shl")
76 124 : CASE_SIGN_OP(INT, Shr, "shr")
77 61 : CASE_INT_OP(Rol, "rol")
78 61 : CASE_INT_OP(Ror, "ror")
79 13 : CASE_FLOAT_OP(Abs, "abs")
80 13 : CASE_FLOAT_OP(Neg, "neg")
81 13 : CASE_FLOAT_OP(Ceil, "ceil")
82 13 : CASE_FLOAT_OP(Floor, "floor")
83 13 : CASE_FLOAT_OP(Trunc, "trunc")
84 13 : CASE_FLOAT_OP(NearestInt, "nearest")
85 13 : CASE_FLOAT_OP(Sqrt, "sqrt")
86 61 : CASE_FLOAT_OP(Min, "min")
87 61 : CASE_FLOAT_OP(Max, "max")
88 61 : CASE_FLOAT_OP(CopySign, "copysign")
89 13 : CASE_I32_OP(ConvertI64, "wrap/i64")
90 25 : CASE_CONVERT_OP(Convert, INT, F32, "f32", "trunc")
91 25 : CASE_CONVERT_OP(Convert, INT, F64, "f64", "trunc")
92 13 : CASE_CONVERT_OP(Convert, I64, I32, "i32", "extend")
93 25 : CASE_CONVERT_OP(Convert, F32, I32, "i32", "convert")
94 13 : CASE_CONVERT_OP(Convert, F32, I64, "i64", "convert")
95 25 : CASE_F32_OP(ConvertF64, "demote/f64")
96 25 : CASE_CONVERT_OP(Convert, F64, I32, "i32", "convert")
97 13 : CASE_CONVERT_OP(Convert, F64, I64, "i64", "convert")
98 25 : CASE_F64_OP(ConvertF32, "promote/f32")
99 13 : CASE_I32_OP(ReinterpretF32, "reinterpret/f32")
100 13 : CASE_I64_OP(ReinterpretF64, "reinterpret/f64")
101 13 : CASE_F32_OP(ReinterpretI32, "reinterpret/i32")
102 13 : CASE_F64_OP(ReinterpretI64, "reinterpret/i64")
103 1 : CASE_OP(Unreachable, "unreachable")
104 45 : CASE_OP(Nop, "nop")
105 25 : CASE_OP(Block, "block")
106 7 : CASE_OP(Loop, "loop")
107 23 : CASE_OP(If, "if")
108 1 : CASE_OP(Else, "else")
109 1 : CASE_OP(End, "end")
110 7 : CASE_OP(Br, "br")
111 13 : CASE_OP(BrIf, "br_if")
112 2 : CASE_OP(BrTable, "br_table")
113 19 : CASE_OP(Return, "return")
114 37 : CASE_OP(CallFunction, "call")
115 1 : CASE_OP(CallIndirect, "call_indirect")
116 7 : CASE_OP(Drop, "drop")
117 17 : CASE_OP(Select, "select")
118 12532 : CASE_OP(GetLocal, "get_local")
119 17 : CASE_OP(SetLocal, "set_local")
120 3 : CASE_OP(TeeLocal, "tee_local")
121 1 : CASE_OP(GetGlobal, "get_global")
122 17 : CASE_OP(SetGlobal, "set_global")
123 186 : CASE_ALL_OP(Const, "const")
124 1 : CASE_OP(MemorySize, "current_memory")
125 2 : CASE_OP(GrowMemory, "grow_memory")
126 1 : CASE_ALL_OP(LoadMem, "load")
127 1 : CASE_SIGN_OP(INT, LoadMem8, "load8")
128 1 : CASE_SIGN_OP(INT, LoadMem16, "load16")
129 1 : CASE_SIGN_OP(I64, LoadMem32, "load32")
130 1 : CASE_S128_OP(LoadMem, "load128")
131 4 : CASE_ALL_OP(StoreMem, "store")
132 7 : CASE_INT_OP(StoreMem8, "store8")
133 7 : CASE_INT_OP(StoreMem16, "store16")
134 1 : CASE_I64_OP(StoreMem32, "store32")
135 1 : CASE_S128_OP(StoreMem, "store128")
136 :
137 : // Non-standard opcodes.
138 1 : CASE_OP(Try, "try")
139 4 : CASE_OP(Throw, "throw")
140 1 : CASE_OP(Catch, "catch")
141 :
142 : // asm.js-only opcodes.
143 13 : CASE_F64_OP(Acos, "acos")
144 13 : CASE_F64_OP(Asin, "asin")
145 13 : CASE_F64_OP(Atan, "atan")
146 13 : CASE_F64_OP(Cos, "cos")
147 13 : CASE_F64_OP(Sin, "sin")
148 13 : CASE_F64_OP(Tan, "tan")
149 13 : CASE_F64_OP(Exp, "exp")
150 13 : CASE_F64_OP(Log, "log")
151 61 : CASE_F64_OP(Atan2, "atan2")
152 61 : CASE_F64_OP(Pow, "pow")
153 61 : CASE_F64_OP(Mod, "mod")
154 13 : CASE_F32_OP(AsmjsLoadMem, "asmjs_load")
155 13 : CASE_F64_OP(AsmjsLoadMem, "asmjs_load")
156 13 : CASE_L32_OP(AsmjsLoadMem, "asmjs_load")
157 61 : CASE_I32_OP(AsmjsStoreMem, "asmjs_store")
158 61 : CASE_F32_OP(AsmjsStoreMem, "asmjs_store")
159 61 : CASE_F64_OP(AsmjsStoreMem, "asmjs_store")
160 61 : CASE_I32_OP(AsmjsStoreMem8, "asmjs_store8")
161 61 : CASE_I32_OP(AsmjsStoreMem16, "asmjs_store16")
162 61 : CASE_SIGN_OP(I32, AsmjsDiv, "asmjs_div")
163 61 : CASE_SIGN_OP(I32, AsmjsRem, "asmjs_rem")
164 13 : CASE_I32_OP(AsmjsSConvertF32, "asmjs_convert_s/f32")
165 13 : CASE_I32_OP(AsmjsUConvertF32, "asmjs_convert_u/f32")
166 13 : CASE_I32_OP(AsmjsSConvertF64, "asmjs_convert_s/f64")
167 13 : CASE_I32_OP(AsmjsUConvertF64, "asmjs_convert_u/f64")
168 :
169 : // SIMD opcodes.
170 1 : CASE_SIMD_OP(Splat, "splat")
171 1 : CASE_SIMD_OP(Neg, "neg")
172 1 : CASE_SIMD_OP(Eq, "eq")
173 1 : CASE_SIMD_OP(Ne, "ne")
174 1 : CASE_SIMD_OP(Add, "add")
175 1 : CASE_SIMD_OP(Sub, "sub")
176 1 : CASE_SIMD_OP(Mul, "mul")
177 1 : CASE_F32x4_OP(Abs, "abs")
178 1 : CASE_F32x4_OP(AddHoriz, "add_horizontal")
179 1 : CASE_F32x4_OP(RecipApprox, "recip_approx")
180 1 : CASE_F32x4_OP(RecipSqrtApprox, "recip_sqrt_approx")
181 1 : CASE_F32x4_OP(Min, "min")
182 1 : CASE_F32x4_OP(Max, "max")
183 1 : CASE_F32x4_OP(Lt, "lt")
184 1 : CASE_F32x4_OP(Le, "le")
185 1 : CASE_F32x4_OP(Gt, "gt")
186 1 : CASE_F32x4_OP(Ge, "ge")
187 1 : CASE_CONVERT_OP(Convert, F32x4, I32x4, "i32", "convert")
188 1 : CASE_CONVERT_OP(Convert, I32x4, F32x4, "f32", "convert")
189 1 : CASE_CONVERT_OP(Convert, I32x4, I16x8Low, "i32", "convert")
190 1 : CASE_CONVERT_OP(Convert, I32x4, I16x8High, "i32", "convert")
191 1 : CASE_CONVERT_OP(Convert, I16x8, I32x4, "i32", "convert")
192 1 : CASE_CONVERT_OP(Convert, I16x8, I8x16Low, "i32", "convert")
193 1 : CASE_CONVERT_OP(Convert, I16x8, I8x16High, "i32", "convert")
194 1 : CASE_CONVERT_OP(Convert, I8x16, I16x8, "i32", "convert")
195 1 : CASE_F32x4_OP(ExtractLane, "extract_lane")
196 1 : CASE_F32x4_OP(ReplaceLane, "replace_lane")
197 1 : CASE_SIMDI_OP(ExtractLane, "extract_lane")
198 1 : CASE_SIMDI_OP(ReplaceLane, "replace_lane")
199 1 : CASE_SIGN_OP(SIMDI, Min, "min")
200 1 : CASE_SIGN_OP(SIMDI, Max, "max")
201 1 : CASE_SIGN_OP(SIMDI, Lt, "lt")
202 1 : CASE_SIGN_OP(SIMDI, Le, "le")
203 1 : CASE_SIGN_OP(SIMDI, Gt, "gt")
204 1 : CASE_SIGN_OP(SIMDI, Ge, "ge")
205 1 : CASE_SIGN_OP(SIMDI, Shr, "shr")
206 1 : CASE_SIMDI_OP(Shl, "shl")
207 1 : CASE_I32x4_OP(AddHoriz, "add_horizontal")
208 1 : CASE_I16x8_OP(AddHoriz, "add_horizontal")
209 1 : CASE_SIGN_OP(I16x8, AddSaturate, "add_saturate")
210 1 : CASE_SIGN_OP(I8x16, AddSaturate, "add_saturate")
211 1 : CASE_SIGN_OP(I16x8, SubSaturate, "sub_saturate")
212 1 : CASE_SIGN_OP(I8x16, SubSaturate, "sub_saturate")
213 1 : CASE_S128_OP(And, "and")
214 1 : CASE_S128_OP(Or, "or")
215 1 : CASE_S128_OP(Xor, "xor")
216 1 : CASE_S128_OP(Not, "not")
217 1 : CASE_S32x4_OP(ZipLeft, "zip left")
218 1 : CASE_S32x4_OP(ZipRight, "zip right")
219 1 : CASE_S32x4_OP(UnzipLeft, "unzip left")
220 1 : CASE_S32x4_OP(UnzipRight, "unzip right")
221 1 : CASE_S32x4_OP(TransposeLeft, "transpose left")
222 1 : CASE_S32x4_OP(TransposeRight, "transpose right")
223 1 : CASE_S32x4_OP(Select, "select")
224 1 : CASE_S16x8_OP(ZipLeft, "zip left")
225 1 : CASE_S16x8_OP(ZipRight, "zip right")
226 1 : CASE_S16x8_OP(UnzipLeft, "unzip left")
227 1 : CASE_S16x8_OP(UnzipRight, "unzip right")
228 1 : CASE_S16x8_OP(TransposeLeft, "transpose left")
229 1 : CASE_S16x8_OP(TransposeRight, "transpose right")
230 1 : CASE_S16x8_OP(Select, "select")
231 1 : CASE_S8x16_OP(ZipLeft, "zip left")
232 1 : CASE_S8x16_OP(ZipRight, "zip right")
233 1 : CASE_S8x16_OP(UnzipLeft, "unzip left")
234 1 : CASE_S8x16_OP(UnzipRight, "unzip right")
235 1 : CASE_S8x16_OP(TransposeLeft, "transpose left")
236 1 : CASE_S8x16_OP(TransposeRight, "transpose right")
237 1 : CASE_S8x16_OP(Select, "select")
238 1 : CASE_S8x16_OP(Concat, "concat")
239 1 : CASE_OP(S32x2Reverse, "32x2 reverse")
240 1 : CASE_OP(S16x4Reverse, "16x4 reverse")
241 1 : CASE_OP(S16x2Reverse, "16x2 reverse")
242 1 : CASE_OP(S8x8Reverse, "8x8 reverse")
243 1 : CASE_OP(S8x4Reverse, "8x4 reverse")
244 1 : CASE_OP(S8x2Reverse, "8x2 reverse")
245 1 : CASE_S1x4_OP(And, "and")
246 1 : CASE_S1x4_OP(Or, "or")
247 1 : CASE_S1x4_OP(Xor, "xor")
248 1 : CASE_S1x4_OP(Not, "not")
249 1 : CASE_S1x4_OP(AnyTrue, "any_true")
250 1 : CASE_S1x4_OP(AllTrue, "all_true")
251 1 : CASE_S1x8_OP(And, "and")
252 1 : CASE_S1x8_OP(Or, "or")
253 1 : CASE_S1x8_OP(Xor, "xor")
254 1 : CASE_S1x8_OP(Not, "not")
255 1 : CASE_S1x8_OP(AnyTrue, "any_true")
256 1 : CASE_S1x8_OP(AllTrue, "all_true")
257 1 : CASE_S1x16_OP(And, "and")
258 1 : CASE_S1x16_OP(Or, "or")
259 1 : CASE_S1x16_OP(Xor, "xor")
260 1 : CASE_S1x16_OP(Not, "not")
261 1 : CASE_S1x16_OP(AnyTrue, "any_true")
262 1 : CASE_S1x16_OP(AllTrue, "all_true")
263 :
264 : // Atomic operations.
265 1 : CASE_L32_OP(AtomicAdd, "atomic_add")
266 1 : CASE_L32_OP(AtomicAnd, "atomic_and")
267 1 : CASE_L32_OP(AtomicCompareExchange, "atomic_cmpxchng")
268 1 : CASE_L32_OP(AtomicExchange, "atomic_xchng")
269 1 : CASE_L32_OP(AtomicOr, "atomic_or")
270 1 : CASE_L32_OP(AtomicSub, "atomic_sub")
271 1 : CASE_L32_OP(AtomicXor, "atomic_xor")
272 :
273 0 : default : return "unknown";
274 : // clang-format on
275 : }
276 : }
277 :
278 0 : bool WasmOpcodes::IsPrefixOpcode(WasmOpcode opcode) {
279 0 : switch (opcode) {
280 : #define CHECK_PREFIX(name, opcode) \
281 : case k##name##Prefix: \
282 : return true;
283 : FOREACH_PREFIX(CHECK_PREFIX)
284 : #undef CHECK_PREFIX
285 : default:
286 0 : return false;
287 : }
288 : }
289 0 : bool WasmOpcodes::IsControlOpcode(WasmOpcode opcode) {
290 0 : switch (opcode) {
291 : #define CHECK_OPCODE(name, opcode, _) \
292 : case kExpr##name: \
293 : return true;
294 : FOREACH_CONTROL_OPCODE(CHECK_OPCODE)
295 : #undef CHECK_OPCODE
296 : default:
297 0 : return false;
298 : }
299 : }
300 :
301 0 : std::ostream& operator<<(std::ostream& os, const FunctionSig& sig) {
302 0 : if (sig.return_count() == 0) os << "v";
303 0 : for (auto ret : sig.returns()) {
304 : os << WasmOpcodes::ShortNameOf(ret);
305 : }
306 0 : os << "_";
307 0 : if (sig.parameter_count() == 0) os << "v";
308 0 : for (auto param : sig.parameters()) {
309 : os << WasmOpcodes::ShortNameOf(param);
310 : }
311 0 : return os;
312 : }
313 :
314 66272 : bool IsJSCompatibleSignature(const FunctionSig* sig) {
315 199796 : for (auto type : sig->all()) {
316 133692 : if (type == wasm::kWasmI64 || type == wasm::kWasmS128) return false;
317 : }
318 : return true;
319 : }
320 :
321 : #define DECLARE_SIG_ENUM(name, ...) kSigEnum_##name,
322 :
323 : enum WasmOpcodeSig { FOREACH_SIGNATURE(DECLARE_SIG_ENUM) };
324 :
325 : // TODO(titzer): not static-initializer safe. Wrap in LazyInstance.
326 : #define DECLARE_SIG(name, ...) \
327 : static ValueType kTypes_##name[] = {__VA_ARGS__}; \
328 : static const FunctionSig kSig_##name( \
329 : 1, static_cast<int>(arraysize(kTypes_##name)) - 1, kTypes_##name);
330 :
331 : FOREACH_SIGNATURE(DECLARE_SIG)
332 :
333 : #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name,
334 :
335 : static const FunctionSig* kSimpleExprSigs[] = {
336 : nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)};
337 :
338 : #define DECLARE_SIMD_SIG_ENTRY(name, ...) &kSig_##name,
339 :
340 : static const FunctionSig* kSimdExprSigs[] = {
341 : nullptr, FOREACH_SIMD_SIGNATURE(DECLARE_SIMD_SIG_ENTRY)};
342 :
343 : static byte kSimpleExprSigTable[256];
344 : static byte kSimpleAsmjsExprSigTable[256];
345 : static byte kSimdExprSigTable[256];
346 : static byte kAtomicExprSigTable[256];
347 :
348 : // Initialize the signature table.
349 7242 : static void InitSigTables() {
350 : #define SET_SIG_TABLE(name, opcode, sig) \
351 : kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1;
352 7242 : FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE);
353 : #undef SET_SIG_TABLE
354 : #define SET_ASMJS_SIG_TABLE(name, opcode, sig) \
355 : kSimpleAsmjsExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1;
356 7242 : FOREACH_ASMJS_COMPAT_OPCODE(SET_ASMJS_SIG_TABLE);
357 : #undef SET_ASMJS_SIG_TABLE
358 : byte simd_index;
359 : #define SET_SIG_TABLE(name, opcode, sig) \
360 : simd_index = opcode & 0xff; \
361 : kSimdExprSigTable[simd_index] = static_cast<int>(kSigEnum_##sig) + 1;
362 7242 : FOREACH_SIMD_0_OPERAND_OPCODE(SET_SIG_TABLE)
363 : #undef SET_SIG_TABLE
364 : byte atomic_index;
365 : #define SET_ATOMIC_SIG_TABLE(name, opcode, sig) \
366 : atomic_index = opcode & 0xff; \
367 : kAtomicExprSigTable[atomic_index] = static_cast<int>(kSigEnum_##sig) + 1;
368 7242 : FOREACH_ATOMIC_OPCODE(SET_ATOMIC_SIG_TABLE)
369 : #undef SET_ATOMIC_SIG_TABLE
370 7242 : }
371 :
372 : class SigTable {
373 : public:
374 : SigTable() {
375 : // TODO(ahaas): Move {InitSigTable} into the class.
376 7242 : InitSigTables();
377 : }
378 : FunctionSig* Signature(WasmOpcode opcode) const {
379 : return const_cast<FunctionSig*>(
380 2730975 : kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]);
381 : }
382 : FunctionSig* AsmjsSignature(WasmOpcode opcode) const {
383 : return const_cast<FunctionSig*>(
384 351530 : kSimpleExprSigs[kSimpleAsmjsExprSigTable[static_cast<byte>(opcode)]]);
385 : }
386 : FunctionSig* SimdSignature(WasmOpcode opcode) const {
387 : return const_cast<FunctionSig*>(
388 1029 : kSimdExprSigs[kSimdExprSigTable[static_cast<byte>(opcode & 0xff)]]);
389 : }
390 : FunctionSig* AtomicSignature(WasmOpcode opcode) const {
391 : return const_cast<FunctionSig*>(
392 0 : kSimpleExprSigs[kAtomicExprSigTable[static_cast<byte>(opcode & 0xff)]]);
393 : }
394 : };
395 :
396 : static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER;
397 :
398 2731966 : FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) {
399 2731966 : if (opcode >> 8 == kSimdPrefix) {
400 1029 : return sig_table.Get().SimdSignature(opcode);
401 : } else {
402 2730975 : return sig_table.Get().Signature(opcode);
403 : }
404 : }
405 :
406 351530 : FunctionSig* WasmOpcodes::AsmjsSignature(WasmOpcode opcode) {
407 351530 : return sig_table.Get().AsmjsSignature(opcode);
408 : }
409 :
410 0 : FunctionSig* WasmOpcodes::AtomicSignature(WasmOpcode opcode) {
411 0 : return sig_table.Get().AtomicSignature(opcode);
412 : }
413 :
414 : // TODO(titzer): pull WASM_64 up to a common header.
415 : #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64
416 : #define WASM_64 1
417 : #else
418 : #define WASM_64 0
419 : #endif
420 :
421 2114 : int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) {
422 2114 : switch (reason) {
423 : #define TRAPREASON_TO_MESSAGE(name) \
424 : case k##name: \
425 : return MessageTemplate::kWasm##name;
426 : FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE)
427 : #undef TRAPREASON_TO_MESSAGE
428 : default:
429 : return MessageTemplate::kNone;
430 : }
431 : }
432 :
433 0 : const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) {
434 0 : return MessageTemplate::TemplateString(TrapReasonToMessageId(reason));
435 : }
436 : } // namespace wasm
437 : } // namespace internal
438 178401 : } // namespace v8
|