Chromium Code Reviews| 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. |
| 11 | 11 |
| 12 #define U32_LE(v) \ | |
| 13 static_cast<byte>(v), static_cast<byte>((v) >> 8), \ | |
| 14 static_cast<byte>((v) >> 16), static_cast<byte>((v) >> 24) | |
| 15 | |
| 16 #define U16_LE(v) static_cast<byte>(v), static_cast<byte>((v) >> 8) | |
| 17 | |
| 18 #define WASM_MODULE_HEADER U32_LE(kWasmMagic), U32_LE(kWasmVersion) | |
|
rossberg
2016/03/04 14:25:22
Nit: perhaps move the concrete index macros to a s
| |
| 19 | |
| 20 #define SIG_INDEX(v) U16_LE(v) | |
| 21 #define FUNC_INDEX(v) U16_LE(v) | |
| 22 #define NAME_OFFSET(v) U32_LE(v) | |
| 23 #define BR_TARGET(v) U16_LE(v) | |
| 24 | |
| 25 #define MASK_7 ((1 << 7) - 1) | |
| 26 #define MASK_14 ((1 << 14) - 1) | |
| 27 #define MASK_21 ((1 << 21) - 1) | |
| 28 #define MASK_28 ((1 << 28) - 1) | |
| 29 | |
| 30 #define U32V_1(x) static_cast<byte>(x & MASK_7) | |
|
bradn
2016/03/03 18:08:23
Maybe the leb stuff should go in its own header? (
| |
| 31 #define U32V_2(x) \ | |
| 32 static_cast<byte>((x & MASK_7) | 0x80), static_cast<byte>((x >> 7) & MASK_7) | |
| 33 #define U32V_3(x) \ | |
| 34 static_cast<byte>((x & MASK_7) | 0x80), \ | |
| 35 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ | |
| 36 static_cast<byte>((x >> 14) & MASK_7) | |
| 37 #define U32V_4(x) \ | |
| 38 static_cast<byte>((x & MASK_7) | 0x80), \ | |
| 39 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ | |
| 40 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ | |
| 41 static_cast<byte>((x >> 21) & MASK_7) | |
| 42 #define U32V_5(x) \ | |
| 43 static_cast<byte>((x & MASK_7) | 0x80), \ | |
| 44 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ | |
| 45 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ | |
| 46 static_cast<byte>(((x >> 21) & MASK_7) | 0x80), \ | |
| 47 static_cast<byte>((x >> 28) & 0xF) | |
| 48 | |
| 12 //------------------------------------------------------------------------------ | 49 //------------------------------------------------------------------------------ |
| 13 // Control. | 50 // Control. |
| 14 //------------------------------------------------------------------------------ | 51 //------------------------------------------------------------------------------ |
| 15 #define WASM_NOP kExprNop | 52 #define WASM_NOP kExprNop |
| 16 | 53 |
| 17 #define WASM_BLOCK(count, ...) kExprBlock, static_cast<byte>(count), __VA_ARGS__ | 54 #define WASM_BLOCK(count, ...) kExprBlock, static_cast<byte>(count), __VA_ARGS__ |
| 18 #define WASM_INFINITE_LOOP kExprLoop, 1, kExprBr, 0, kExprNop | 55 #define WASM_INFINITE_LOOP kExprLoop, 1, kExprBr, 0, kExprNop |
| 19 #define WASM_LOOP(count, ...) kExprLoop, static_cast<byte>(count), __VA_ARGS__ | 56 #define WASM_LOOP(count, ...) kExprLoop, static_cast<byte>(count), __VA_ARGS__ |
| 20 #define WASM_IF(cond, tstmt) kExprIf, cond, tstmt | 57 #define WASM_IF(cond, tstmt) kExprIf, cond, tstmt |
| 21 #define WASM_IF_ELSE(cond, tstmt, fstmt) kExprIfElse, cond, tstmt, fstmt | 58 #define WASM_IF_ELSE(cond, tstmt, fstmt) kExprIfElse, cond, tstmt, fstmt |
| 22 #define WASM_SELECT(cond, tval, fval) kExprSelect, cond, tval, fval | 59 #define WASM_SELECT(cond, tval, fval) kExprSelect, cond, tval, fval |
| 23 #define WASM_BR(depth) kExprBr, static_cast<byte>(depth), kExprNop | 60 #define WASM_BR(depth) kExprBr, static_cast<byte>(depth), kExprNop |
| 24 #define WASM_BR_IF(depth, cond) \ | 61 #define WASM_BR_IF(depth, cond) \ |
| 25 kExprBrIf, static_cast<byte>(depth), kExprNop, cond | 62 kExprBrIf, static_cast<byte>(depth), kExprNop, cond |
| 26 #define WASM_BRV(depth, val) kExprBr, static_cast<byte>(depth), val | 63 #define WASM_BRV(depth, val) kExprBr, static_cast<byte>(depth), val |
| 27 #define WASM_BRV_IF(depth, val, cond) \ | 64 #define WASM_BRV_IF(depth, val, cond) \ |
| 28 kExprBrIf, static_cast<byte>(depth), val, cond | 65 kExprBrIf, static_cast<byte>(depth), val, cond |
| 29 #define WASM_BREAK(depth) kExprBr, static_cast<byte>(depth + 1), kExprNop | 66 #define WASM_BREAK(depth) kExprBr, static_cast<byte>(depth + 1), kExprNop |
| 30 #define WASM_CONTINUE(depth) kExprBr, static_cast<byte>(depth), kExprNop | 67 #define WASM_CONTINUE(depth) kExprBr, static_cast<byte>(depth), kExprNop |
| 31 #define WASM_BREAKV(depth, val) kExprBr, static_cast<byte>(depth + 1), val | 68 #define WASM_BREAKV(depth, val) kExprBr, static_cast<byte>(depth + 1), val |
| 32 #define WASM_RETURN0 kExprReturn | 69 #define WASM_RETURN0 kExprReturn |
| 33 #define WASM_RETURN(...) kExprReturn, __VA_ARGS__ | 70 #define WASM_RETURN(...) kExprReturn, __VA_ARGS__ |
| 34 #define WASM_UNREACHABLE kExprUnreachable | 71 #define WASM_UNREACHABLE kExprUnreachable |
| 35 | 72 |
| 36 #define WASM_TABLESWITCH_OP(case_count, table_count, ...) \ | 73 #define WASM_BR_TABLE(key, count, ...) \ |
| 37 kExprTableSwitch, static_cast<byte>(case_count), \ | 74 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 | |
| 45 #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) | |
| 47 | 75 |
| 48 //------------------------------------------------------------------------------ | 76 //------------------------------------------------------------------------------ |
| 49 // Misc expressions. | 77 // Misc expressions. |
| 50 //------------------------------------------------------------------------------ | 78 //------------------------------------------------------------------------------ |
| 51 #define WASM_ID(...) __VA_ARGS__ | 79 #define WASM_ID(...) __VA_ARGS__ |
| 52 #define WASM_ZERO kExprI8Const, 0 | 80 #define WASM_ZERO kExprI8Const, 0 |
| 53 #define WASM_ONE kExprI8Const, 1 | 81 #define WASM_ONE kExprI8Const, 1 |
| 54 #define WASM_I8(val) kExprI8Const, static_cast<byte>(val) | 82 #define WASM_I8(val) kExprI8Const, static_cast<byte>(val) |
| 55 #define WASM_I32(val) \ | 83 #define WASM_I32(val) \ |
| 56 kExprI32Const, static_cast<byte>(val), static_cast<byte>(val >> 8), \ | 84 kExprI32Const, static_cast<byte>(val), static_cast<byte>(val >> 8), \ |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 #define WASM_F32_REINTERPRET_I32(x) kExprF32ReinterpretI32, x | 286 #define WASM_F32_REINTERPRET_I32(x) kExprF32ReinterpretI32, x |
| 259 #define WASM_F64_SCONVERT_I32(x) kExprF64SConvertI32, x | 287 #define WASM_F64_SCONVERT_I32(x) kExprF64SConvertI32, x |
| 260 #define WASM_F64_UCONVERT_I32(x) kExprF64UConvertI32, x | 288 #define WASM_F64_UCONVERT_I32(x) kExprF64UConvertI32, x |
| 261 #define WASM_F64_SCONVERT_I64(x) kExprF64SConvertI64, x | 289 #define WASM_F64_SCONVERT_I64(x) kExprF64SConvertI64, x |
| 262 #define WASM_F64_UCONVERT_I64(x) kExprF64UConvertI64, x | 290 #define WASM_F64_UCONVERT_I64(x) kExprF64UConvertI64, x |
| 263 #define WASM_F64_CONVERT_F32(x) kExprF64ConvertF32, x | 291 #define WASM_F64_CONVERT_F32(x) kExprF64ConvertF32, x |
| 264 #define WASM_F64_REINTERPRET_I64(x) kExprF64ReinterpretI64, x | 292 #define WASM_F64_REINTERPRET_I64(x) kExprF64ReinterpretI64, x |
| 265 #define WASM_I32_REINTERPRET_F32(x) kExprI32ReinterpretF32, x | 293 #define WASM_I32_REINTERPRET_F32(x) kExprI32ReinterpretF32, x |
| 266 #define WASM_I64_REINTERPRET_F64(x) kExprI64ReinterpretF64, x | 294 #define WASM_I64_REINTERPRET_F64(x) kExprI64ReinterpretF64, x |
| 267 | 295 |
| 268 #define U32_LE(v) \ | |
| 269 static_cast<byte>(v), static_cast<byte>((v) >> 8), \ | |
| 270 static_cast<byte>((v) >> 16), static_cast<byte>((v) >> 24) | |
| 271 | |
| 272 #define U16_LE(v) static_cast<byte>(v), static_cast<byte>((v) >> 8) | |
| 273 | |
| 274 #define WASM_MODULE_HEADER U32_LE(kWasmMagic), U32_LE(kWasmVersion) | |
| 275 | |
| 276 #define SIG_INDEX(v) U16_LE(v) | |
| 277 #define FUNC_INDEX(v) U16_LE(v) | |
| 278 #define NAME_OFFSET(v) U32_LE(v) | |
| 279 | |
| 280 #define MASK_7 ((1 << 7) - 1) | |
| 281 #define MASK_14 ((1 << 14) - 1) | |
| 282 #define MASK_21 ((1 << 21) - 1) | |
| 283 #define MASK_28 ((1 << 28) - 1) | |
| 284 | |
| 285 #define U32V_1(x) static_cast<byte>(x & MASK_7) | |
| 286 #define U32V_2(x) \ | |
| 287 static_cast<byte>((x & MASK_7) | 0x80), static_cast<byte>((x >> 7) & MASK_7) | |
| 288 #define U32V_3(x) \ | |
| 289 static_cast<byte>((x & MASK_7) | 0x80), \ | |
| 290 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ | |
| 291 static_cast<byte>((x >> 14) & MASK_7) | |
| 292 #define U32V_4(x) \ | |
| 293 static_cast<byte>((x & MASK_7) | 0x80), \ | |
| 294 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ | |
| 295 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ | |
| 296 static_cast<byte>((x >> 21) & MASK_7) | |
| 297 #define U32V_5(x) \ | |
| 298 static_cast<byte>((x & MASK_7) | 0x80), \ | |
| 299 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ | |
| 300 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ | |
| 301 static_cast<byte>(((x >> 21) & MASK_7) | 0x80), \ | |
| 302 static_cast<byte>((x >> 28) & 0xF) | |
| 303 | |
| 304 #endif // V8_WASM_MACRO_GEN_H_ | 296 #endif // V8_WASM_MACRO_GEN_H_ |
| OLD | NEW |