summaryrefslogtreecommitdiff
path: root/test/example
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2019-05-31 20:02:37 -0700
committerGitHub <noreply@github.com>2019-05-31 20:02:37 -0700
commitfe99e3458f11d1a01fa3ad5b68883dbcba3903af (patch)
tree6f5eda61c7c7cba9c3b16be5e361cdc148d8b315 /test/example
parent7306f60a4474ca1fa948bddee5c068e7c2f635f6 (diff)
downloadbinaryen-fe99e3458f11d1a01fa3ad5b68883dbcba3903af.tar.gz
binaryen-fe99e3458f11d1a01fa3ad5b68883dbcba3903af.tar.bz2
binaryen-fe99e3458f11d1a01fa3ad5b68883dbcba3903af.zip
Add event section (#2151)
This adds support for the event and the event section, as specified in https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model. Wasm events are features that suspend the current execution and transfer the control flow to a corresponding handler. Currently the only supported event kind is exceptions. For events, this includes support for - Binary file reading/writing - Wast file reading/writing - Binaryen.js API - Fuzzer - Validation - Metadce - Passes: metrics, minify-imports-and-exports, remove-unused-module-elements
Diffstat (limited to 'test/example')
-rw-r--r--test/example/c-api-kitchen-sink.c5
-rw-r--r--test/example/c-api-kitchen-sink.txt26
-rw-r--r--test/example/c-api-kitchen-sink.txt.txt4
3 files changed, 27 insertions, 8 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index e0b4a5ec4..76a8aa675 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -488,6 +488,11 @@ void test_core() {
BinaryenAddGlobal(module, "a-global", BinaryenTypeInt32(), 0, makeInt32(module, 7));
BinaryenAddGlobal(module, "a-mutable-global", BinaryenTypeFloat32(), 1, makeFloat32(module, 7.5));
+ // Events
+ BinaryenType eparams[1] = { BinaryenTypeInt32() };
+ BinaryenFunctionTypeRef vi = BinaryenAddFunctionType(module, "vi", BinaryenTypeNone(), eparams, 1);
+ BinaryenAddEvent(module, "a-event", 0, vi);
+
// Imports
BinaryenType iparams[2] = { BinaryenTypeInt32(), BinaryenTypeFloat64() };
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index c9bcc4b68..e5e16c6fe 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -21,9 +21,10 @@ BinaryenFeatureAll: 127
)
(module
(type $iiIfF (func (param i32 i64 f32 f64) (result i32)))
+ (type $vi (func (param i32)))
(type $fiF (func (param i32 f64) (result f32)))
(type $v (func))
- (type $3 (func))
+ (type $4 (func))
(import "module" "base" (func $an-imported (param i32 f64) (result f32)))
(memory $0 1 256)
(data (i32.const 10) "hello, world")
@@ -32,6 +33,7 @@ BinaryenFeatureAll: 127
(elem (i32.const 0) "$kitchen()sinker")
(global $a-global i32 (i32.const 7))
(global $a-mutable-global (mut f32) (f32.const 7.5))
+ (event $a-event (attr 0) (param i32))
(export "kitchen_sinker" (func "$kitchen()sinker"))
(export "mem" (memory $0))
(start $starter)
@@ -1930,6 +1932,7 @@ int main() {
std::map<size_t, BinaryenExpressionRef> expressions;
std::map<size_t, BinaryenFunctionRef> functions;
std::map<size_t, BinaryenGlobalRef> globals;
+ std::map<size_t, BinaryenEventRef> events;
std::map<size_t, BinaryenExportRef> exports;
std::map<size_t, RelooperBlockRef> relooperBlocks;
BinaryenModuleRef the_module = NULL;
@@ -3308,10 +3311,15 @@ int main() {
expressions[654] = BinaryenConst(the_module, BinaryenLiteralFloat32(7.5));
globals[1] = BinaryenAddGlobal(the_module, "a-mutable-global", 3, 1, expressions[654]);
{
+ BinaryenType paramTypes[] = { 1 };
+ functionTypes[1] = BinaryenAddFunctionType(the_module, "vi", 0, paramTypes, 1);
+ }
+ BinaryenAddEvent(the_module, "a-event", 0, functionTypes[1]);
+ {
BinaryenType paramTypes[] = { 1, 4 };
- functionTypes[1] = BinaryenAddFunctionType(the_module, "fiF", 3, paramTypes, 2);
+ functionTypes[2] = BinaryenAddFunctionType(the_module, "fiF", 3, paramTypes, 2);
}
- BinaryenAddFunctionImport(the_module, "an-imported", "module", "base", functionTypes[1]);
+ BinaryenAddFunctionImport(the_module, "an-imported", "module", "base", functionTypes[2]);
exports[0] = BinaryenAddFunctionExport(the_module, "kitchen()sinker", "kitchen_sinker");
BinaryenFunctionGetName(functions[0]);
{
@@ -3330,17 +3338,17 @@ int main() {
}
{
BinaryenType paramTypes[] = { 0 };
- functionTypes[2] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0);
+ functionTypes[3] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0);
}
expressions[656] = BinaryenNop(the_module);
{
BinaryenType varTypes[] = { 0 };
- functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[2], varTypes, 0, expressions[656]);
+ functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[3], varTypes, 0, expressions[656]);
}
BinaryenSetStart(the_module, functions[1]);
{
BinaryenType paramTypes[] = { 0 };
- functionTypes[3] = BinaryenAddFunctionType(the_module, NULL, 0, paramTypes, 0);
+ functionTypes[4] = BinaryenAddFunctionType(the_module, NULL, 0, paramTypes, 0);
}
BinaryenModuleAutoDrop(the_module);
BinaryenModuleSetFeatures(the_module, 127);
@@ -3349,9 +3357,10 @@ int main() {
BinaryenModulePrint(the_module);
(module
(type $iiIfF (func (param i32 i64 f32 f64) (result i32)))
+ (type $vi (func (param i32)))
(type $fiF (func (param i32 f64) (result f32)))
(type $v (func))
- (type $3 (func))
+ (type $4 (func))
(import "module" "base" (func $an-imported (param i32 f64) (result f32)))
(memory $0 1 256)
(data (i32.const 10) "hello, world")
@@ -3360,6 +3369,7 @@ int main() {
(elem (i32.const 0) "$kitchen()sinker")
(global $a-global i32 (i32.const 7))
(global $a-mutable-global (mut f32) (f32.const 7.5))
+ (event $a-event (attr 0) (param i32))
(export "kitchen_sinker" (func "$kitchen()sinker"))
(export "mem" (memory $0))
(start $starter)
@@ -4723,6 +4733,7 @@ int main() {
expressions.clear();
functions.clear();
globals.clear();
+ events.clear();
exports.clear();
relooperBlocks.clear();
the_module = BinaryenModuleCreate();
@@ -5657,6 +5668,7 @@ optimized:
expressions.clear();
functions.clear();
globals.clear();
+ events.clear();
exports.clear();
relooperBlocks.clear();
return 0;
diff --git a/test/example/c-api-kitchen-sink.txt.txt b/test/example/c-api-kitchen-sink.txt.txt
index 05edca1a2..679ae534c 100644
--- a/test/example/c-api-kitchen-sink.txt.txt
+++ b/test/example/c-api-kitchen-sink.txt.txt
@@ -3,9 +3,10 @@
)
(module
(type $iiIfF (func (param i32 i64 f32 f64) (result i32)))
+ (type $vi (func (param i32)))
(type $fiF (func (param i32 f64) (result f32)))
(type $v (func))
- (type $3 (func))
+ (type $4 (func))
(import "module" "base" (func $an-imported (param i32 f64) (result f32)))
(memory $0 1 256)
(data (i32.const 10) "hello, world")
@@ -14,6 +15,7 @@
(elem (i32.const 0) "$kitchen()sinker")
(global $a-global i32 (i32.const 7))
(global $a-mutable-global (mut f32) (f32.const 7.5))
+ (event $a-event (attr 0) (param i32))
(export "kitchen_sinker" (func "$kitchen()sinker"))
(export "mem" (memory $0))
(start $starter)