summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2019-08-13 00:29:26 +0900
committerGitHub <noreply@github.com>2019-08-13 00:29:26 +0900
commite2f49d8227f2b71e4dede5cf4074bb9f65e3d77f (patch)
tree30b132b02824839d1d7718ed32c6b90cc0828151 /test/unit
parent69ad1e8a8d2e1d395e30230433742f4f5668563b (diff)
downloadbinaryen-e2f49d8227f2b71e4dede5cf4074bb9f65e3d77f.tar.gz
binaryen-e2f49d8227f2b71e4dede5cf4074bb9f65e3d77f.tar.bz2
binaryen-e2f49d8227f2b71e4dede5cf4074bb9f65e3d77f.zip
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.
Diffstat (limited to 'test/unit')
-rwxr-xr-xtest/unit/input/exception_handling_target_feature.wasmbin0 -> 89 bytes
-rw-r--r--test/unit/test_features.py27
2 files changed, 27 insertions, 0 deletions
diff --git a/test/unit/input/exception_handling_target_feature.wasm b/test/unit/input/exception_handling_target_feature.wasm
new file mode 100755
index 000000000..487aaf679
--- /dev/null
+++ b/test/unit/input/exception_handling_target_feature.wasm
Binary files differ
diff --git a/test/unit/test_features.py b/test/unit/test_features.py
index 1836aa08a..3fd362aed 100644
--- a/test/unit/test_features.py
+++ b/test/unit/test_features.py
@@ -145,6 +145,27 @@ class FeatureValidationTest(BinaryenTestCase):
'''
self.check_tail_call(module, 'return_call_indirect requires tail calls to be enabled')
+ def test_exnref_local(self):
+ module = '''
+ (module
+ (func $foo
+ (local exnref)
+ )
+ )
+ '''
+ self.check_exception_handling(module, 'all used types should be allowed')
+
+ def test_event(self):
+ module = '''
+ (module
+ (event $e (attr 0) (param i32))
+ (func $foo
+ (throw $e (i32.const 0))
+ )
+ )
+ '''
+ self.check_exception_handling(module, 'Module has events')
+
class TargetFeaturesSectionTest(BinaryenTestCase):
def test_atomics(self):
@@ -190,6 +211,12 @@ class TargetFeaturesSectionTest(BinaryenTestCase):
self.check_features(filename, ['tail-call'])
self.assertIn('return_call', self.disassemble(filename))
+ def test_exception_handling(self):
+ filename = 'exception_handling_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['exception-handling'])
+ self.assertIn('throw', self.disassemble(filename))
+
def test_incompatible_features(self):
path = self.input_path('signext_target_feature.wasm')
p = run_process(