diff options
author | Heejin Ahn <aheejin@gmail.com> | 2021-01-15 18:48:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 18:48:00 +0900 |
commit | beccdf70258cd99ea25f10af13103e14dc243ffa (patch) | |
tree | 1081d7d350fbab7f901b917f2f082c8d351c3157 /src/binaryen-c.h | |
parent | f18c18e01d03d6d293fe3d701408855bbcea58bd (diff) | |
download | binaryen-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 'src/binaryen-c.h')
-rw-r--r-- | src/binaryen-c.h | 78 |
1 files changed, 63 insertions, 15 deletions
diff --git a/src/binaryen-c.h b/src/binaryen-c.h index a32d9ff1c..8d991343d 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -796,16 +796,20 @@ BINARYEN_API BinaryenExpressionRef BinaryenRefFunc(BinaryenModuleRef module, BINARYEN_API BinaryenExpressionRef BinaryenRefEq(BinaryenModuleRef module, BinaryenExpressionRef left, BinaryenExpressionRef right); -BINARYEN_API BinaryenExpressionRef BinaryenTry(BinaryenModuleRef module, - BinaryenExpressionRef body, - BinaryenExpressionRef catchBody); +BINARYEN_API BinaryenExpressionRef +BinaryenTry(BinaryenModuleRef module, + BinaryenExpressionRef body, + const char** catchEvents, + BinaryenIndex numCatchEvents, + BinaryenExpressionRef* catchBodies, + BinaryenIndex numCatchBodies); BINARYEN_API BinaryenExpressionRef BinaryenThrow(BinaryenModuleRef module, const char* event, BinaryenExpressionRef* operands, BinaryenIndex numOperands); -BINARYEN_API BinaryenExpressionRef -BinaryenRethrow(BinaryenModuleRef module, BinaryenExpressionRef exnref); +BINARYEN_API BinaryenExpressionRef BinaryenRethrow(BinaryenModuleRef module, + BinaryenIndex depth); BINARYEN_API BinaryenExpressionRef BinaryenBrOnExn(BinaryenModuleRef module, const char* name, @@ -1714,12 +1718,57 @@ BinaryenTryGetBody(BinaryenExpressionRef expr); // Sets the body expression of a `try` expression. BINARYEN_API void BinaryenTrySetBody(BinaryenExpressionRef expr, BinaryenExpressionRef bodyExpr); -// Gets the catch body expression of a `try` expression. +// Gets the number of catch blocks (= the number of catch events) of a `try` +// expression. +BINARYEN_API BinaryenIndex +BinaryenTryGetNumCatchEvents(BinaryenExpressionRef expr); +// Gets the number of catch/catch_all blocks of a `try` expression. +BINARYEN_API BinaryenIndex +BinaryenTryGetNumCatchBodies(BinaryenExpressionRef expr); +// Gets the catch event at the specified index of a `try` expression. +BINARYEN_API const char* BinaryenTryGetCatchEventAt(BinaryenExpressionRef expr, + BinaryenIndex index); +// Sets the catch event at the specified index of a `try` expression. +BINARYEN_API void BinaryenTrySetCatchEventAt(BinaryenExpressionRef expr, + BinaryenIndex index, + const char* catchEvent); +// Appends a catch event to a `try` expression, returning its insertion index. +BINARYEN_API BinaryenIndex +BinaryenTryAppendCatchEvent(BinaryenExpressionRef expr, const char* catchEvent); +// Inserts a catch event at the specified index of a `try` expression, moving +// existing catch events including the one previously at that index one index +// up. +BINARYEN_API void BinaryenTryInsertCatchEventAt(BinaryenExpressionRef expr, + BinaryenIndex index, + const char* catchEvent); +// Removes the catch event at the specified index of a `try` expression, moving +// all subsequent catch events one index down. Returns the event. +BINARYEN_API const char* +BinaryenTryRemoveCatchEventAt(BinaryenExpressionRef expr, BinaryenIndex index); +// Gets the catch body expression at the specified index of a `try` expression. +BINARYEN_API BinaryenExpressionRef +BinaryenTryGetCatchBodyAt(BinaryenExpressionRef expr, BinaryenIndex index); +// Sets the catch body expression at the specified index of a `try` expression. +BINARYEN_API void BinaryenTrySetCatchBodyAt(BinaryenExpressionRef expr, + BinaryenIndex index, + BinaryenExpressionRef catchExpr); +// Appends a catch expression to a `try` expression, returning its insertion +// index. +BINARYEN_API BinaryenIndex BinaryenTryAppendCatchBody( + BinaryenExpressionRef expr, BinaryenExpressionRef catchExpr); +// Inserts a catch expression at the specified index of a `try` expression, +// moving existing catch bodies including the one previously at that index one +// index up. +BINARYEN_API void BinaryenTryInsertCatchBodyAt(BinaryenExpressionRef expr, + BinaryenIndex index, + BinaryenExpressionRef catchExpr); +// Removes the catch expression at the specified index of a `try` expression, +// moving all subsequent catch bodies one index down. Returns the catch +// expression. BINARYEN_API BinaryenExpressionRef -BinaryenTryGetCatchBody(BinaryenExpressionRef expr); -// Sets the catch body expression of a `try` expression. -BINARYEN_API void BinaryenTrySetCatchBody(BinaryenExpressionRef expr, - BinaryenExpressionRef catchBodyExpr); +BinaryenTryRemoveCatchBodyAt(BinaryenExpressionRef expr, BinaryenIndex index); +// Gets whether an `try` expression has a catch_all clause. +BINARYEN_API int BinaryenTryHasCatchAll(BinaryenExpressionRef expr); // Throw @@ -1757,12 +1806,11 @@ BinaryenThrowRemoveOperandAt(BinaryenExpressionRef expr, BinaryenIndex index); // Rethrow -// Gets the exception reference expression of a `rethrow` expression. -BINARYEN_API BinaryenExpressionRef -BinaryenRethrowGetExnref(BinaryenExpressionRef expr); +// Gets the depth of a `rethrow` expression. +BINARYEN_API BinaryenIndex BinaryenRethrowGetDepth(BinaryenExpressionRef expr); // Sets the exception reference expression of a `rethrow` expression. -BINARYEN_API void BinaryenRethrowSetExnref(BinaryenExpressionRef expr, - BinaryenExpressionRef exnrefExpr); +BINARYEN_API void BinaryenRethrowSetDepth(BinaryenExpressionRef expr, + BinaryenIndex depth); // BrOnExn |