diff options
Diffstat (limited to 'test/binaryen.js')
-rw-r--r-- | test/binaryen.js/event.js | 32 | ||||
-rw-r--r-- | test/binaryen.js/event.js.txt | 16 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js | 14 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js.txt | 38 |
4 files changed, 92 insertions, 8 deletions
diff --git a/test/binaryen.js/event.js b/test/binaryen.js/event.js new file mode 100644 index 000000000..ec7a0f3b1 --- /dev/null +++ b/test/binaryen.js/event.js @@ -0,0 +1,32 @@ +function cleanInfo(info) { + var ret = {}; + for (var x in info) { + ret[x] = info[x]; + } + return ret; +} + +var module = new Binaryen.Module(); +module.setFeatures(Binaryen.Features.ExceptionHandling); + +var vi = module.addFunctionType("vi", Binaryen.none, [Binaryen.i32]); +var vif = module.addFunctionType("vif", Binaryen.none, [Binaryen.i32, Binaryen.f32]); + +var event_ = module.addEvent("a-event", 0, vi); + +console.log("GetEvent is equal: " + (event_ === module.getEvent("a-event"))); + +var eventInfo = Binaryen.getEventInfo(event_); +console.log("getEventInfo=" + JSON.stringify(cleanInfo(eventInfo))); + +module.addEventExport("a-event", "a-event-exp"); +module.addEventImport("a-event-imp", "module", "base", 0, vif); + +module.validate(); +console.log(module.emitText()); + +module.removeExport("a-event-exp"); +module.removeEvent("a-event"); + +module.validate(); +console.log(module.emitText()); diff --git a/test/binaryen.js/event.js.txt b/test/binaryen.js/event.js.txt new file mode 100644 index 000000000..233f4b037 --- /dev/null +++ b/test/binaryen.js/event.js.txt @@ -0,0 +1,16 @@ +GetEvent is equal: true +getEventInfo={"name":"a-event","module":"","base":"","attribute":0,"type":"vi"} +(module + (type $vi (func (param i32))) + (type $vif (func (param i32 f32))) + (import "module" "base" (event $a-event-imp (attr 0) (param i32 f32))) + (event $a-event (attr 0) (param i32)) + (export "a-event-exp" (event $a-event)) +) + +(module + (type $vi (func (param i32))) + (type $vif (func (param i32 f32))) + (import "module" "base" (event $a-event-imp (attr 0) (param i32 f32))) +) + diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index 649abfa4b..e745c0303 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -423,16 +423,22 @@ function test_core() { var initExpr = module.i32.const(1); var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr) + // Create an event + var vi = module.addFunctionType("vi", Binaryen.none, [Binaryen.i32]); + var event_ = module.addEvent("a-event", 0, vi); + // Imports var fiF = module.addFunctionType("fiF", Binaryen.f32, [ Binaryen.i32, Binaryen.f64 ]); module.addFunctionImport("an-imported", "module", "base", fiF); module.addGlobalImport("a-global-imp", "module", "base", Binaryen.i32); + module.addEventImport("a-event-imp", "module", "base", 0, vi); // Exports module.addFunctionExport("kitchen()sinker", "kitchen_sinker"); module.addGlobalExport("a-global", "a-global-exp"); + module.addEventExport("a-event", "a-event-exp"); // Function table. One per module @@ -683,13 +689,16 @@ function test_binaries() { { // create a module and write it to binary module = new Binaryen.Module(); + module.setFeatures(Binaryen.Features.All); var iii = module.addFunctionType("iii", Binaryen.i32, [ Binaryen.i32, Binaryen.i32 ]); + var vii = module.addFunctionType("vii", Binaryen.none, [ Binaryen.i32, Binaryen.i32 ]); var x = module.local.get(0, Binaryen.i32), y = module.local.get(1, Binaryen.i32); var add = module.i32.add(x, y); var adder = module.addFunction("adder", iii, [], add); var initExpr = module.i32.const(3); var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr) + var event_ = module.addEvent("a-event", 0, vii); Binaryen.setDebugInfo(true); // include names section buffer = module.emitBinary(); Binaryen.setDebugInfo(false); @@ -702,6 +711,7 @@ function test_binaries() { // read the module from the binary module = Binaryen.readBinary(buffer); + module.setFeatures(Binaryen.Features.All); // validate, print, and free assert(module.validate()); @@ -755,16 +765,17 @@ function test_parsing() { // create a module and write it to text module = new Binaryen.Module(); - module.setFeatures(Binaryen.Features.All); var iii = module.addFunctionType("iii", Binaryen.i32, [ Binaryen.i32, Binaryen.i32 ]); + var vi = module.addFunctionType("vi", Binaryen.none, [ Binaryen.i32 ]); var x = module.local.get(0, Binaryen.i32), y = module.local.get(1, Binaryen.i32); var add = module.i32.add(x, y); var adder = module.addFunction("adder", iii, [], add); var initExpr = module.i32.const(3); var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr) + var event_ = module.addEvent("a-event", 0, vi); text = module.emitText(); module.dispose(); module = null; @@ -773,6 +784,7 @@ function test_parsing() { text = text.replace('adder', 'ADD_ER'); var module2 = Binaryen.parseText(text); + module2.setFeatures(Binaryen.Features.All); assert(module2.validate()); console.log("module loaded from text form:"); console.log(module2.emitText()); diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index 857950e6b..85085fa82 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -63,19 +63,23 @@ getExpressionInfo(f32.const)={"id":14,"type":3,"value":8.5} getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} (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" (global $a-global-imp i32)) (import "module" "base" (func $an-imported (param i32 f64) (result f32))) + (import "module" "base" (event $a-event-imp (attr 0) (param i32))) (memory $0 1 256) (data (i32.const 10) "hello, world") (data passive "I am passive") (table $0 1 funcref) (elem (i32.const 0) "$kitchen()sinker") (global $a-global i32 (i32.const 1)) + (event $a-event (attr 0) (param i32)) (export "kitchen_sinker" (func "$kitchen()sinker")) (export "a-global-exp" (global $a-global)) + (export "a-event-exp" (event $a-event)) (export "mem" (memory $0)) (start $starter) (func "$kitchen()sinker" (; 1 ;) (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) @@ -1898,7 +1902,9 @@ optimized: module loaded from binary form: (module (type $0 (func (param i32 i32) (result i32))) + (type $1 (func (param i32 i32))) (global $global$0 i32 (i32.const 3)) + (event $event$0 (attr 0) (param i32 i32)) (func $adder (; 0 ;) (type $0) (param $0 i32) (param $1 i32) (result i32) (i32.add (local.get $0) @@ -1944,6 +1950,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; @@ -3343,13 +3350,20 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} expressions[656] = BinaryenConst(the_module, BinaryenLiteralInt32(1)); globals[0] = BinaryenAddGlobal(the_module, "a-global", 1, 0, expressions[656]); { + 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]); BinaryenAddGlobalImport(the_module, "a-global-imp", "module", "base", 1); + BinaryenAddEventImport(the_module, "a-event-imp", "module", "base", 0, functionTypes[1]); exports[0] = BinaryenAddFunctionExport(the_module, "kitchen()sinker", "kitchen_sinker"); exports[1] = BinaryenAddGlobalExport(the_module, "a-global", "a-global-exp"); + exports[2] = BinaryenAddEventExport(the_module, "a-event", "a-event-exp"); BinaryenFunctionGetName(functions[0]); BinaryenFunctionImportGetModule(functions[0]); BinaryenFunctionImportGetBase(functions[0]); @@ -3379,17 +3393,17 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} } { BinaryenType paramTypes[] = { 0 }; - functionTypes[2] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0); + functionTypes[3] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0); } expressions[658] = BinaryenNop(the_module); { BinaryenType varTypes[] = { 0 }; - functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[2], varTypes, 0, expressions[658]); + functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[3], varTypes, 0, expressions[658]); } 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); @@ -3398,19 +3412,23 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} 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" (global $a-global-imp i32)) (import "module" "base" (func $an-imported (param i32 f64) (result f32))) + (import "module" "base" (event $a-event-imp (attr 0) (param i32))) (memory $0 1 256) (data (i32.const 10) "hello, world") (data passive "I am passive") (table $0 1 funcref) (elem (i32.const 0) "$kitchen()sinker") (global $a-global i32 (i32.const 1)) + (event $a-event (attr 0) (param i32)) (export "kitchen_sinker" (func "$kitchen()sinker")) (export "a-global-exp" (global $a-global)) + (export "a-event-exp" (event $a-event)) (export "mem" (memory $0)) (start $starter) (func "$kitchen()sinker" (; 1 ;) (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) @@ -4765,6 +4783,7 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} expressions.clear(); functions.clear(); globals.clear(); + events.clear(); exports.clear(); relooperBlocks.clear(); the_module = BinaryenModuleCreate(); @@ -5706,6 +5725,7 @@ optimized: expressions.clear(); functions.clear(); globals.clear(); + events.clear(); exports.clear(); relooperBlocks.clear(); return 0; @@ -5713,7 +5733,9 @@ optimized: test_parsing text: (module (type $iii (func (param i32 i32) (result i32))) + (type $vi (func (param i32))) (global $a-global i32 (i32.const 3)) + (event $a-event (attr 0) (param i32)) (func $adder (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.add (local.get $0) @@ -5725,7 +5747,9 @@ test_parsing text: module loaded from text form: (module (type $iii (func (param i32 i32) (result i32))) + (type $vi (func (param i32))) (global $a-global i32 (i32.const 3)) + (event $a-event (attr 0) (param i32)) (func $ADD_ER (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.add (local.get $0) |