diff options
Diffstat (limited to 'test/binaryen.js')
-rw-r--r-- | test/binaryen.js/atomics.js | 158 | ||||
-rw-r--r-- | test/binaryen.js/custom-section.js | 18 | ||||
-rw-r--r-- | test/binaryen.js/debug-info.js | 72 | ||||
-rw-r--r-- | test/binaryen.js/emit_asmjs.js | 18 | ||||
-rw-r--r-- | test/binaryen.js/event.js | 38 | ||||
-rw-r--r-- | test/binaryen.js/exception-handling.js | 92 | ||||
-rw-r--r-- | test/binaryen.js/functions.js | 42 | ||||
-rw-r--r-- | test/binaryen.js/global.js | 46 | ||||
-rw-r--r-- | test/binaryen.js/hello-world.js | 80 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js | 398 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js.txt | 88 | ||||
-rw-r--r-- | test/binaryen.js/optimize-levels.js | 90 | ||||
-rw-r--r-- | test/binaryen.js/push-pop.js | 63 | ||||
-rw-r--r-- | test/binaryen.js/reloc.js | 38 | ||||
-rw-r--r-- | test/binaryen.js/sieve.js | 128 | ||||
-rw-r--r-- | test/binaryen.js/simd.js | 12 | ||||
-rw-r--r-- | test/binaryen.js/sourcemap.js | 64 | ||||
-rw-r--r-- | test/binaryen.js/stackir.js | 22 | ||||
-rw-r--r-- | test/binaryen.js/validation_errors.js | 52 |
19 files changed, 693 insertions, 826 deletions
diff --git a/test/binaryen.js/atomics.js b/test/binaryen.js/atomics.js index 1374da804..bd4b898bd 100644 --- a/test/binaryen.js/atomics.js +++ b/test/binaryen.js/atomics.js @@ -1,95 +1,87 @@ -function assert(x) { - if (!x) throw 'error!'; -} - var wast = ` (module (memory $0 (shared 1 1)) ) `; -function test() { - var module = Binaryen.parseText(wast); +var module = binaryen.parseText(wast); - // i32/i64.atomic.load/store - module.addFunction("main", Binaryen.none, Binaryen.none, [], module.block("", [ - // i32 - module.i32.atomic.store(0, - module.i32.const(0), - module.i32.atomic.load(0, - module.i32.const(0) - ) - ), - // i32 as u8 - module.i32.atomic.store8(0, - module.i32.const(0), - module.i32.atomic.load8_u(0, - module.i32.const(0) - ) - ), - // i32 as u16 - module.i32.atomic.store16(0, +// i32/i64.atomic.load/store +module.addFunction("main", binaryen.none, binaryen.none, [], module.block("", [ + // i32 + module.i32.atomic.store(0, + module.i32.const(0), + module.i32.atomic.load(0, + module.i32.const(0) + ) + ), + // i32 as u8 + module.i32.atomic.store8(0, + module.i32.const(0), + module.i32.atomic.load8_u(0, + module.i32.const(0) + ) + ), + // i32 as u16 + module.i32.atomic.store16(0, + module.i32.const(0), + module.i32.atomic.load16_u(0, + module.i32.const(0) + ) + ), + // i64 + module.i64.atomic.store(0, + module.i32.const(0), + module.i64.atomic.load(0, + module.i32.const(0) + ) + ), + // i64 as u8 + module.i64.atomic.store8(0, + module.i32.const(0), + module.i64.atomic.load8_u(0, + module.i32.const(0) + ) + ), + // i64 as u16 + module.i64.atomic.store16(0, + module.i32.const(0), + module.i64.atomic.load16_u(0, + module.i32.const(0) + ) + ), + // i64 as u32 + module.i64.atomic.store32(0, + module.i32.const(0), + module.i64.atomic.load32_u(0, + module.i32.const(0) + ) + ), + // wait and notify + module.drop( + module.i32.atomic.wait( module.i32.const(0), - module.i32.atomic.load16_u(0, - module.i32.const(0) - ) - ), - // i64 - module.i64.atomic.store(0, module.i32.const(0), - module.i64.atomic.load(0, - module.i32.const(0) - ) - ), - // i64 as u8 - module.i64.atomic.store8(0, + module.i64.const(0) + ) + ), + module.drop( + module.i64.atomic.wait( module.i32.const(0), - module.i64.atomic.load8_u(0, - module.i32.const(0) - ) - ), - // i64 as u16 - module.i64.atomic.store16(0, + module.i64.const(0), + module.i64.const(0) + ) + ), + module.drop( + module.atomic.notify( module.i32.const(0), - module.i64.atomic.load16_u(0, - module.i32.const(0) - ) - ), - // i64 as u32 - module.i64.atomic.store32(0, - module.i32.const(0), - module.i64.atomic.load32_u(0, - module.i32.const(0) - ) - ), - // wait and notify - module.drop( - module.i32.atomic.wait( - module.i32.const(0), - module.i32.const(0), - module.i64.const(0) - ) - ), - module.drop( - module.i64.atomic.wait( - module.i32.const(0), - module.i64.const(0), - module.i64.const(0) - ) - ), - module.drop( - module.atomic.notify( - module.i32.const(0), - module.i32.const(0) - ) - ), - // fence - module.atomic.fence() - ])); - - module.setFeatures(Binaryen.Features.Atomics); - assert(module.validate()); - console.log(module.emitText()); -} + module.i32.const(0) + ) + ), + // fence + module.atomic.fence() +])); -Binaryen.ready.then(test); +module.setFeatures(binaryen.Features.Atomics); +assert(module.validate()); +console.log(module.emitText()); diff --git a/test/binaryen.js/custom-section.js b/test/binaryen.js/custom-section.js index 2ecd39025..404fe4a4a 100644 --- a/test/binaryen.js/custom-section.js +++ b/test/binaryen.js/custom-section.js @@ -1,15 +1,7 @@ -function assert(x) { - if (!x) throw 'error!'; -} +binaryen.setAPITracing(true); +var module = new binaryen.Module(); -function test() { - Binaryen.setAPITracing(true); - var module = new Binaryen.Module(); +module.addCustomSection("hello", [119, 111, 114, 108, 100]); - module.addCustomSection("hello", [119, 111, 114, 108, 100]); - - assert(module.validate()); - console.log(module.emitText()); -} - -Binaryen.ready.then(test); +assert(module.validate()); +console.log(module.emitText()); diff --git a/test/binaryen.js/debug-info.js b/test/binaryen.js/debug-info.js index a769d8911..44eca1b07 100644 --- a/test/binaryen.js/debug-info.js +++ b/test/binaryen.js/debug-info.js @@ -1,7 +1,3 @@ -function assert(x) { - if (!x) throw 'error!'; -} - var wast = ` (module (type $v (func)) @@ -11,41 +7,37 @@ var wast = ` ) `; -function test() { - // Use defaults (should not emit debug info) - console.log("=== default ==="); - console.log("debugInfo=" + Binaryen.getDebugInfo()); - var module = Binaryen.parseText(wast); - var binary = module.emitBinary(); - module.dispose(); - module = Binaryen.readBinary(binary); - console.log(module.emitText()); - assert(module.validate()); - module.dispose(); - - // With debug info - console.log("=== with debug info ==="); - Binaryen.setDebugInfo(true); - console.log("debugInfo=" + Binaryen.getDebugInfo()); - module = Binaryen.parseText(wast); - binary = module.emitBinary(); - module.dispose(); - module = Binaryen.readBinary(binary); - console.log(module.emitText()); - assert(module.validate()); - module.dispose(); +// Use defaults (should not emit debug info) +console.log("=== default ==="); +console.log("debugInfo=" + binaryen.getDebugInfo()); +var module = binaryen.parseText(wast); +var binary = module.emitBinary(); +module.dispose(); +module = binaryen.readBinary(binary); +console.log(module.emitText()); +assert(module.validate()); +module.dispose(); - // Without debug info - console.log("=== without debug info ==="); - Binaryen.setDebugInfo(false); - console.log("debugInfo=" + Binaryen.getDebugInfo()); - module = Binaryen.parseText(wast); - binary = module.emitBinary(); - module.dispose(); - module = Binaryen.readBinary(binary); - console.log(module.emitText()); - assert(module.validate()); - module.dispose(); -} +// With debug info +console.log("=== with debug info ==="); +binaryen.setDebugInfo(true); +console.log("debugInfo=" + binaryen.getDebugInfo()); +module = binaryen.parseText(wast); +binary = module.emitBinary(); +module.dispose(); +module = binaryen.readBinary(binary); +console.log(module.emitText()); +assert(module.validate()); +module.dispose(); -Binaryen.ready.then(test); +// Without debug info +console.log("=== without debug info ==="); +binaryen.setDebugInfo(false); +console.log("debugInfo=" + binaryen.getDebugInfo()); +module = binaryen.parseText(wast); +binary = module.emitBinary(); +module.dispose(); +module = binaryen.readBinary(binary); +console.log(module.emitText()); +assert(module.validate()); +module.dispose(); diff --git a/test/binaryen.js/emit_asmjs.js b/test/binaryen.js/emit_asmjs.js index 751712592..e7b9afee2 100644 --- a/test/binaryen.js/emit_asmjs.js +++ b/test/binaryen.js/emit_asmjs.js @@ -1,17 +1,9 @@ -function assert(x) { - if (!x) throw 'error!'; -} +var module = new binaryen.Module(); -function test() { - var module = new Binaryen.Module(); +module.addFunction("main", binaryen.i32, binaryen.i32, [], module.local.get(0, binaryen.i32)); - module.addFunction("main", Binaryen.i32, Binaryen.i32, [], module.local.get(0, Binaryen.i32)); +module.addFunctionExport("main", "main"); - module.addFunctionExport("main", "main"); +assert(module.validate()); // should validate before calling emitAsmjs - assert(module.validate()); // should validate before calling emitAsmjs - - console.log(module.emitAsmjs()); -} - -Binaryen.ready.then(test); +console.log(module.emitAsmjs()); diff --git a/test/binaryen.js/event.js b/test/binaryen.js/event.js index f728e9228..73af158f9 100644 --- a/test/binaryen.js/event.js +++ b/test/binaryen.js/event.js @@ -1,7 +1,3 @@ -function assert(x) { - if (!x) throw 'error!'; -} - function cleanInfo(info) { var ret = {}; for (var x in info) { @@ -10,30 +6,26 @@ function cleanInfo(info) { return ret; } -function test() { - var module = new Binaryen.Module(); - module.setFeatures(Binaryen.Features.ExceptionHandling); +var module = new binaryen.Module(); +module.setFeatures(binaryen.Features.ExceptionHandling); - var pairType = Binaryen.createType([Binaryen.i32, Binaryen.f32]); +var pairType = binaryen.createType([binaryen.i32, binaryen.f32]); - var event_ = module.addEvent("a-event", 0, Binaryen.i32, Binaryen.none); +var event_ = module.addEvent("a-event", 0, binaryen.i32, binaryen.none); - console.log("GetEvent is equal: " + (event_ === module.getEvent("a-event"))); +console.log("GetEvent is equal: " + (event_ === module.getEvent("a-event"))); - var eventInfo = Binaryen.getEventInfo(event_); - console.log("getEventInfo=" + JSON.stringify(cleanInfo(eventInfo))); +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, pairType, Binaryen.none); +module.addEventExport("a-event", "a-event-exp"); +module.addEventImport("a-event-imp", "module", "base", 0, pairType, binaryen.none); - assert(module.validate()); - console.log(module.emitText()); +assert(module.validate()); +console.log(module.emitText()); - module.removeExport("a-event-exp"); - module.removeEvent("a-event"); - - assert(module.validate()); - console.log(module.emitText()); -} +module.removeExport("a-event-exp"); +module.removeEvent("a-event"); -Binaryen.ready.then(test); +assert(module.validate()); +console.log(module.emitText()); diff --git a/test/binaryen.js/exception-handling.js b/test/binaryen.js/exception-handling.js index 5ee53667c..b3c9974e7 100644 --- a/test/binaryen.js/exception-handling.js +++ b/test/binaryen.js/exception-handling.js @@ -1,7 +1,3 @@ -function assert(x) { - if (!x) throw 'error!'; -} - function cleanInfo(info) { var ret = {}; for (var x in info) { @@ -13,52 +9,48 @@ function cleanInfo(info) { } function stringify(expr) { - return JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(expr))); + return JSON.stringify(cleanInfo(binaryen.getExpressionInfo(expr))); } -function test() { - var module = new Binaryen.Module(); - module.setFeatures(Binaryen.Features.ReferenceTypes | - Binaryen.Features.ExceptionHandling); - - var event_ = module.addEvent("e", 0, Binaryen.i32, Binaryen.none); - - // (try - // (throw $e (i32.const 0)) - // (catch - // ;; We don't support multi-value yet. Use locals instead. - // (local.set 0 (exnref.pop)) - // (drop - // (block $l (result i32) - // (rethrow - // (br_on_exn $l $e (local.get 0)) - // ) - // ) - // ) - // ) - // ) - var throw_ = module.throw("e", [module.i32.const(0)]); - var br_on_exn = module.br_on_exn("l", "e", module.local.get(0, Binaryen.exnref)); - var rethrow = module.rethrow(br_on_exn); - var try_ = module.try( - throw_, - module.block(null, [ - module.local.set(0, module.exnref.pop()), - module.drop( - module.block("l", [rethrow], Binaryen.i32) - ) - ] +var module = new binaryen.Module(); +module.setFeatures(binaryen.Features.ReferenceTypes | + binaryen.Features.ExceptionHandling); + +var event_ = module.addEvent("e", 0, binaryen.i32, binaryen.none); + +// (try +// (throw $e (i32.const 0)) +// (catch +// ;; We don't support multi-value yet. Use locals instead. +// (local.set 0 (exnref.pop)) +// (drop +// (block $l (result i32) +// (rethrow +// (br_on_exn $l $e (local.get 0)) +// ) +// ) +// ) +// ) +// ) +var throw_ = module.throw("e", [module.i32.const(0)]); +var br_on_exn = module.br_on_exn("l", "e", module.local.get(0, binaryen.exnref)); +var rethrow = module.rethrow(br_on_exn); +var try_ = module.try( + throw_, + module.block(null, [ + module.local.set(0, module.exnref.pop()), + module.drop( + module.block("l", [rethrow], binaryen.i32) ) - ); - var func = module.addFunction("test", Binaryen.none, Binaryen.none, [Binaryen.exnref], try_); - - console.log(module.emitText()); - assert(module.validate()); - - console.log("getExpressionInfo(throw) = " + stringify(throw_)); - console.log("getExpressionInfo(br_on_exn) = " + stringify(br_on_exn)); - console.log("getExpressionInfo(rethrow) = " + stringify(rethrow)); - console.log("getExpressionInfo(try) = " + stringify(try_)); -} - -Binaryen.ready.then(test); + ] + ) +); +var func = module.addFunction("test", binaryen.none, binaryen.none, [binaryen.exnref], try_); + +console.log(module.emitText()); +assert(module.validate()); + +console.log("getExpressionInfo(throw) = " + stringify(throw_)); +console.log("getExpressionInfo(br_on_exn) = " + stringify(br_on_exn)); +console.log("getExpressionInfo(rethrow) = " + stringify(rethrow)); +console.log("getExpressionInfo(try) = " + stringify(try_)); diff --git a/test/binaryen.js/functions.js b/test/binaryen.js/functions.js index 0a3aa2243..b50632dfa 100644 --- a/test/binaryen.js/functions.js +++ b/test/binaryen.js/functions.js @@ -1,7 +1,3 @@ -function assert(x) { - if (!x) throw 'error!'; -} - function cleanInfo(info) { var ret = {}; for (var x in info) { @@ -12,31 +8,27 @@ function cleanInfo(info) { return ret; } -function test() { - var module = new Binaryen.Module(); +var module = new binaryen.Module(); - var func = module.addFunction("a-function", Binaryen.none, Binaryen.i32, [], - module.i32.add( - module.i32.const(1), - module.i32.const(2) - ) - ); +var func = module.addFunction("a-function", binaryen.none, binaryen.i32, [], + module.i32.add( + module.i32.const(1), + module.i32.const(2) + ) +); - console.log("GetFunction is equal: " + (func === module.getFunction("a-function"))); +console.log("GetFunction is equal: " + (func === module.getFunction("a-function"))); - module.runPassesOnFunction(func, ["precompute"]); +module.runPassesOnFunction(func, ["precompute"]); - var funcInfo = Binaryen.getFunctionInfo(func); - console.log("getFunctionInfo=" + JSON.stringify(cleanInfo(funcInfo))); - var expInfo = Binaryen.getExpressionInfo(funcInfo.body); - console.log("getExpressionInfo(body)=" + JSON.stringify(cleanInfo(expInfo))); - console.log(Binaryen.emitText(funcInfo.body)); +var funcInfo = binaryen.getFunctionInfo(func); +console.log("getFunctionInfo=" + JSON.stringify(cleanInfo(funcInfo))); +var expInfo = binaryen.getExpressionInfo(funcInfo.body); +console.log("getExpressionInfo(body)=" + JSON.stringify(cleanInfo(expInfo))); +console.log(binaryen.emitText(funcInfo.body)); - module.removeFunction("a-function"); +module.removeFunction("a-function"); - assert(module.validate()); - - console.log(module.emitText()); -} +assert(module.validate()); -Binaryen.ready.then(test); +console.log(module.emitText()); diff --git a/test/binaryen.js/global.js b/test/binaryen.js/global.js index 48571ef93..b0baf2599 100644 --- a/test/binaryen.js/global.js +++ b/test/binaryen.js/global.js @@ -1,7 +1,3 @@ -function assert(x) { - if (!x) throw 'error!'; -} - function cleanInfo(info) { var ret = {}; for (var x in info) { @@ -12,34 +8,30 @@ function cleanInfo(info) { return ret; } -function test() { - var module = new Binaryen.Module(); - module.setFeatures(Binaryen.Features.MVP | Binaryen.Features.MutableGlobals); +var module = new binaryen.Module(); +module.setFeatures(binaryen.Features.MVP | binaryen.Features.MutableGlobals); - var initExpr = module.i32.const(1); - var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr); +var initExpr = module.i32.const(1); +var global = module.addGlobal("a-global", binaryen.i32, false, initExpr); - console.log("GetGlobal is equal: " + (global === module.getGlobal("a-global"))); +console.log("GetGlobal is equal: " + (global === module.getGlobal("a-global"))); - var globalInfo = Binaryen.getGlobalInfo(global); - console.log("getGlobalInfo=" + JSON.stringify(cleanInfo(globalInfo))); +var globalInfo = binaryen.getGlobalInfo(global); +console.log("getGlobalInfo=" + JSON.stringify(cleanInfo(globalInfo))); - var initExpInfo = Binaryen.getExpressionInfo(globalInfo.init); - console.log("getExpressionInfo(init)=" + JSON.stringify(cleanInfo(initExpInfo))); - console.log(Binaryen.emitText(globalInfo.init)); +var initExpInfo = binaryen.getExpressionInfo(globalInfo.init); +console.log("getExpressionInfo(init)=" + JSON.stringify(cleanInfo(initExpInfo))); +console.log(binaryen.emitText(globalInfo.init)); - module.addGlobalExport("a-global", "a-global-exp"); - module.addGlobalImport("a-global-imp", "module", "base", Binaryen.i32, false); - module.addGlobalImport("a-mut-global-imp", "module", "base", Binaryen.i32, true); +module.addGlobalExport("a-global", "a-global-exp"); +module.addGlobalImport("a-global-imp", "module", "base", binaryen.i32, false); +module.addGlobalImport("a-mut-global-imp", "module", "base", binaryen.i32, true); - assert(module.validate()); - console.log(module.emitText()); +assert(module.validate()); +console.log(module.emitText()); - module.removeGlobal("a-global"); - module.removeExport("a-global-exp"); - - assert(module.validate()); - console.log(module.emitText()); -} +module.removeGlobal("a-global"); +module.removeExport("a-global-exp"); -Binaryen.ready.then(test); +assert(module.validate()); +console.log(module.emitText()); diff --git a/test/binaryen.js/hello-world.js b/test/binaryen.js/hello-world.js index d14c97912..d82de6116 100644 --- a/test/binaryen.js/hello-world.js +++ b/test/binaryen.js/hello-world.js @@ -1,57 +1,49 @@ -function assert(x) { - if (!x) throw 'error!'; -} - // "hello world" type example: create a function that adds two i32s and // returns the result -function test() { - // Create a module to work on - var module = new Binaryen.Module(); - - // Start to create the function, starting with the contents: Get the 0 and - // 1 arguments, and add them, then return them - var left = module.local.get(0, Binaryen.i32); - var right = module.local.get(1, Binaryen.i32); - var add = module.i32.add(left, right); - var ret = module.return(add); +// Create a module to work on +var module = new binaryen.Module(); - // Create the add function - // Note: no additional local variables (that's the []) - var ii = Binaryen.createType([Binaryen.i32, Binaryen.i32]) - module.addFunction('adder', ii, Binaryen.i32, [], ret); +// Start to create the function, starting with the contents: Get the 0 and +// 1 arguments, and add them, then return them +var left = module.local.get(0, binaryen.i32); +var right = module.local.get(1, binaryen.i32); +var add = module.i32.add(left, right); +var ret = module.return(add); - // Export the function, so we can call it later (for simplicity we - // export it as the same name as it has internally) - module.addFunctionExport('adder', 'adder'); +// Create the add function +// Note: no additional local variables (that's the []) +var ii = binaryen.createType([binaryen.i32, binaryen.i32]) +module.addFunction('adder', ii, binaryen.i32, [], ret); - // Print out the text - console.log(module.emitText()); +// Export the function, so we can call it later (for simplicity we +// export it as the same name as it has internally) +module.addFunctionExport('adder', 'adder'); - // Optimize the module! This removes the 'return', since the - // output of the add can just fall through - module.optimize(); +// Print out the text +console.log(module.emitText()); - // Print out the optimized module's text - console.log('optimized:\n\n' + module.emitText()); +// Optimize the module! This removes the 'return', since the +// output of the add can just fall through +module.optimize(); - // Get the binary in typed array form - var binary = module.emitBinary(); - console.log('binary size: ' + binary.length); - console.log(); - assert(module.validate()); +// Print out the optimized module's text +console.log('optimized:\n\n' + module.emitText()); - // We don't need the Binaryen module anymore, so we can tell it to - // clean itself up - module.dispose(); +// Get the binary in typed array form +var binary = module.emitBinary(); +console.log('binary size: ' + binary.length); +console.log(); +assert(module.validate()); - // Compile the binary and create an instance - var wasm = new WebAssembly.Instance(new WebAssembly.Module(binary), {}) - console.log("exports: " + Object.keys(wasm.exports).sort().join(",")); - console.log(); +// We don't need the Binaryen module anymore, so we can tell it to +// clean itself up +module.dispose(); - // Call the code! - console.log('an addition: ' + wasm.exports.adder(40, 2)); -} +// Compile the binary and create an instance +var wasm = new WebAssembly.Instance(new WebAssembly.Module(binary), {}) +console.log("exports: " + Object.keys(wasm.exports).sort().join(",")); +console.log(); -Binaryen.ready.then(test); +// Call the code! +console.log('an addition: ' + wasm.exports.adder(40, 2)); diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index ac101c93d..87e14c3d0 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -1,9 +1,5 @@ // kitchen sink, tests the full API -function assert(x) { - if (!x) throw 'error!'; -} - function cleanInfo(info) { var ret = {}; for (var x in info) { @@ -51,113 +47,113 @@ function makeDroppedInt32(x) { // tests function test_types() { - console.log(" // BinaryenTypeNone: " + Binaryen.none); - console.log(" //", Binaryen.expandType(Binaryen.none)); + console.log(" // BinaryenTypeNone: " + binaryen.none); + console.log(" //", binaryen.expandType(binaryen.none)); - console.log(" // BinaryenTypeUnreachable: " + Binaryen.unreachable); - console.log(" //", Binaryen.expandType(Binaryen.unreachable)); + console.log(" // BinaryenTypeUnreachable: " + binaryen.unreachable); + console.log(" //", binaryen.expandType(binaryen.unreachable)); - console.log(" // BinaryenTypeInt32: " + Binaryen.i32); - console.log(" //", Binaryen.expandType(Binaryen.i32)); + console.log(" // BinaryenTypeInt32: " + binaryen.i32); + console.log(" //", binaryen.expandType(binaryen.i32)); - console.log(" // BinaryenTypeInt64: " + Binaryen.i64); - console.log(" //", Binaryen.expandType(Binaryen.i64)); + console.log(" // BinaryenTypeInt64: " + binaryen.i64); + console.log(" //", binaryen.expandType(binaryen.i64)); - console.log(" // BinaryenTypeFloat32: " + Binaryen.f32); - console.log(" //", Binaryen.expandType(Binaryen.f32)); + console.log(" // BinaryenTypeFloat32: " + binaryen.f32); + console.log(" //", binaryen.expandType(binaryen.f32)); - console.log(" // BinaryenTypeFloat64: " + Binaryen.f64); - console.log(" //", Binaryen.expandType(Binaryen.f64)); + console.log(" // BinaryenTypeFloat64: " + binaryen.f64); + console.log(" //", binaryen.expandType(binaryen.f64)); - console.log(" // BinaryenTypeVec128: " + Binaryen.v128); - console.log(" //", Binaryen.expandType(Binaryen.v128)); + console.log(" // BinaryenTypeVec128: " + binaryen.v128); + console.log(" //", binaryen.expandType(binaryen.v128)); - console.log(" // BinaryenTypeAnyref: " + Binaryen.anyref); - console.log(" //", Binaryen.expandType(Binaryen.anyref)); + console.log(" // BinaryenTypeAnyref: " + binaryen.anyref); + console.log(" //", binaryen.expandType(binaryen.anyref)); - console.log(" // BinaryenTypeExnref: " + Binaryen.exnref); - console.log(" //", Binaryen.expandType(Binaryen.exnref)); + console.log(" // BinaryenTypeExnref: " + binaryen.exnref); + console.log(" //", binaryen.expandType(binaryen.exnref)); - console.log(" // BinaryenTypeAuto: " + Binaryen.auto); + console.log(" // BinaryenTypeAuto: " + binaryen.auto); - var i32_pair = Binaryen.createType([Binaryen.i32, Binaryen.i32]); - console.log(" //", i32_pair, Binaryen.expandType(i32_pair)); + var i32_pair = binaryen.createType([binaryen.i32, binaryen.i32]); + console.log(" //", i32_pair, binaryen.expandType(i32_pair)); - var duplicate_pair = Binaryen.createType([Binaryen.i32, Binaryen.i32]); - console.log(" //", duplicate_pair, Binaryen.expandType(duplicate_pair)); + var duplicate_pair = binaryen.createType([binaryen.i32, binaryen.i32]); + console.log(" //", duplicate_pair, binaryen.expandType(duplicate_pair)); - var f32_pair = Binaryen.createType([Binaryen.f32, Binaryen.f32]); - console.log(" //", f32_pair, Binaryen.expandType(f32_pair)); + var f32_pair = binaryen.createType([binaryen.f32, binaryen.f32]); + console.log(" //", f32_pair, binaryen.expandType(f32_pair)); } function test_features() { - console.log("Binaryen.Features.MVP: " + Binaryen.Features.MVP); - console.log("Binaryen.Features.Atomics: " + Binaryen.Features.Atomics); - console.log("Binaryen.Features.BulkMemory: " + Binaryen.Features.BulkMemory); - console.log("Binaryen.Features.MutableGlobals: " + Binaryen.Features.MutableGlobals); - console.log("Binaryen.Features.NontrappingFPToInt: " + Binaryen.Features.NontrappingFPToInt); - console.log("Binaryen.Features.SignExt: " + Binaryen.Features.SignExt); - console.log("Binaryen.Features.SIMD128: " + Binaryen.Features.SIMD128); - console.log("Binaryen.Features.ExceptionHandling: " + Binaryen.Features.ExceptionHandling); - console.log("Binaryen.Features.TailCall: " + Binaryen.Features.TailCall); - console.log("Binaryen.Features.ReferenceTypes: " + Binaryen.Features.ReferenceTypes); - console.log("Binaryen.Features.All: " + Binaryen.Features.All); + console.log("Features.MVP: " + binaryen.Features.MVP); + console.log("Features.Atomics: " + binaryen.Features.Atomics); + console.log("Features.BulkMemory: " + binaryen.Features.BulkMemory); + console.log("Features.MutableGlobals: " + binaryen.Features.MutableGlobals); + console.log("Features.NontrappingFPToInt: " + binaryen.Features.NontrappingFPToInt); + console.log("Features.SignExt: " + binaryen.Features.SignExt); + console.log("Features.SIMD128: " + binaryen.Features.SIMD128); + console.log("Features.ExceptionHandling: " + binaryen.Features.ExceptionHandling); + console.log("Features.TailCall: " + binaryen.Features.TailCall); + console.log("Features.ReferenceTypes: " + binaryen.Features.ReferenceTypes); + console.log("Features.All: " + binaryen.Features.All); } function test_ids() { - console.log("BinaryenInvalidId: " + Binaryen.InvalidId); - console.log("BinaryenBlockId: " + Binaryen.BlockId); - console.log("BinaryenIfId: " + Binaryen.IfId); - console.log("BinaryenLoopId: " + Binaryen.LoopId); - console.log("BinaryenBreakId: " + Binaryen.BreakId); - console.log("BinaryenSwitchId: " + Binaryen.SwitchId); - console.log("BinaryenCallId: " + Binaryen.CallId); - console.log("BinaryenCallIndirectId: " + Binaryen.CallIndirectId); - console.log("BinaryenLocalGetId: " + Binaryen.LocalGetId); - console.log("BinaryenLocalSetId: " + Binaryen.LocalSetId); - console.log("BinaryenGlobalGetId: " + Binaryen.GlobalGetId); - console.log("BinaryenGlobalSetId: " + Binaryen.GlobalSetId); - console.log("BinaryenLoadId: " + Binaryen.LoadId); - console.log("BinaryenStoreId: " + Binaryen.StoreId); - console.log("BinaryenConstId: " + Binaryen.ConstId); - console.log("BinaryenUnaryId: " + Binaryen.UnaryId); - console.log("BinaryenBinaryId: " + Binaryen.BinaryId); - console.log("BinaryenSelectId: " + Binaryen.SelectId); - console.log("BinaryenDropId: " + Binaryen.DropId); - console.log("BinaryenReturnId: " + Binaryen.ReturnId); - console.log("BinaryenHostId: " + Binaryen.HostId); - console.log("BinaryenNopId: " + Binaryen.NopId); - console.log("BinaryenUnreachableId: " + Binaryen.UnreachableId); - console.log("BinaryenAtomicCmpxchgId: " + Binaryen.AtomicCmpxchgId); - console.log("BinaryenAtomicRMWId: " + Binaryen.AtomicRMWId); - console.log("BinaryenAtomicWaitId: " + Binaryen.AtomicWaitId); - console.log("BinaryenAtomicNotifyId: " + Binaryen.AtomicNotifyId); - console.log("BinaryenSIMDExtractId: " + Binaryen.SIMDExtractId); - console.log("BinaryenSIMDReplaceId: " + Binaryen.SIMDReplaceId); - console.log("BinaryenSIMDShuffleId: " + Binaryen.SIMDShuffleId); - console.log("BinaryenSIMDTernaryId: " + Binaryen.SIMDTernaryId); - console.log("BinaryenSIMDShiftId: " + Binaryen.SIMDShiftId); - console.log("BinaryenSIMDLoadId: " + Binaryen.SIMDLoadId); - console.log("MemoryInitId: " + Binaryen.MemoryInitId); - console.log("DataDropId: " + Binaryen.DataDropId); - console.log("MemoryCopyId: " + Binaryen.MemoryCopyId); - console.log("MemoryFillId: " + Binaryen.MemoryFillId); - console.log("TryId: " + Binaryen.TryId); - console.log("ThrowId: " + Binaryen.ThrowId); - console.log("RethrowId: " + Binaryen.RethrowId); - console.log("BrOnExnId: " + Binaryen.BrOnExnId); - console.log("PushId: " + Binaryen.PushId); - console.log("PopId: " + Binaryen.PopId); + console.log("InvalidId: " + binaryen.InvalidId); + console.log("BlockId: " + binaryen.BlockId); + console.log("IfId: " + binaryen.IfId); + console.log("LoopId: " + binaryen.LoopId); + console.log("BreakId: " + binaryen.BreakId); + console.log("SwitchId: " + binaryen.SwitchId); + console.log("CallId: " + binaryen.CallId); + console.log("CallIndirectId: " + binaryen.CallIndirectId); + console.log("LocalGetId: " + binaryen.LocalGetId); + console.log("LocalSetId: " + binaryen.LocalSetId); + console.log("GlobalGetId: " + binaryen.GlobalGetId); + console.log("GlobalSetId: " + binaryen.GlobalSetId); + console.log("LoadId: " + binaryen.LoadId); + console.log("StoreId: " + binaryen.StoreId); + console.log("ConstId: " + binaryen.ConstId); + console.log("UnaryId: " + binaryen.UnaryId); + console.log("BinaryId: " + binaryen.BinaryId); + console.log("SelectId: " + binaryen.SelectId); + console.log("DropId: " + binaryen.DropId); + console.log("ReturnId: " + binaryen.ReturnId); + console.log("HostId: " + binaryen.HostId); + console.log("NopId: " + binaryen.NopId); + console.log("UnreachableId: " + binaryen.UnreachableId); + console.log("AtomicCmpxchgId: " + binaryen.AtomicCmpxchgId); + console.log("AtomicRMWId: " + binaryen.AtomicRMWId); + console.log("AtomicWaitId: " + binaryen.AtomicWaitId); + console.log("AtomicNotifyId: " + binaryen.AtomicNotifyId); + console.log("SIMDExtractId: " + binaryen.SIMDExtractId); + console.log("SIMDReplaceId: " + binaryen.SIMDReplaceId); + console.log("SIMDShuffleId: " + binaryen.SIMDShuffleId); + console.log("SIMDTernaryId: " + binaryen.SIMDTernaryId); + console.log("SIMDShiftId: " + binaryen.SIMDShiftId); + console.log("SIMDLoadId: " + binaryen.SIMDLoadId); + console.log("MemoryInitId: " + binaryen.MemoryInitId); + console.log("DataDropId: " + binaryen.DataDropId); + console.log("MemoryCopyId: " + binaryen.MemoryCopyId); + console.log("MemoryFillId: " + binaryen.MemoryFillId); + console.log("TryId: " + binaryen.TryId); + console.log("ThrowId: " + binaryen.ThrowId); + console.log("RethrowId: " + binaryen.RethrowId); + console.log("BrOnExnId: " + binaryen.BrOnExnId); + console.log("PushId: " + binaryen.PushId); + console.log("PopId: " + binaryen.PopId); } function test_core() { // Module creation - module = new Binaryen.Module(); + module = new binaryen.Module(); // Create an event - var event_ = module.addEvent("a-event", 0, Binaryen.i32, Binaryen.none); + var event_ = module.addEvent("a-event", 0, binaryen.i32, binaryen.none); // Literals and consts @@ -168,7 +164,7 @@ function test_core() { constF32Bits = module.f32.const_bits(0xffff1234), constF64Bits = module.f64.const_bits(0x5678abcd, 0xffff1234); - var iIfF = Binaryen.createType([Binaryen.i32, Binaryen.i64, Binaryen.f32, Binaryen.f64]) + var iIfF = binaryen.createType([binaryen.i32, binaryen.i64, binaryen.f32, binaryen.f64]) var temp1 = makeInt32(1), temp2 = makeInt32(2), temp3 = makeInt32(3), temp4 = makeInt32(4), temp5 = makeInt32(5), @@ -459,19 +455,19 @@ function test_core() { module.switch([ "the-value" ], "the-value", temp8, temp9), module.switch([ "the-nothing" ], "the-nothing", makeInt32(2)), module.i32.eqz( // check the output type of the call node - module.call("kitchen()sinker", [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], Binaryen.i32) + module.call("kitchen()sinker", [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], binaryen.i32) ), module.i32.eqz( // check the output type of the call node module.i32.trunc_s.f32( - module.call("an-imported", [ makeInt32(13), makeFloat64(3.7) ], Binaryen.f32) + module.call("an-imported", [ makeInt32(13), makeFloat64(3.7) ], binaryen.f32) ) ), module.i32.eqz( // check the output type of the call node - module.callIndirect(makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], iIfF, Binaryen.i32) + module.callIndirect(makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], iIfF, binaryen.i32) ), - module.drop(module.local.get(0, Binaryen.i32)), + module.drop(module.local.get(0, binaryen.i32)), module.local.set(0, makeInt32(101)), - module.drop(module.local.tee(0, makeInt32(102), Binaryen.i32)), + module.drop(module.local.tee(0, makeInt32(102), binaryen.i32)), module.i32.load(0, 0, makeInt32(1)), module.i64.load16_s(2, 1, makeInt32(8)), module.f32.load(0, 0, makeInt32(2)), @@ -481,13 +477,13 @@ function test_core() { module.select(temp10, temp11, temp12), module.return(makeInt32(1337)), // Tail Call - module.returnCall("kitchen()sinker", [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], Binaryen.i32), - module.returnCallIndirect(makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], iIfF, Binaryen.i32), + module.returnCall("kitchen()sinker", [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], binaryen.i32), + module.returnCallIndirect(makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], iIfF, binaryen.i32), // Reference types module.ref.is_null(module.ref.null()), module.ref.is_null(module.ref.func("kitchen()sinker")), - module.select(temp10, module.ref.null(), module.ref.func("kitchen()sinker"), Binaryen.funcref), + module.select(temp10, module.ref.null(), module.ref.func("kitchen()sinker"), binaryen.funcref), // Exception handling module.try( @@ -498,9 +494,9 @@ function test_core() { module.block("try-block", [ module.rethrow( module.br_on_exn("try-block", "a-event", - module.local.get(5, Binaryen.exnref)), + module.local.get(5, binaryen.exnref)), ) - ], Binaryen.i32) + ], binaryen.i32) ) ] ) @@ -544,13 +540,13 @@ function test_core() { ]; // Test expression utility - console.log("getExpressionInfo=" + JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(valueList[3])))); - console.log(Binaryen.emitText(valueList[3])); // test printing a standalone expression + console.log("getExpressionInfo=" + JSON.stringify(cleanInfo(binaryen.getExpressionInfo(valueList[3])))); + console.log(binaryen.emitText(valueList[3])); // test printing a standalone expression - console.log("getExpressionInfo(i32.const)=" + JSON.stringify(Binaryen.getExpressionInfo(module.i32.const(5)))); - console.log("getExpressionInfo(i64.const)=" + JSON.stringify(Binaryen.getExpressionInfo(module.i64.const(6, 7)))); - console.log("getExpressionInfo(f32.const)=" + JSON.stringify(Binaryen.getExpressionInfo(module.f32.const(8.5)))); - console.log("getExpressionInfo(f64.const)=" + JSON.stringify(Binaryen.getExpressionInfo(module.f64.const(9.5)))); + console.log("getExpressionInfo(i32.const)=" + JSON.stringify(binaryen.getExpressionInfo(module.i32.const(5)))); + console.log("getExpressionInfo(i64.const)=" + JSON.stringify(binaryen.getExpressionInfo(module.i64.const(6, 7)))); + console.log("getExpressionInfo(f32.const)=" + JSON.stringify(binaryen.getExpressionInfo(module.f32.const(8.5)))); + console.log("getExpressionInfo(f64.const)=" + JSON.stringify(binaryen.getExpressionInfo(module.f64.const(9.5)))); // Make the main body of the function. and one block with a return value, one without var value = module.block("the-value", valueList); @@ -559,19 +555,19 @@ function test_core() { var body = module.block("the-body", [ nothing, makeInt32(42) ]); // Create the function - var sinker = module.addFunction("kitchen()sinker", iIfF, Binaryen.i32, [ Binaryen.i32, Binaryen.exnref ], body); + var sinker = module.addFunction("kitchen()sinker", iIfF, binaryen.i32, [ binaryen.i32, binaryen.exnref ], body); // Create a global var initExpr = module.i32.const(1); - var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr) + var global = module.addGlobal("a-global", binaryen.i32, false, initExpr) // Imports - var iF = Binaryen.createType([Binaryen.i32, Binaryen.f64]); - module.addFunctionImport("an-imported", "module", "base", iF, Binaryen.f32); - module.addGlobalImport("a-global-imp", "module", "base", Binaryen.i32, false); - module.addGlobalImport("a-mut-global-imp", "module", "base", Binaryen.i32, true); - module.addEventImport("a-event-imp", "module", "base", 0, Binaryen.i32, Binaryen.none); + var iF = binaryen.createType([binaryen.i32, binaryen.f64]); + module.addFunctionImport("an-imported", "module", "base", iF, binaryen.f32); + module.addGlobalImport("a-global-imp", "module", "base", binaryen.i32, false); + module.addGlobalImport("a-mut-global-imp", "module", "base", binaryen.i32, true); + module.addEventImport("a-event-imp", "module", "base", 0, binaryen.i32, binaryen.none); // Exports @@ -581,7 +577,7 @@ function test_core() { // Function table. One per module - module.setFunctionTable(1, 0xffffffff, [ Binaryen.getFunctionInfo(sinker).name ]); + module.setFunctionTable(1, 0xffffffff, [ binaryen.getFunctionInfo(sinker).name ]); // Memory. One per module @@ -599,13 +595,13 @@ function test_core() { ], true); // Start function. One per module - var starter = module.addFunction("starter", Binaryen.none, Binaryen.none, [], module.nop()); + var starter = module.addFunction("starter", binaryen.none, binaryen.none, [], module.nop()); module.setStart(starter); // A bunch of our code needs drop, auto-add it module.autoDrop(); - var features = Binaryen.Features.All; + var features = binaryen.Features.All; module.setFeatures(features); assert(module.getFeatures() == features); console.log(module.emitText()); @@ -621,67 +617,67 @@ function test_core() { } function makeCallCheck(x) { - return module.call("check", [ makeInt32(x) ], Binaryen.None); + return module.call("check", [ makeInt32(x) ], binaryen.None); } function test_relooper() { - module = new Binaryen.Module(); - var localTypes = [ Binaryen.i32 ]; + module = new binaryen.Module(); + var localTypes = [ binaryen.i32 ]; - module.addFunctionImport("check", "module", "check", Binaryen.i32, Binaryen.none); + module.addFunctionImport("check", "module", "check", binaryen.i32, binaryen.none); { // trivial: just one block - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block = relooper.addBlock(makeCallCheck(1337)); var body = relooper.renderAndDispose(block, 0, module); - module.addFunction("just-one-block", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("just-one-block", binaryen.none, binaryen.none, localTypes, body); } { // two blocks - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); relooper.addBranch(block0, block1); // no condition, no code on branch var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("two-blocks", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("two-blocks", binaryen.none, binaryen.none, localTypes, body); } { // two blocks with code between them - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); relooper.addBranch(block0, block1, null, makeDroppedInt32(77)); // code on branch var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("two-blocks-plus-code", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("two-blocks-plus-code", binaryen.none, binaryen.none, localTypes, body); } { // two blocks in a loop - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); relooper.addBranch(block0, block1, null, null); relooper.addBranch(block1, block0, null, null); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("loop", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("loop", binaryen.none, binaryen.none, localTypes, body); } { // two blocks in a loop with codes - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); relooper.addBranch(block0, block1, null, makeDroppedInt32(33)); relooper.addBranch(block1, block0, null, makeDroppedInt32(-66)); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("loop-plus-code", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("loop-plus-code", binaryen.none, binaryen.none, localTypes, body); } { // split - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); var block2 = relooper.addBlock(makeCallCheck(2)); relooper.addBranch(block0, block1, makeInt32(55), null); relooper.addBranch(block0, block2, null, null); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("split", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("split", binaryen.none, binaryen.none, localTypes, body); } { // split + code - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); var block2 = relooper.addBlock(makeCallCheck(2)); @@ -689,10 +685,10 @@ function test_relooper() { relooper.addBranch(block0, block1, makeInt32(55), temp); relooper.addBranch(block0, block2, null, makeDroppedInt32(20)); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("split-plus-code", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("split-plus-code", binaryen.none, binaryen.none, localTypes, body); } { // if - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); var block2 = relooper.addBlock(makeCallCheck(2)); @@ -700,10 +696,10 @@ function test_relooper() { relooper.addBranch(block0, block2, null, null); relooper.addBranch(block1, block2, null, null); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("if", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("if", binaryen.none, binaryen.none, localTypes, body); } { // if + code - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); var block2 = relooper.addBlock(makeCallCheck(2)); @@ -712,10 +708,10 @@ function test_relooper() { relooper.addBranch(block0, block2, null, makeDroppedInt32(-2)); relooper.addBranch(block1, block2, null, makeDroppedInt32(-3)); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("if-plus-code", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("if-plus-code", binaryen.none, binaryen.none, localTypes, body); } { // if-else - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); var block2 = relooper.addBlock(makeCallCheck(2)); @@ -725,10 +721,10 @@ function test_relooper() { relooper.addBranch(block1, block3, null, null); relooper.addBranch(block2, block3, null, null); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("if-else", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("if-else", binaryen.none, binaryen.none, localTypes, body); } { // loop+tail - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); var block2 = relooper.addBlock(makeCallCheck(2)); @@ -736,10 +732,10 @@ function test_relooper() { relooper.addBranch(block1, block0, makeInt32(10), null); relooper.addBranch(block1, block2, null, null); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("loop-tail", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("loop-tail", binaryen.none, binaryen.none, localTypes, body); } { // nontrivial loop + phi to head - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); var block2 = relooper.addBlock(makeCallCheck(2)); @@ -757,10 +753,10 @@ function test_relooper() { relooper.addBranch(block4, block5, null, null); relooper.addBranch(block5, block6, null, makeDroppedInt32(40)); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("nontrivial-loop-plus-phi-to-head", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("nontrivial-loop-plus-phi-to-head", binaryen.none, binaryen.none, localTypes, body); } { // switch - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); temp = makeInt32(-99); var block0 = relooper.addBlockWithSwitch(makeCallCheck(0), temp); var block1 = relooper.addBlock(makeCallCheck(1)); @@ -770,10 +766,10 @@ function test_relooper() { relooper.addBranchForSwitch(block0, block2, [4], makeDroppedInt32(55)); relooper.addBranchForSwitch(block0, block3, [], null); var body = relooper.renderAndDispose(block0, 0, module); - module.addFunction("switch", Binaryen.none, Binaryen.none, localTypes, body); + module.addFunction("switch", binaryen.none, binaryen.none, localTypes, body); } { // duff's device - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var block0 = relooper.addBlock(makeCallCheck(0)); var block1 = relooper.addBlock(makeCallCheck(1)); var block2 = relooper.addBlock(makeCallCheck(2)); @@ -782,15 +778,15 @@ function test_relooper() { relooper.addBranch(block1, block2, null, null); relooper.addBranch(block2, block1, null, null); var body = relooper.renderAndDispose(block0, 3, module); // use $3 as the helper var - module.addFunction("duffs-device", Binaryen.none, Binaryen.none, [ Binaryen.i32, Binaryen.i32, Binaryen.i64, Binaryen.i32, Binaryen.f32, Binaryen.f64, Binaryen.i32 ], body); + module.addFunction("duffs-device", binaryen.none, binaryen.none, [ binaryen.i32, binaryen.i32, binaryen.i64, binaryen.i32, binaryen.f32, binaryen.f64, binaryen.i32 ], body); } { // return in a block - var relooper = new Binaryen.Relooper(module); + var relooper = new binaryen.Relooper(module); var list = module.block("the-list", [ makeCallCheck(42), module.return(makeInt32(1337)) ]); var block = relooper.addBlock(list); var body = relooper.renderAndDispose(block, 0, module); - module.addFunction("return", Binaryen.none, Binaryen.i32, localTypes, body); + module.addFunction("return", binaryen.none, binaryen.i32, localTypes, body); } console.log("raw:"); @@ -816,19 +812,19 @@ function test_binaries() { var buffer, size; { // create a module and write it to binary - module = new Binaryen.Module(); - module.setFeatures(Binaryen.Features.All); - var ii = Binaryen.createType([Binaryen.i32, Binaryen.i32]); - var x = module.local.get(0, Binaryen.i32), - y = module.local.get(1, Binaryen.i32); + module = new binaryen.Module(); + module.setFeatures(binaryen.Features.All); + var ii = binaryen.createType([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", ii, Binaryen.i32, [], add); + var adder = module.addFunction("adder", ii, binaryen.i32, [], add); var initExpr = module.i32.const(3); - var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr) - var event_ = module.addEvent("a-event", 0, Binaryen.createType([Binaryen.i32, Binaryen.i32]), Binaryen.none); - Binaryen.setDebugInfo(true); // include names section + var global = module.addGlobal("a-global", binaryen.i32, false, initExpr) + var event_ = module.addEvent("a-event", 0, binaryen.createType([binaryen.i32, binaryen.i32]), binaryen.none); + binaryen.setDebugInfo(true); // include names section buffer = module.emitBinary(); - Binaryen.setDebugInfo(false); + binaryen.setDebugInfo(false); size = buffer.length; // write out the module module.dispose(); } @@ -837,8 +833,8 @@ function test_binaries() { assert(size < 512); // this is a tiny module // read the module from the binary - module = Binaryen.readBinary(buffer); - module.setFeatures(Binaryen.Features.All); + module = binaryen.readBinary(buffer); + module.setFeatures(binaryen.Features.All); // validate, print, and free assert(module.validate()); @@ -849,11 +845,11 @@ function test_binaries() { function test_interpret() { // create a simple module with a start method that prints a number, and interpret it, printing that number. - module = new Binaryen.Module(); + module = new binaryen.Module(); - module.addFunctionImport("print-i32", "spectest", "print", Binaryen.i32, Binaryen.none); - call = module.call("print-i32", [ makeInt32(1234) ], Binaryen.None); - var starter = module.addFunction("starter", Binaryen.none, Binaryen.none, [], call); + module.addFunctionImport("print-i32", "spectest", "print", binaryen.i32, binaryen.none); + call = module.call("print-i32", [ makeInt32(1234) ], binaryen.None); + var starter = module.addFunction("starter", binaryen.none, binaryen.none, [], call); module.setStart(starter); console.log(module.emitText()); @@ -864,9 +860,9 @@ function test_interpret() { function test_nonvalid() { // create a module that fails to validate - module = new Binaryen.Module(); + module = new binaryen.Module(); - var func = module.addFunction("func", Binaryen.none, Binaryen.none, [ Binaryen.i32 ], + var func = module.addFunction("func", binaryen.none, binaryen.none, [ binaryen.i32 ], module.local.set(0, makeInt64(1234, 0)) // wrong type! ); @@ -877,28 +873,28 @@ function test_nonvalid() { } function test_tracing() { - Binaryen.setAPITracing(1); + binaryen.setAPITracing(1); test_core(); test_relooper(); test_types(); - Binaryen.setAPITracing(0); + binaryen.setAPITracing(0); } function test_parsing() { var text; // create a module and write it to text - module = new Binaryen.Module(); - module.setFeatures(Binaryen.Features.All); + module = new binaryen.Module(); + module.setFeatures(binaryen.Features.All); - var ii = Binaryen.createType([Binaryen.i32, Binaryen.i32]); - var x = module.local.get(0, Binaryen.i32), - y = module.local.get(1, Binaryen.i32); + var ii = binaryen.createType([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", ii, Binaryen.i32, [], add); + var adder = module.addFunction("adder", ii, binaryen.i32, [], add); var initExpr = module.i32.const(3); - var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr) - var event_ = module.addEvent("a-event", 0, Binaryen.i32, Binaryen.none); + var global = module.addGlobal("a-global", binaryen.i32, false, initExpr) + var event_ = module.addEvent("a-event", 0, binaryen.i32, binaryen.none); text = module.emitText(); module.dispose(); module = null; @@ -906,8 +902,8 @@ function test_parsing() { text = text.replace('adder', 'ADD_ER'); - var module2 = Binaryen.parseText(text); - module2.setFeatures(Binaryen.Features.All); + var module2 = binaryen.parseText(text); + module2.setFeatures(binaryen.Features.All); assert(module2.validate()); console.log("module loaded from text form:"); console.log(module2.emitText()); @@ -915,16 +911,16 @@ function test_parsing() { } function test_internals() { - console.log('sizeof Literal: ' + Binaryen['_BinaryenSizeofLiteral']()); + console.log('sizeof Literal: ' + binaryen['_BinaryenSizeofLiteral']()); } function test_for_each() { - module = new Binaryen.Module(); + module = new binaryen.Module(); var fns = [ - module.addFunction("fn0", Binaryen.none, Binaryen.none, [], module.nop()), - module.addFunction("fn1", Binaryen.none, Binaryen.none, [], module.nop()), - module.addFunction("fn2", Binaryen.none, Binaryen.none, [], module.nop()) + module.addFunction("fn0", binaryen.none, binaryen.none, [], module.nop()), + module.addFunction("fn1", binaryen.none, binaryen.none, [], module.nop()), + module.addFunction("fn2", binaryen.none, binaryen.none, [], module.nop()) ]; var i; @@ -945,7 +941,7 @@ function test_for_each() { var expected_offsets = [10, 125]; var expected_data = ["hello, world", "segment data 2"]; - var global = module.addGlobal("a-global", Binaryen.i32, false, module.i32.const(expected_offsets[1])) + var global = module.addGlobal("a-global", binaryen.i32, false, module.i32.const(expected_offsets[1])) module.setMemory(1, 256, "mem", [ { passive: false, @@ -971,32 +967,28 @@ function test_for_each() { } function test_expression_info() { - module = new Binaryen.Module(); + module = new binaryen.Module(); // Issue #2392 - console.log("getExpressionInfo(memory.grow)=" + JSON.stringify(Binaryen.getExpressionInfo(module.memory.grow(1)))); + console.log("getExpressionInfo(memory.grow)=" + JSON.stringify(binaryen.getExpressionInfo(module.memory.grow(1)))); // Issue #2396 - console.log("getExpressionInfo(switch)=" + JSON.stringify(Binaryen.getExpressionInfo(module.switch([ "label" ], "label", 0)))); + console.log("getExpressionInfo(switch)=" + JSON.stringify(binaryen.getExpressionInfo(module.switch([ "label" ], "label", 0)))); module.dispose(); } -function test() { - // Tracing must be first so it starts with a fresh set of interned types - test_tracing(); - test_types(); - test_features(); - test_ids(); - test_core(); - test_relooper(); - test_binaries(); - test_interpret(); - test_nonvalid(); - test_parsing(); - test_internals(); - test_for_each(); - test_expression_info(); -} - -Binaryen.ready.then(test); +// Tracing must be first so it starts with a fresh set of interned types +test_tracing(); +test_types(); +test_features(); +test_ids(); +test_core(); +test_relooper(); +test_binaries(); +test_interpret(); +test_nonvalid(); +test_parsing(); +test_internals(); +test_for_each(); +test_expression_info(); diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index 7e0615ffd..c86b276d5 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -6272,50 +6272,50 @@ optimized: // 13 [ 2, 2 ] // 13 [ 2, 2 ] // 14 [ 4, 4 ] -Binaryen.Features.MVP: 0 -Binaryen.Features.Atomics: 1 -Binaryen.Features.BulkMemory: 16 -Binaryen.Features.MutableGlobals: 2 -Binaryen.Features.NontrappingFPToInt: 4 -Binaryen.Features.SignExt: 32 -Binaryen.Features.SIMD128: 8 -Binaryen.Features.ExceptionHandling: 64 -Binaryen.Features.TailCall: 128 -Binaryen.Features.ReferenceTypes: 256 -Binaryen.Features.All: 511 -BinaryenInvalidId: 0 -BinaryenBlockId: 1 -BinaryenIfId: 2 -BinaryenLoopId: 3 -BinaryenBreakId: 4 -BinaryenSwitchId: 5 -BinaryenCallId: 6 -BinaryenCallIndirectId: 7 -BinaryenLocalGetId: 8 -BinaryenLocalSetId: 9 -BinaryenGlobalGetId: 10 -BinaryenGlobalSetId: 11 -BinaryenLoadId: 12 -BinaryenStoreId: 13 -BinaryenConstId: 14 -BinaryenUnaryId: 15 -BinaryenBinaryId: 16 -BinaryenSelectId: 17 -BinaryenDropId: 18 -BinaryenReturnId: 19 -BinaryenHostId: 20 -BinaryenNopId: 21 -BinaryenUnreachableId: 22 -BinaryenAtomicCmpxchgId: 24 -BinaryenAtomicRMWId: 23 -BinaryenAtomicWaitId: 25 -BinaryenAtomicNotifyId: 26 -BinaryenSIMDExtractId: 28 -BinaryenSIMDReplaceId: 29 -BinaryenSIMDShuffleId: 30 -BinaryenSIMDTernaryId: 31 -BinaryenSIMDShiftId: 32 -BinaryenSIMDLoadId: 33 +Features.MVP: 0 +Features.Atomics: 1 +Features.BulkMemory: 16 +Features.MutableGlobals: 2 +Features.NontrappingFPToInt: 4 +Features.SignExt: 32 +Features.SIMD128: 8 +Features.ExceptionHandling: 64 +Features.TailCall: 128 +Features.ReferenceTypes: 256 +Features.All: 511 +InvalidId: 0 +BlockId: 1 +IfId: 2 +LoopId: 3 +BreakId: 4 +SwitchId: 5 +CallId: 6 +CallIndirectId: 7 +LocalGetId: 8 +LocalSetId: 9 +GlobalGetId: 10 +GlobalSetId: 11 +LoadId: 12 +StoreId: 13 +ConstId: 14 +UnaryId: 15 +BinaryId: 16 +SelectId: 17 +DropId: 18 +ReturnId: 19 +HostId: 20 +NopId: 21 +UnreachableId: 22 +AtomicCmpxchgId: 24 +AtomicRMWId: 23 +AtomicWaitId: 25 +AtomicNotifyId: 26 +SIMDExtractId: 28 +SIMDReplaceId: 29 +SIMDShuffleId: 30 +SIMDTernaryId: 31 +SIMDShiftId: 32 +SIMDLoadId: 33 MemoryInitId: 34 DataDropId: 35 MemoryCopyId: 36 diff --git a/test/binaryen.js/optimize-levels.js b/test/binaryen.js/optimize-levels.js index b3ae66a43..b3dd2adbd 100644 --- a/test/binaryen.js/optimize-levels.js +++ b/test/binaryen.js/optimize-levels.js @@ -1,7 +1,3 @@ -function assert(x) { - if (!x) throw 'error!'; -} - var wast = ` (module (type $i (func (param i32) (result i32))) @@ -19,51 +15,47 @@ var wast = ` ) `; -function test() { - console.log("=== input wast ===" + wast); - - function printOptions() { - console.log("optimizeLevel=" + Binaryen.getOptimizeLevel()); - console.log("shrinkLevel=" + Binaryen.getShrinkLevel()); - } - - // Use defaults (should be equal to -Os below) - var module = Binaryen.parseText(wast); - - console.log("=== unoptimized ==="); - assert(module.validate()); - console.log(module.emitText()); - - module.optimize(); - console.log("=== optimized using defaults ==="); - printOptions(); - assert(module.validate()); - console.log(module.emitText()); - module.dispose(); - - // Use -O0 (should remove the block) - module = Binaryen.parseText(wast); - - Binaryen.setOptimizeLevel(0); - Binaryen.setShrinkLevel(0); - module.optimize(); - console.log("=== optimized with -O0 ==="); - printOptions(); - assert(module.validate()); - console.log(module.emitText()); - module.dispose(); - - // Use -Os (should remove the block and convert to a select) - module = Binaryen.parseText(wast); +console.log("=== input wast ===" + wast); - Binaryen.setOptimizeLevel(2); - Binaryen.setShrinkLevel(1); - module.optimize(); - console.log("=== optimized with -Os ==="); - printOptions(); - assert(module.validate()); - console.log(module.emitText()); - module.dispose(); +function printOptions() { + console.log("optimizeLevel=" + binaryen.getOptimizeLevel()); + console.log("shrinkLevel=" + binaryen.getShrinkLevel()); } -Binaryen.ready.then(test); +// Use defaults (should be equal to -Os below) +var module = binaryen.parseText(wast); + +console.log("=== unoptimized ==="); +assert(module.validate()); +console.log(module.emitText()); + +module.optimize(); +console.log("=== optimized using defaults ==="); +printOptions(); +assert(module.validate()); +console.log(module.emitText()); +module.dispose(); + +// Use -O0 (should remove the block) +module = binaryen.parseText(wast); + +binaryen.setOptimizeLevel(0); +binaryen.setShrinkLevel(0); +module.optimize(); +console.log("=== optimized with -O0 ==="); +printOptions(); +assert(module.validate()); +console.log(module.emitText()); +module.dispose(); + +// Use -Os (should remove the block and convert to a select) +module = binaryen.parseText(wast); + +binaryen.setOptimizeLevel(2); +binaryen.setShrinkLevel(1); +module.optimize(); +console.log("=== optimized with -Os ==="); +printOptions(); +assert(module.validate()); +console.log(module.emitText()); +module.dispose(); diff --git a/test/binaryen.js/push-pop.js b/test/binaryen.js/push-pop.js index 2b50b2dca..042ed17d6 100644 --- a/test/binaryen.js/push-pop.js +++ b/test/binaryen.js/push-pop.js @@ -1,7 +1,3 @@ -function assert(x) { - if (!x) throw 'error!'; -} - function cleanInfo(info) { var ret = {}; for (var x in info) { @@ -13,40 +9,35 @@ function cleanInfo(info) { } function stringify(expr) { - return JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(expr))); + return JSON.stringify(cleanInfo(binaryen.getExpressionInfo(expr))); } -function test() { - var module = new Binaryen.Module(); +var module = new binaryen.Module(); - var func = module.addFunction("func", Binaryen.none, Binaryen.none, [], - module.block(null, [ - module.push(module.i32.pop()), - module.push(module.i64.pop()), - module.push(module.f32.pop()), - module.push(module.f64.pop()), - module.push(module.v128.pop()), - module.push(module.funcref.pop()), - module.push(module.anyref.pop()), - module.push(module.nullref.pop()), - module.push(module.exnref.pop()) - ] - ) - ) +var func = module.addFunction("func", binaryen.none, binaryen.none, [], + module.block(null, [ + module.push(module.i32.pop()), + module.push(module.i64.pop()), + module.push(module.f32.pop()), + module.push(module.f64.pop()), + module.push(module.v128.pop()), + module.push(module.funcref.pop()), + module.push(module.anyref.pop()), + module.push(module.nullref.pop()), + module.push(module.exnref.pop()) + ]) +) - assert(module.validate()); - console.log(module.emitText()); - - console.log("getExpressionInfo(i32.pop) = " + stringify(module.i32.pop())); - console.log("getExpressionInfo(i64.pop) = " + stringify(module.i64.pop())); - console.log("getExpressionInfo(f32.pop) = " + stringify(module.f32.pop())); - console.log("getExpressionInfo(f64.pop) = " + stringify(module.f64.pop())); - console.log("getExpressionInfo(v128.pop) = " + stringify(module.v128.pop())); - console.log("getExpressionInfo(funcref.pop) = " + stringify(module.funcref.pop())); - console.log("getExpressionInfo(anyref.pop) = " + stringify(module.anyref.pop())); - console.log("getExpressionInfo(nullref.pop) = " + stringify(module.nullref.pop())); - console.log("getExpressionInfo(exnref.pop) = " + stringify(module.exnref.pop())); - console.log("getExpressionInfo(push) = " + stringify(module.push(module.i32.const(0)))); -} +assert(module.validate()); +console.log(module.emitText()); -Binaryen.ready.then(test); +console.log("getExpressionInfo(i32.pop) = " + stringify(module.i32.pop())); +console.log("getExpressionInfo(i64.pop) = " + stringify(module.i64.pop())); +console.log("getExpressionInfo(f32.pop) = " + stringify(module.f32.pop())); +console.log("getExpressionInfo(f64.pop) = " + stringify(module.f64.pop())); +console.log("getExpressionInfo(v128.pop) = " + stringify(module.v128.pop())); +console.log("getExpressionInfo(funcref.pop) = " + stringify(module.funcref.pop())); +console.log("getExpressionInfo(anyref.pop) = " + stringify(module.anyref.pop())); +console.log("getExpressionInfo(nullref.pop) = " + stringify(module.nullref.pop())); +console.log("getExpressionInfo(exnref.pop) = " + stringify(module.exnref.pop())); +console.log("getExpressionInfo(push) = " + stringify(module.push(module.i32.const(0)))); diff --git a/test/binaryen.js/reloc.js b/test/binaryen.js/reloc.js index e9fdd6012..bb011916d 100644 --- a/test/binaryen.js/reloc.js +++ b/test/binaryen.js/reloc.js @@ -1,29 +1,21 @@ -function assert(x) { - if (!x) throw 'error!'; -} +var module = new binaryen.Module(); -function test() { - var module = new Binaryen.Module(); +// memory with offset - // memory with offset +module.addGlobalImport("memory_base", "env", "memory_base", binaryen.i32, false); +module.setMemory(1, -1, null, [ + { + offset: module.global.get("memory_base", binaryen.i32), + data: "data data".split('').map(function(x) { return x.charCodeAt(0) }) + } +]); - module.addGlobalImport("memory_base", "env", "memory_base", Binaryen.i32, false); - module.setMemory(1, -1, null, [ - { - offset: module.global.get("memory_base", Binaryen.i32), - data: "data data".split('').map(function(x) { return x.charCodeAt(0) }) - } - ]); +// table with offset - // table with offset +var func = module.addFunction("func", binaryen.none, binaryen.none, [], module.nop()); - var func = module.addFunction("func", Binaryen.none, Binaryen.none, [], module.nop()); +module.addGlobalImport("table_base", "env", "table_base", binaryen.i32, false); +module.setFunctionTable(1, -1, [ "func", "func" ], module.global.get("table_base", binaryen.i32)); - module.addGlobalImport("table_base", "env", "table_base", Binaryen.i32, false); - module.setFunctionTable(1, -1, [ "func", "func" ], module.global.get("table_base", Binaryen.i32)); - - assert(module.validate()); - console.log(module.emitText()); -} - -Binaryen.ready.then(test); +assert(module.validate()); +console.log(module.emitText()); diff --git a/test/binaryen.js/sieve.js b/test/binaryen.js/sieve.js index ef7c6cca8..4ba61a434 100644 --- a/test/binaryen.js/sieve.js +++ b/test/binaryen.js/sieve.js @@ -1,79 +1,75 @@ -function test() { - // Create a module to work on - var module = new Binaryen.Module(); +// Create a module to work on +var module = new binaryen.Module(); - // Set a memory of initially one page, maximum 100 pages - module.setMemory(1, 100); +// Set a memory of initially one page, maximum 100 pages +module.setMemory(1, 100); - var body = module.block( - null, - [ - // if the current memory size is too small, grow it - module.if( - module.i32.lt_u( - module.i32.mul( - module.memory.size(), - module.i32.const(65536) - ), - module.local.get(0, Binaryen.i32) +var body = module.block( + null, + [ + // if the current memory size is too small, grow it + module.if( + module.i32.lt_u( + module.i32.mul( + module.memory.size(), + module.i32.const(65536) ), - module.drop( - module.memory.grow( - module.i32.sub( - module.i32.div_u( - module.i32.add( - module.local.get(0, Binaryen.i32), - module.i32.const(65535) - ), - module.i32.const(65536) + module.local.get(0, binaryen.i32) + ), + module.drop( + module.memory.grow( + module.i32.sub( + module.i32.div_u( + module.i32.add( + module.local.get(0, binaryen.i32), + module.i32.const(65535) ), - module.memory.size() - ) + module.i32.const(65536) + ), + module.memory.size() ) ) + ) + ), + // first, clear memory + module.local.set(1, module.i32.const(0)), + module.loop('clear', module.block(null, [ + module.i32.store8(0, 1, + module.local.get(1, binaryen.i32), + module.i32.const(0) ), - // first, clear memory - module.local.set(1, module.i32.const(0)), - module.loop('clear', module.block(null, [ - module.i32.store8(0, 1, - module.local.get(1, Binaryen.i32), - module.i32.const(0) - ), - module.local.set(1, module.i32.add( - module.local.get(1, Binaryen.i32), - module.i32.const(1) - )), - module.br_if('clear', module.i32.eq( - module.local.get(1, Binaryen.i32), - module.local.get(0, Binaryen.i32) - )) - ])), - // perform the sieve TODO - // calculate how many primes there are - module.return(module.local.get(0, Binaryen.i32)) - ], - Binaryen.none - ); - - // Create the add function - // Note: no additional local variables (that's the []) - module.addFunction('sieve', Binaryen.i32, Binaryen.i32, [Binaryen.i32], body); + module.local.set(1, module.i32.add( + module.local.get(1, binaryen.i32), + module.i32.const(1) + )), + module.br_if('clear', module.i32.eq( + module.local.get(1, binaryen.i32), + module.local.get(0, binaryen.i32) + )) + ])), + // perform the sieve TODO + // calculate how many primes there are + module.return(module.local.get(0, binaryen.i32)) + ], + binaryen.none +); - // Export the function, so we can call it later (for simplicity we - // export it as the same name as it has internally) - module.addFunctionExport('sieve', 'sieve'); +// Create the add function +// Note: no additional local variables (that's the []) +module.addFunction('sieve', binaryen.i32, binaryen.i32, [binaryen.i32], body); - if (!module.validate()) throw 'did not validate :('; +// Export the function, so we can call it later (for simplicity we +// export it as the same name as it has internally) +module.addFunctionExport('sieve', 'sieve'); - // Print out the text - console.log(module.emitText()); +if (!module.validate()) throw 'did not validate :('; - // Optimize the module! This removes the 'return', since the - // output of the add can just fall through - module.optimize(); +// Print out the text +console.log(module.emitText()); - // Print out the optimized module's text - console.log('optimized:\n\n' + module.emitText()); -} +// Optimize the module! This removes the 'return', since the +// output of the add can just fall through +module.optimize(); -Binaryen.ready.then(test); +// Print out the optimized module's text +console.log('optimized:\n\n' + module.emitText()); diff --git a/test/binaryen.js/simd.js b/test/binaryen.js/simd.js index 68785f9d7..347bb8682 100644 --- a/test/binaryen.js/simd.js +++ b/test/binaryen.js/simd.js @@ -1,9 +1,5 @@ -function test() { - var module = new Binaryen.Module(); +var module = new binaryen.Module(); - var expr = module.v128.const([1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]); - var info = Binaryen.getExpressionInfo(expr); - console.log("v128.const i8x16 0x" + info.value.map(b => b.toString(16)).join(" 0x")); -} - -Binaryen.ready.then(test); +var expr = module.v128.const([1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]); +var info = binaryen.getExpressionInfo(expr); +console.log("v128.const i8x16 0x" + info.value.map(b => b.toString(16)).join(" 0x")); diff --git a/test/binaryen.js/sourcemap.js b/test/binaryen.js/sourcemap.js index f8deecf3f..90f41c720 100644 --- a/test/binaryen.js/sourcemap.js +++ b/test/binaryen.js/sourcemap.js @@ -1,46 +1,38 @@ -function assert(x) { - if (!x) throw 'error!'; -} - -function test() { - var module = new Binaryen.Module(); +var module = new binaryen.Module(); - var fileIndex = module.addDebugInfoFileName("module.c"); +var fileIndex = module.addDebugInfoFileName("module.c"); - console.log(module.getDebugInfoFileName(fileIndex)); - console.log(); +console.log(module.getDebugInfoFileName(fileIndex)); +console.log(); - var expr = module.i32.const(1); - var body = module.block("", [ - expr - ], Binaryen.i32); +var expr = module.i32.const(1); +var body = module.block("", [ + expr +], binaryen.i32); - var func = module.addFunction("main", Binaryen.none, Binaryen.i32, [], body); +var func = module.addFunction("main", binaryen.none, binaryen.i32, [], body); - module.setDebugLocation(func, expr, fileIndex, 1, 2); - module.setDebugLocation(func, body, fileIndex, 0, 3); +module.setDebugLocation(func, expr, fileIndex, 1, 2); +module.setDebugLocation(func, body, fileIndex, 0, 3); - var output = module.emitBinary("module.wasm.map"); - assert(module.validate()); +var output = module.emitBinary("module.wasm.map"); +assert(module.validate()); - function dumpBinary(buffer) { - var hex = [], o, b, h; - for (var i = 0; i < buffer.length; ++i) { - o = i.toString(16); - while (o.length < 3) o = "0" + o; - if ((i & 15) === 0) hex.push((i ? "\n" : "") + o + ":"); - if ((b = buffer[i]) >= 0x21 && b <= 0x7e) - h = String.fromCharCode(b) + ' '; - else if ((h = b.toString(16)).length < 2) - h = "0" + h; - hex.push(h); - } - console.log(hex.join(" ")); +function dumpBinary(buffer) { + var hex = [], o, b, h; + for (var i = 0; i < buffer.length; ++i) { + o = i.toString(16); + while (o.length < 3) o = "0" + o; + if ((i & 15) === 0) hex.push((i ? "\n" : "") + o + ":"); + if ((b = buffer[i]) >= 0x21 && b <= 0x7e) + h = String.fromCharCode(b) + ' '; + else if ((h = b.toString(16)).length < 2) + h = "0" + h; + hex.push(h); } - - dumpBinary(output.binary); - console.log(); - console.log(output.sourceMap); + console.log(hex.join(" ")); } -Binaryen.ready.then(test); +dumpBinary(output.binary); +console.log(); +console.log(output.sourceMap); diff --git a/test/binaryen.js/stackir.js b/test/binaryen.js/stackir.js index 324a99abe..20754e078 100644 --- a/test/binaryen.js/stackir.js +++ b/test/binaryen.js/stackir.js @@ -1,7 +1,3 @@ -function assert(x) { - if (!x) throw 'error!'; -} - var wast = ` (module (type $i (func (param i32) (result i32))) @@ -21,17 +17,13 @@ var wast = ` ) `; -function test() { - console.log("=== input wast ===" + wast); - - var module = Binaryen.parseText(wast); - assert(module.validate()); +console.log("=== input wast ===" + wast); - console.log("=== default ==="); - console.log(module.emitStackIR()); +var module = binaryen.parseText(wast); +assert(module.validate()); - console.log("=== optimize ==="); // should omit the second block - console.log(module.emitStackIR(true)); -} +console.log("=== default ==="); +console.log(module.emitStackIR()); -Binaryen.ready.then(test); +console.log("=== optimize ==="); // should omit the second block +console.log(module.emitStackIR(true)); diff --git a/test/binaryen.js/validation_errors.js b/test/binaryen.js/validation_errors.js index 1251d37e6..57e37d8ba 100644 --- a/test/binaryen.js/validation_errors.js +++ b/test/binaryen.js/validation_errors.js @@ -1,29 +1,25 @@ -function test() { - (function() { - var mod = new Binaryen.Module(); - var func = mod.addFunction("test", Binaryen.none, Binaryen.none, [], - mod.block("", [ - mod.drop( - mod.global.get("missing", Binaryen.i32) - ) - ]) - ); - mod.addExport("test", func); - console.log(mod.validate()) - })(); +(function() { + var mod = new binaryen.Module(); + var func = mod.addFunction("test", binaryen.none, binaryen.none, [], + mod.block("", [ + mod.drop( + mod.global.get("missing", binaryen.i32) + ) + ]) + ); + mod.addExport("test", func); + console.log(mod.validate()) +})(); - (function() { - var mod = new Binaryen.Module(); - var func = mod.addFunction("test", Binaryen.none, Binaryen.none, [], - mod.block("", [ - mod.drop( - mod.local.get(0, Binaryen.i32) - ) - ]) - ); - mod.addFunctionExport("test", "test", func); - console.log(mod.validate()) - })(); -} - -Binaryen.ready.then(test); +(function() { + var mod = new binaryen.Module(); + var func = mod.addFunction("test", binaryen.none, binaryen.none, [], + mod.block("", [ + mod.drop( + mod.local.get(0, binaryen.i32) + ) + ]) + ); + mod.addFunctionExport("test", "test", func); + console.log(mod.validate()) +})(); |