summaryrefslogtreecommitdiff
path: root/test/example/c-api-kitchen-sink.c
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2021-01-15 18:48:00 +0900
committerGitHub <noreply@github.com>2021-01-15 18:48:00 +0900
commitbeccdf70258cd99ea25f10af13103e14dc243ffa (patch)
tree1081d7d350fbab7f901b917f2f082c8d351c3157 /test/example/c-api-kitchen-sink.c
parentf18c18e01d03d6d293fe3d701408855bbcea58bd (diff)
downloadbinaryen-beccdf70258cd99ea25f10af13103e14dc243ffa.tar.gz
binaryen-beccdf70258cd99ea25f10af13103e14dc243ffa.tar.bz2
binaryen-beccdf70258cd99ea25f10af13103e14dc243ffa.zip
Basic EH instrucion support for the new spec (#3487)
This updates `try`-`catch`-`catch_all` and `rethrow` instructions to match the new spec. `delegate` is not included. Now `Try` contains not a single `catchBody` expression but a vector of catch bodies and events. This updates most existing routines, optimizations, and tests modulo the interpreter and the CFG traversal. Because the interpreter has not been updated yet, the EH spec test is temporarily disabled in check.py. Also, because the CFG traversal for EH is not yet updated, several EH tests in `rse_all-features.wast`, which uses CFG traversal, are temporarily commented out. Also added a few more tests in existing EH test functions in test/passes. In the previous spec, `catch` was catching all exceptions so it was assumed that anything `try` body throws is caught by its `catch`, but now we can assume the same only if there is a `catch_all`. Newly added tests test cases when there is a `catch_all` and cases there are only `catch`es separately.
Diffstat (limited to 'test/example/c-api-kitchen-sink.c')
-rw-r--r--test/example/c-api-kitchen-sink.c40
1 files changed, 9 insertions, 31 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index 79cbabca3..58b1e00aa 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -325,40 +325,18 @@ void test_core() {
// (do
// (throw $a-event (i32.const 0))
// )
- // (catch
- // ;; We don't support multi-value yet. Use locals instead.
- // (local.set 0 (exnref.pop))
- // (drop
- // (block $try-block (result i32)
- // (rethrow
- // (br_on_exn $try-block $a-event (local.get 5))
- // )
- // )
- // )
+ // (catch $a-event
+ // (drop (i32 pop))
// )
+ // (catch_all)
// )
BinaryenExpressionRef tryBody = BinaryenThrow(
module, "a-event", (BinaryenExpressionRef[]){makeInt32(module, 0)}, 1);
- BinaryenExpressionRef catchBody = BinaryenBlock(
- module,
- NULL,
- (BinaryenExpressionRef[]){
- BinaryenLocalSet(module, 5, BinaryenPop(module, BinaryenTypeExnref())),
- BinaryenDrop(
- module,
- BinaryenBlock(module,
- "try-block",
- (BinaryenExpressionRef[]){BinaryenRethrow(
- module,
- BinaryenBrOnExn(
- module,
- "try-block",
- "a-event",
- BinaryenLocalGet(module, 5, BinaryenTypeExnref())))},
- 1,
- BinaryenTypeInt32()))},
- 2,
- BinaryenTypeNone());
+ BinaryenExpressionRef catchBody =
+ BinaryenDrop(module, BinaryenPop(module, BinaryenTypeInt32()));
+ BinaryenExpressionRef catchAllBody = BinaryenNop(module);
+ BinaryenExpressionRef catchBodies[] = {catchBody, catchAllBody};
+ const char* catchEvents[] = {"a-event"};
BinaryenType i32 = BinaryenTypeInt32();
BinaryenType i64 = BinaryenTypeInt64();
@@ -747,7 +725,7 @@ void test_core() {
BinaryenRefNull(module, BinaryenTypeEqref()),
BinaryenRefNull(module, BinaryenTypeEqref())),
// Exception handling
- BinaryenTry(module, tryBody, catchBody),
+ BinaryenTry(module, tryBody, catchEvents, 1, catchBodies, 2),
// Atomics
BinaryenAtomicStore(
module,