Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Unified Diff: src/wasm/wasm-macro-gen.h

Issue 1764723002: [wasm] Remove TableSwitch and replace with br_table. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/wasm/wasm-macro-gen.h
diff --git a/src/wasm/wasm-macro-gen.h b/src/wasm/wasm-macro-gen.h
index e40a2d4aaccc5633115d99c74aad5dfb66bb7b17..e0c26dd5f714fcf2ba2bbfa8ed450f83832dd117 100644
--- a/src/wasm/wasm-macro-gen.h
+++ b/src/wasm/wasm-macro-gen.h
@@ -9,6 +9,43 @@
// Convenience macros for building Wasm bytecode directly into a byte array.
+#define U32_LE(v) \
+ static_cast<byte>(v), static_cast<byte>((v) >> 8), \
+ static_cast<byte>((v) >> 16), static_cast<byte>((v) >> 24)
+
+#define U16_LE(v) static_cast<byte>(v), static_cast<byte>((v) >> 8)
+
+#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
+
+#define SIG_INDEX(v) U16_LE(v)
+#define FUNC_INDEX(v) U16_LE(v)
+#define NAME_OFFSET(v) U32_LE(v)
+#define BR_TARGET(v) U16_LE(v)
+
+#define MASK_7 ((1 << 7) - 1)
+#define MASK_14 ((1 << 14) - 1)
+#define MASK_21 ((1 << 21) - 1)
+#define MASK_28 ((1 << 28) - 1)
+
+#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? (
+#define U32V_2(x) \
+ static_cast<byte>((x & MASK_7) | 0x80), static_cast<byte>((x >> 7) & MASK_7)
+#define U32V_3(x) \
+ static_cast<byte>((x & MASK_7) | 0x80), \
+ static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \
+ static_cast<byte>((x >> 14) & MASK_7)
+#define U32V_4(x) \
+ static_cast<byte>((x & MASK_7) | 0x80), \
+ static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \
+ static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \
+ static_cast<byte>((x >> 21) & MASK_7)
+#define U32V_5(x) \
+ static_cast<byte>((x & MASK_7) | 0x80), \
+ static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \
+ static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \
+ static_cast<byte>(((x >> 21) & MASK_7) | 0x80), \
+ static_cast<byte>((x >> 28) & 0xF)
+
//------------------------------------------------------------------------------
// Control.
//------------------------------------------------------------------------------
@@ -33,17 +70,8 @@
#define WASM_RETURN(...) kExprReturn, __VA_ARGS__
#define WASM_UNREACHABLE kExprUnreachable
-#define WASM_TABLESWITCH_OP(case_count, table_count, ...) \
- kExprTableSwitch, static_cast<byte>(case_count), \
- static_cast<byte>(case_count >> 8), static_cast<byte>(table_count), \
- static_cast<byte>(table_count >> 8), __VA_ARGS__
-
-#define WASM_TABLESWITCH_BODY0(key) key
-
-#define WASM_TABLESWITCH_BODY(key, ...) key, __VA_ARGS__
-
-#define WASM_CASE(x) static_cast<byte>(x), static_cast<byte>(x >> 8)
-#define WASM_CASE_BR(x) static_cast<byte>(x), static_cast<byte>(0x80 | (x) >> 8)
+#define WASM_BR_TABLE(key, count, ...) \
+ kExprBrTable, U16_LE(count), __VA_ARGS__, key
//------------------------------------------------------------------------------
// Misc expressions.
@@ -265,40 +293,4 @@
#define WASM_I32_REINTERPRET_F32(x) kExprI32ReinterpretF32, x
#define WASM_I64_REINTERPRET_F64(x) kExprI64ReinterpretF64, x
-#define U32_LE(v) \
- static_cast<byte>(v), static_cast<byte>((v) >> 8), \
- static_cast<byte>((v) >> 16), static_cast<byte>((v) >> 24)
-
-#define U16_LE(v) static_cast<byte>(v), static_cast<byte>((v) >> 8)
-
-#define WASM_MODULE_HEADER U32_LE(kWasmMagic), U32_LE(kWasmVersion)
-
-#define SIG_INDEX(v) U16_LE(v)
-#define FUNC_INDEX(v) U16_LE(v)
-#define NAME_OFFSET(v) U32_LE(v)
-
-#define MASK_7 ((1 << 7) - 1)
-#define MASK_14 ((1 << 14) - 1)
-#define MASK_21 ((1 << 21) - 1)
-#define MASK_28 ((1 << 28) - 1)
-
-#define U32V_1(x) static_cast<byte>(x & MASK_7)
-#define U32V_2(x) \
- static_cast<byte>((x & MASK_7) | 0x80), static_cast<byte>((x >> 7) & MASK_7)
-#define U32V_3(x) \
- static_cast<byte>((x & MASK_7) | 0x80), \
- static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \
- static_cast<byte>((x >> 14) & MASK_7)
-#define U32V_4(x) \
- static_cast<byte>((x & MASK_7) | 0x80), \
- static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \
- static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \
- static_cast<byte>((x >> 21) & MASK_7)
-#define U32V_5(x) \
- static_cast<byte>((x & MASK_7) | 0x80), \
- static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \
- static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \
- static_cast<byte>(((x >> 21) & MASK_7) | 0x80), \
- static_cast<byte>((x >> 28) & 0xF)
-
#endif // V8_WASM_MACRO_GEN_H_

Powered by Google App Engine
This is Rietveld 408576698