OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_WASM_MACRO_GEN_H_ | 5 #ifndef V8_WASM_MACRO_GEN_H_ |
6 #define V8_WASM_MACRO_GEN_H_ | 6 #define V8_WASM_MACRO_GEN_H_ |
7 | 7 |
8 #include "src/wasm/wasm-opcodes.h" | 8 #include "src/wasm/wasm-opcodes.h" |
9 | 9 |
10 // Convenience macros for building Wasm bytecode directly into a byte array. | 10 // Convenience macros for building Wasm bytecode directly into a byte array. |
(...skipping 15 matching lines...) Expand all Loading... |
26 #define WASM_BRV(depth, val) kExprBr, static_cast<byte>(depth), val | 26 #define WASM_BRV(depth, val) kExprBr, static_cast<byte>(depth), val |
27 #define WASM_BRV_IF(depth, val, cond) \ | 27 #define WASM_BRV_IF(depth, val, cond) \ |
28 kExprBrIf, static_cast<byte>(depth), val, cond | 28 kExprBrIf, static_cast<byte>(depth), val, cond |
29 #define WASM_BREAK(depth) kExprBr, static_cast<byte>(depth + 1), kExprNop | 29 #define WASM_BREAK(depth) kExprBr, static_cast<byte>(depth + 1), kExprNop |
30 #define WASM_CONTINUE(depth) kExprBr, static_cast<byte>(depth), kExprNop | 30 #define WASM_CONTINUE(depth) kExprBr, static_cast<byte>(depth), kExprNop |
31 #define WASM_BREAKV(depth, val) kExprBr, static_cast<byte>(depth + 1), val | 31 #define WASM_BREAKV(depth, val) kExprBr, static_cast<byte>(depth + 1), val |
32 #define WASM_RETURN0 kExprReturn | 32 #define WASM_RETURN0 kExprReturn |
33 #define WASM_RETURN(...) kExprReturn, __VA_ARGS__ | 33 #define WASM_RETURN(...) kExprReturn, __VA_ARGS__ |
34 #define WASM_UNREACHABLE kExprUnreachable | 34 #define WASM_UNREACHABLE kExprUnreachable |
35 | 35 |
36 #define WASM_TABLESWITCH_OP(case_count, table_count, ...) \ | 36 #define WASM_BR_TABLE(key, count, ...) \ |
37 kExprTableSwitch, static_cast<byte>(case_count), \ | 37 kExprBrTable, U16_LE(count), __VA_ARGS__, key |
38 static_cast<byte>(case_count >> 8), static_cast<byte>(table_count), \ | |
39 static_cast<byte>(table_count >> 8), __VA_ARGS__ | |
40 | |
41 #define WASM_TABLESWITCH_BODY0(key) key | |
42 | |
43 #define WASM_TABLESWITCH_BODY(key, ...) key, __VA_ARGS__ | |
44 | 38 |
45 #define WASM_CASE(x) static_cast<byte>(x), static_cast<byte>(x >> 8) | 39 #define WASM_CASE(x) static_cast<byte>(x), static_cast<byte>(x >> 8) |
46 #define WASM_CASE_BR(x) static_cast<byte>(x), static_cast<byte>(0x80 | (x) >> 8) | 40 #define WASM_CASE_BR(x) static_cast<byte>(x), static_cast<byte>(0x80 | (x) >> 8) |
47 | 41 |
48 //------------------------------------------------------------------------------ | 42 //------------------------------------------------------------------------------ |
49 // Misc expressions. | 43 // Misc expressions. |
50 //------------------------------------------------------------------------------ | 44 //------------------------------------------------------------------------------ |
51 #define WASM_ID(...) __VA_ARGS__ | 45 #define WASM_ID(...) __VA_ARGS__ |
52 #define WASM_ZERO kExprI8Const, 0 | 46 #define WASM_ZERO kExprI8Const, 0 |
53 #define WASM_ONE kExprI8Const, 1 | 47 #define WASM_ONE kExprI8Const, 1 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 static_cast<byte>(v), static_cast<byte>((v) >> 8), \ | 394 static_cast<byte>(v), static_cast<byte>((v) >> 8), \ |
401 static_cast<byte>((v) >> 16), static_cast<byte>((v) >> 24) | 395 static_cast<byte>((v) >> 16), static_cast<byte>((v) >> 24) |
402 | 396 |
403 #define U16_LE(v) static_cast<byte>(v), static_cast<byte>((v) >> 8) | 397 #define U16_LE(v) static_cast<byte>(v), static_cast<byte>((v) >> 8) |
404 | 398 |
405 #define WASM_MODULE_HEADER U32_LE(kWasmMagic), U32_LE(kWasmVersion) | 399 #define WASM_MODULE_HEADER U32_LE(kWasmMagic), U32_LE(kWasmVersion) |
406 | 400 |
407 #define SIG_INDEX(v) U16_LE(v) | 401 #define SIG_INDEX(v) U16_LE(v) |
408 #define FUNC_INDEX(v) U16_LE(v) | 402 #define FUNC_INDEX(v) U16_LE(v) |
409 #define NAME_OFFSET(v) U32_LE(v) | 403 #define NAME_OFFSET(v) U32_LE(v) |
| 404 #define BR_TARGET(v) U16_LE(v) |
410 | 405 |
411 #define MASK_7 ((1 << 7) - 1) | 406 #define MASK_7 ((1 << 7) - 1) |
412 #define MASK_14 ((1 << 14) - 1) | 407 #define MASK_14 ((1 << 14) - 1) |
413 #define MASK_21 ((1 << 21) - 1) | 408 #define MASK_21 ((1 << 21) - 1) |
414 #define MASK_28 ((1 << 28) - 1) | 409 #define MASK_28 ((1 << 28) - 1) |
415 | 410 |
416 #define U32V_1(x) static_cast<byte>(x & MASK_7) | 411 #define U32V_1(x) static_cast<byte>(x & MASK_7) |
417 #define U32V_2(x) \ | 412 #define U32V_2(x) \ |
418 static_cast<byte>((x & MASK_7) | 0x80), static_cast<byte>((x >> 7) & MASK_7) | 413 static_cast<byte>((x & MASK_7) | 0x80), static_cast<byte>((x >> 7) & MASK_7) |
419 #define U32V_3(x) \ | 414 #define U32V_3(x) \ |
420 static_cast<byte>((x & MASK_7) | 0x80), \ | 415 static_cast<byte>((x & MASK_7) | 0x80), \ |
421 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ | 416 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ |
422 static_cast<byte>((x >> 14) & MASK_7) | 417 static_cast<byte>((x >> 14) & MASK_7) |
423 #define U32V_4(x) \ | 418 #define U32V_4(x) \ |
424 static_cast<byte>((x & MASK_7) | 0x80), \ | 419 static_cast<byte>((x & MASK_7) | 0x80), \ |
425 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ | 420 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ |
426 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ | 421 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ |
427 static_cast<byte>((x >> 21) & MASK_7) | 422 static_cast<byte>((x >> 21) & MASK_7) |
428 #define U32V_5(x) \ | 423 #define U32V_5(x) \ |
429 static_cast<byte>((x & MASK_7) | 0x80), \ | 424 static_cast<byte>((x & MASK_7) | 0x80), \ |
430 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ | 425 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ |
431 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ | 426 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ |
432 static_cast<byte>(((x >> 21) & MASK_7) | 0x80), \ | 427 static_cast<byte>(((x >> 21) & MASK_7) | 0x80), \ |
433 static_cast<byte>(((x >> 28) & MASK_7)) | 428 static_cast<byte>(((x >> 28) & MASK_7)) |
434 | 429 |
435 #endif // V8_WASM_MACRO_GEN_H_ | 430 #endif // V8_WASM_MACRO_GEN_H_ |
OLD | NEW |