Index: test/cctest/wasm/test-run-wasm.cc |
diff --git a/test/cctest/wasm/test-run-wasm.cc b/test/cctest/wasm/test-run-wasm.cc |
index f48e44d4eb5c258f67fd3452510affe2c47eeb79..9805bfd356a74945dd8784042a710a096acbd507 100644 |
--- a/test/cctest/wasm/test-run-wasm.cc |
+++ b/test/cctest/wasm/test-run-wasm.cc |
@@ -2776,3 +2776,222 @@ WASM_EXEC_TEST(Int32RemS_dead) { |
CHECK_TRAP(r.Call(-1001, 0)); |
CHECK_TRAP(r.Call(kMin, 0)); |
} |
+ |
+// TODO(jpp): WASM_EXEC_TEST(TryCatch) |
+ |
+// TODO(jpp): Move these macros to src/wasm/wasm-macro-gen.h once zero cost |
+// exceptions are added to the spec. |
+#define TRY_FINALLY(...) kExprTryFinally, __VA_ARGS__, kExprEnd |
+#define FINALLY(...) kExprFinally, __VA_ARGS__ |
+ |
+WASM_EXEC_TEST(TryFinally_single) { |
+ if (execution_mode == kExecuteInterpreted) { |
+ // TODO(jpp): implement eh support in the interpreter. |
+ return; |
+ } |
+ |
+ FLAG_wasm_eh_prototype = true; |
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
+ MachineType::Int32()); |
+ // r(i32 p, i32 q) -> i32 { |
+ // try { |
+ // if (q) { |
+ // break; |
+ // } |
+ // p += 0x0f0; |
+ // } finally { |
+ // p += 0x00f; |
+ // } |
+ // p += 0xf00 |
+ // return p; |
+ // } |
+ BUILD(r, TRY_FINALLY( |
+ WASM_IF(WASM_GET_LOCAL(1), WASM_BREAK(0)), |
+ WASM_SET_LOCAL( |
+ 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_2(0xf0))), |
+ FINALLY(WASM_SET_LOCAL( |
+ 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_1(0x0f))))), |
+ WASM_SET_LOCAL(0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0xf00))), |
+ WASM_GET_LOCAL(0)); |
+ |
+ CHECK_EQ(0xFFFF, r.Call(0xF000, 0)); |
+ CHECK_EQ(0xFF0F, r.Call(0xF000, 1)); |
+} |
+ |
+WASM_EXEC_TEST(TryFinally_double) { |
+ if (execution_mode == kExecuteInterpreted) { |
+ // TODO(jpp): implement eh support in the interpreter. |
+ return; |
+ } |
+ |
+ FLAG_wasm_eh_prototype = true; |
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
+ MachineType::Int32()); |
+ // r(i32 p, i32 q) -> i32 { |
+ // a: try { |
+ // b: try { |
+ // if (q == 40) { |
+ // break a; |
+ // } else { |
+ // if (q == 1) { |
+ // break b; |
+ // } |
+ // } |
+ // p += 0x00000f; |
+ // } finally { |
+ // p += 0x0000f0; |
+ // } |
+ // p += 0x000f00; |
+ // } finally { |
+ // p += 0x00f000; |
+ // } |
+ // return p; |
+ // } |
+ BUILD( |
+ r, |
+ TRY_FINALLY( |
+ TRY_FINALLY( |
+ WASM_IF_ELSE(WASM_I32_EQ(WASM_GET_LOCAL(1), WASM_I32V(40)), |
+ WASM_BREAK(1), |
+ WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(1), WASM_I32V(1)), |
+ WASM_BREAK(1))), |
+ WASM_SET_LOCAL( |
+ 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x00000f))), |
+ FINALLY(WASM_SET_LOCAL( |
+ 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x0000f0))))), |
+ WASM_SET_LOCAL(0, |
+ WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x000f00))), |
+ FINALLY(WASM_SET_LOCAL( |
+ 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x00f000))))), |
+ WASM_GET_LOCAL(0)); |
+ |
+ CHECK_EQ(0x7000ffff, r.Call(0x70000000, 2)); |
+ CHECK_EQ(0x7000fff0, r.Call(0x70000000, 1)); |
+ CHECK_EQ(0x7000f0f0, r.Call(0x70000000, 40)); |
+} |
+ |
+WASM_EXEC_TEST(TryFinally_multiple) { |
+ if (execution_mode == kExecuteInterpreted) { |
John
2016/08/22 13:36:34
Yeah, this test is complicated, but I don't see an
|
+ // TODO(jpp): implement eh support in the interpreter. |
+ return; |
+ } |
+ |
+ FLAG_wasm_eh_prototype = true; |
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
+ MachineType::Int32()); |
+ |
+// Handy-dandy shortcuts for recurring patterns for this test. |
+#define I32_IOR_LOCAL(local, value) \ |
+ WASM_SET_LOCAL(local, WASM_I32_IOR(WASM_GET_LOCAL(local), WASM_I32V(value))) |
+#define IF_LOCAL_IS_BREAK_TO(local, value, depth) \ |
+ WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(local), WASM_I32V(value)), \ |
+ WASM_BREAK(depth)) |
+ |
+ // r(i32 p, i32 q) -> i32 { |
+ // a: try { |
+ // b: try { |
+ // c: try { |
+ // d: try { |
+ // e: try { |
+ // switch (q) { |
+ // case 1: break e; |
+ // case 2: break d; |
+ // case 3: break c; |
+ // case 4: break b; |
+ // case 5: break a; |
+ // } |
+ // p |= 0x00000001; |
+ // } finally { |
+ // p |= 0x00000002; |
+ // } |
+ // switch (q) { |
+ // case 6: break d; |
+ // case 7: break c; |
+ // case 8: break b; |
+ // case 9: break a; |
+ // } |
+ // p |= 0x00000004; |
+ // } finally { |
+ // p |= 0x00000008; |
+ // } |
+ // switch (q) { |
+ // case 10: break c; |
+ // case 11: break b; |
+ // case 12: break a; |
+ // } |
+ // p |= 0x00000010; |
+ // } finally { |
+ // p |= 0x00000020; |
+ // } |
+ // switch (q) { |
+ // case 13: break b; |
+ // case 14: break a; |
+ // } |
+ // p |= 0x00000040; |
+ // } finally { |
+ // p |= 0x00000080; |
+ // } |
+ // switch (q) { |
+ // case 15: break a; |
+ // } |
+ // p |= 0x00000100; |
+ // } finally { |
+ // p |= 0x00000200; |
+ // } |
+ // return p; |
+ // } |
+ BUILD( |
+ r, |
+ TRY_FINALLY( |
+ TRY_FINALLY( |
+ TRY_FINALLY( |
+ TRY_FINALLY( |
+ TRY_FINALLY(IF_LOCAL_IS_BREAK_TO(1, 1, 0), |
+ IF_LOCAL_IS_BREAK_TO(1, 2, 1), |
+ IF_LOCAL_IS_BREAK_TO(1, 3, 2), |
+ IF_LOCAL_IS_BREAK_TO(1, 4, 3), |
+ IF_LOCAL_IS_BREAK_TO(1, 5, 4), |
+ I32_IOR_LOCAL(0, 0x00000001), |
+ FINALLY(I32_IOR_LOCAL(0, 0x00000002))), |
+ IF_LOCAL_IS_BREAK_TO(1, 6, 0), |
+ IF_LOCAL_IS_BREAK_TO(1, 7, 1), |
+ IF_LOCAL_IS_BREAK_TO(1, 8, 2), |
+ IF_LOCAL_IS_BREAK_TO(1, 9, 3), |
+ I32_IOR_LOCAL(0, 0x00000004), |
+ FINALLY(I32_IOR_LOCAL(0, 0x00000008))), |
+ IF_LOCAL_IS_BREAK_TO(1, 10, 0), |
+ IF_LOCAL_IS_BREAK_TO(1, 11, 1), |
+ IF_LOCAL_IS_BREAK_TO(1, 12, 2), I32_IOR_LOCAL(0, 0x00000010), |
+ FINALLY(I32_IOR_LOCAL(0, 0x00000020))), |
+ IF_LOCAL_IS_BREAK_TO(1, 13, 0), IF_LOCAL_IS_BREAK_TO(1, 14, 1), |
+ I32_IOR_LOCAL(0, 0x00000040), |
+ FINALLY(I32_IOR_LOCAL(0, 0x00000080))), |
+ IF_LOCAL_IS_BREAK_TO(1, 15, 0), I32_IOR_LOCAL(0, 0x00000100), |
+ FINALLY(I32_IOR_LOCAL(0, 0x00000200))), |
+ WASM_GET_LOCAL(0)); |
+#undef WASM_IF_LOCAL_IS_BREAK_TO |
+#undef WASM_I32_IOR_LOCAL |
+ |
+ const struct { |
+ uint32_t inputs[2]; |
+ uint32_t expected_output; |
+ } kTests[] = { |
+ {{0x80000000u, 0}, 0x800003ffu}, {{0x80000000u, 1}, 0x800003feu}, |
+ {{0x80000000u, 2}, 0x800003fau}, {{0x80000000u, 3}, 0x800003eau}, |
+ {{0x80000000u, 4}, 0x800003aau}, {{0x80000000u, 5}, 0x800002aau}, |
+ {{0x80000000u, 6}, 0x800003fbu}, {{0x80000000u, 7}, 0x800003ebu}, |
+ {{0x80000000u, 8}, 0x800003abu}, {{0x80000000u, 9}, 0x800002abu}, |
+ {{0x80000000u, 10}, 0x800003efu}, {{0x80000000u, 11}, 0x800003afu}, |
+ {{0x80000000u, 12}, 0x800002afu}, {{0x80000000u, 13}, 0x800003bfu}, |
+ {{0x80000000u, 14}, 0x800002bfu}, {{0x80000000u, 15}, 0x800002ffu}, |
+ }; |
+ |
+ for (uint32_t ii = 0; ii < arraysize(kTests); ++ii) { |
+ const auto& test_instance = kTests[ii]; |
+ CHECK_EQ(test_instance.expected_output, |
+ static_cast<uint32_t>( |
+ r.Call(test_instance.inputs[0], test_instance.inputs[1]))); |
+ } |
+} |
+ |
+// TODO(jpp): WASM_EXEC_TEST(TryCatchFinally) |