From e2f49d8227f2b71e4dede5cf4074bb9f65e3d77f Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 13 Aug 2019 00:29:26 +0900 Subject: Add basic exception handling support (#2282) This adds basic support for exception handling instructions, according to the spec: https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md This PR includes support for: - Binary reading/writing - Wast reading/writing - Stack IR - Validation - binaryen.js + C API - Few IR routines: branch-utils, type-updating, etc - Few passes: just enough to make `wasm-opt -O` pass - Tests This PR does not include support for many optimization passes, fuzzer, or interpreter. They will be follow-up PRs. Try-catch construct is modeled in Binaryen IR in a similar manner to that of if-else: each of try body and catch body will contain a block, which can be omitted if there is only a single instruction. This block will not be emitted in wast or binary, as in if-else. As in if-else, `class Try` contains two expressions each for try body and catch body, and `catch` is not modeled as an instruction. `exnref` value pushed by `catch` is get by `pop` instruction. `br_on_exn` is special: it returns different types of values when taken and not taken. We make `exnref`, the type `br_on_exn` pushes if not taken, as `br_on_exn`'s type. --- test/exception-handling.wast.fromBinary | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'test/exception-handling.wast.fromBinary') diff --git a/test/exception-handling.wast.fromBinary b/test/exception-handling.wast.fromBinary index 1cb238708..1cff3d215 100644 --- a/test/exception-handling.wast.fromBinary +++ b/test/exception-handling.wast.fromBinary @@ -1,8 +1,44 @@ (module (type $0 (func (param exnref) (result exnref))) - (memory $0 1 1) + (type $1 (func)) + (type $2 (func (param i32))) + (event $event$0 (attr 0) (param i32)) (func $exnref_test (; 0 ;) (type $0) (param $0 exnref) (result exnref) (local.get $0) ) + (func $eh_test (; 1 ;) (type $1) + (local $0 exnref) + (try + (throw $event$0 + (i32.const 0) + ) + (catch + (local.set $0 + (exnref.pop) + ) + (drop + (block $label$3 (result i32) + (rethrow + (br_on_exn $label$3 $event$0 + (local.get $0) + ) + ) + ) + ) + ) + ) + (block $label$4 + (try + (br $label$4) + (catch + (drop + (exnref.pop) + ) + (br $label$4) + ) + ) + ) + (unreachable) + ) ) -- cgit v1.2.3