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 | 14 | ||||
-rw-r--r-- | test/binaryen.js/debug-info.js | 68 | ||||
-rw-r--r-- | test/binaryen.js/emit_asmjs.js | 14 | ||||
-rw-r--r-- | test/binaryen.js/event.js | 34 | ||||
-rw-r--r-- | test/binaryen.js/exception-handling.js | 84 | ||||
-rw-r--r-- | test/binaryen.js/functions.js | 38 | ||||
-rw-r--r-- | test/binaryen.js/global.js | 42 | ||||
-rw-r--r-- | test/binaryen.js/hello-world.js | 96 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js | 12 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js.txt | 10 | ||||
-rw-r--r-- | test/binaryen.js/optimize-levels.js | 77 | ||||
-rw-r--r-- | test/binaryen.js/push-pop.js | 50 | ||||
-rw-r--r-- | test/binaryen.js/reloc.js | 34 | ||||
-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 | 74 | ||||
-rw-r--r-- | test/binaryen.js/stackir.js | 19 | ||||
-rw-r--r-- | test/binaryen.js/validation_errors.js | 52 |
19 files changed, 544 insertions, 472 deletions
diff --git a/test/binaryen.js/atomics.js b/test/binaryen.js/atomics.js index d19a8e89d..1374da804 100644 --- a/test/binaryen.js/atomics.js +++ b/test/binaryen.js/atomics.js @@ -2,88 +2,94 @@ function assert(x) { if (!x) throw 'error!'; } -var module = Binaryen.parseText(` +var wast = ` (module (memory $0 (shared 1 1)) ) -`); +`; -// 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( +function test() { + 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, 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.const(0) - ) - ), - module.drop( - module.i64.atomic.wait( + module.i64.atomic.load(0, + module.i32.const(0) + ) + ), + // i64 as u8 + module.i64.atomic.store8(0, module.i32.const(0), - module.i64.const(0), - module.i64.const(0) - ) - ), - module.drop( - module.atomic.notify( + module.i64.atomic.load8_u(0, + module.i32.const(0) + ) + ), + // i64 as u16 + module.i64.atomic.store16(0, module.i32.const(0), - module.i32.const(0) - ) - ), - // fence - module.atomic.fence() -])); + 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.setFeatures(Binaryen.Features.Atomics); -assert(module.validate()); -console.log(module.emitText()); +Binaryen.ready.then(test); diff --git a/test/binaryen.js/custom-section.js b/test/binaryen.js/custom-section.js index f61af0096..2ecd39025 100644 --- a/test/binaryen.js/custom-section.js +++ b/test/binaryen.js/custom-section.js @@ -2,10 +2,14 @@ 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()); + assert(module.validate()); + console.log(module.emitText()); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/debug-info.js b/test/binaryen.js/debug-info.js index d1634f10e..a769d8911 100644 --- a/test/binaryen.js/debug-info.js +++ b/test/binaryen.js/debug-info.js @@ -11,37 +11,41 @@ var wast = ` ) `; -// 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(); +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(); + // 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(); -// 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(); + // 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(); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/emit_asmjs.js b/test/binaryen.js/emit_asmjs.js index 9d5a3966d..751712592 100644 --- a/test/binaryen.js/emit_asmjs.js +++ b/test/binaryen.js/emit_asmjs.js @@ -2,12 +2,16 @@ 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()); + console.log(module.emitAsmjs()); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/event.js b/test/binaryen.js/event.js index 3931b3440..f728e9228 100644 --- a/test/binaryen.js/event.js +++ b/test/binaryen.js/event.js @@ -10,26 +10,30 @@ function cleanInfo(info) { return ret; } -var module = new Binaryen.Module(); -module.setFeatures(Binaryen.Features.ExceptionHandling); +function test() { + 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"); + module.removeExport("a-event-exp"); + module.removeEvent("a-event"); -assert(module.validate()); -console.log(module.emitText()); + assert(module.validate()); + console.log(module.emitText()); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/exception-handling.js b/test/binaryen.js/exception-handling.js index 5d84c1365..6a1b32ed7 100644 --- a/test/binaryen.js/exception-handling.js +++ b/test/binaryen.js/exception-handling.js @@ -16,44 +16,48 @@ function stringify(expr) { return JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(expr))); } -var module = new Binaryen.Module(); -module.setFeatures(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) +function test() { + var module = new Binaryen.Module(); + module.setFeatures(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_)); + ); + 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); diff --git a/test/binaryen.js/functions.js b/test/binaryen.js/functions.js index b2172d005..0a3aa2243 100644 --- a/test/binaryen.js/functions.js +++ b/test/binaryen.js/functions.js @@ -12,27 +12,31 @@ function cleanInfo(info) { return ret; } -var module = new Binaryen.Module(); +function test() { + 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()); + assert(module.validate()); -console.log(module.emitText()); + console.log(module.emitText()); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/global.js b/test/binaryen.js/global.js index 562de7360..48571ef93 100644 --- a/test/binaryen.js/global.js +++ b/test/binaryen.js/global.js @@ -12,30 +12,34 @@ function cleanInfo(info) { return ret; } -var module = new Binaryen.Module(); -module.setFeatures(Binaryen.Features.MVP | Binaryen.Features.MutableGlobals); +function test() { + 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"); + module.removeGlobal("a-global"); + module.removeExport("a-global-exp"); -assert(module.validate()); -console.log(module.emitText()); + assert(module.validate()); + console.log(module.emitText()); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/hello-world.js b/test/binaryen.js/hello-world.js index 414e5bfd1..d14c97912 100644 --- a/test/binaryen.js/hello-world.js +++ b/test/binaryen.js/hello-world.js @@ -5,49 +5,53 @@ function assert(x) { // "hello world" type example: create a function that adds two i32s and // returns the result -// 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 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); - -// 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'); - -// Print out the text -console.log(module.emitText()); - -// Optimize the module! This removes the 'return', since the -// output of the add can just fall through -module.optimize(); - -// Print out the optimized module's text -console.log('optimized:\n\n' + module.emitText()); - -// Get the binary in typed array form -var binary = module.emitBinary(); -console.log('binary size: ' + binary.length); -console.log(); -assert(module.validate()); - -// We don't need the Binaryen module anymore, so we can tell it to -// clean itself up -module.dispose(); - -// 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(); - -// Call the code! -console.log('an addition: ' + wasm.exports.adder(40, 2)); +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 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); + + // 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'); + + // Print out the text + console.log(module.emitText()); + + // Optimize the module! This removes the 'return', since the + // output of the add can just fall through + module.optimize(); + + // Print out the optimized module's text + console.log('optimized:\n\n' + module.emitText()); + + // Get the binary in typed array form + var binary = module.emitBinary(); + console.log('binary size: ' + binary.length); + console.log(); + assert(module.validate()); + + // We don't need the Binaryen module anymore, so we can tell it to + // clean itself up + module.dispose(); + + // 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(); + + // Call the code! + console.log('an addition: ' + wasm.exports.adder(40, 2)); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index 630db311f..e8cf3e0f5 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -1,5 +1,9 @@ // kitchen sink, tests the full API +function assert(x) { + if (!x) throw 'error!'; +} + function cleanInfo(info) { var ret = {}; for (var x in info) { @@ -16,10 +20,6 @@ var module; var v128_bytes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; -function assert(x) { - if (!x) throw 'error!'; -} - function makeInt32(x) { return module.i32.const(x); } @@ -975,7 +975,7 @@ function test_expression_info() { module.dispose(); } -function main() { +function test() { // Tracing must be first so it starts with a fresh set of interned types test_tracing(); test_types(); @@ -992,4 +992,4 @@ function main() { test_expression_info(); } -main(); +Binaryen.ready.then(test); diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index 586834f26..bb6c92f72 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -743,7 +743,7 @@ int main() { uint8_t t109[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; expressions[398] = BinaryenConst(the_module, BinaryenLiteralVec128(t109)); } - expressions[399] = BinaryenBinary(the_module, 111, expressions[397], expressions[398]); + expressions[399] = BinaryenBinary(the_module, 112, expressions[397], expressions[398]); { uint8_t t110[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; expressions[400] = BinaryenConst(the_module, BinaryenLiteralVec128(t110)); @@ -2689,7 +2689,7 @@ getExpressionInfo(f64.const)={"id":14,"type":5,"value":9.5} ) ) (drop - (f32x4.ge + (f64x2.eq (v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d) (v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d) ) @@ -4386,7 +4386,7 @@ getExpressionInfo(f64.const)={"id":14,"type":5,"value":9.5} ) ) (drop - (f32x4.ge + (f64x2.eq (v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d) (v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d) ) @@ -7139,7 +7139,7 @@ getExpressionInfo(f64.const)={"id":14,"type":5,"value":9.5} ) ) (drop - (f32x4.ge + (f64x2.eq (v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d) (v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d) ) @@ -8834,7 +8834,7 @@ getExpressionInfo(f64.const)={"id":14,"type":5,"value":9.5} ) ) (drop - (f32x4.ge + (f64x2.eq (v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d) (v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d) ) diff --git a/test/binaryen.js/optimize-levels.js b/test/binaryen.js/optimize-levels.js index e42bd5409..b3ae66a43 100644 --- a/test/binaryen.js/optimize-levels.js +++ b/test/binaryen.js/optimize-levels.js @@ -18,47 +18,52 @@ var wast = ` ) ) `; -console.log("=== input wast ===" + wast); -function printOptions() { - console.log("optimizeLevel=" + Binaryen.getOptimizeLevel()); - console.log("shrinkLevel=" + Binaryen.getShrinkLevel()); -} +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); + // Use defaults (should be equal to -Os below) + var module = Binaryen.parseText(wast); -console.log("=== unoptimized ==="); -assert(module.validate()); -console.log(module.emitText()); + 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(); + 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); + // 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(); + 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); + // 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(); +} -Binaryen.setOptimizeLevel(2); -Binaryen.setShrinkLevel(1); -module.optimize(); -console.log("=== optimized with -Os ==="); -printOptions(); -assert(module.validate()); -console.log(module.emitText()); -module.dispose(); +Binaryen.ready.then(test); diff --git a/test/binaryen.js/push-pop.js b/test/binaryen.js/push-pop.js index 9f1d66719..01d6e76a9 100644 --- a/test/binaryen.js/push-pop.js +++ b/test/binaryen.js/push-pop.js @@ -16,29 +16,33 @@ function stringify(expr) { return JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(expr))); } -var module = new Binaryen.Module(); +function test() { + 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.anyref.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.anyref.pop()), + module.push(module.exnref.pop()) + ] + ) + ) -assert(module.validate()); -console.log(module.emitText()); + 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(anyref.pop) = " + stringify(module.anyref.pop())); -console.log("getExpressionInfo(exnref.pop) = " + stringify(module.exnref.pop())); -console.log("getExpressionInfo(push) = " + stringify(module.push(module.i32.const(0)))); + 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(anyref.pop) = " + stringify(module.anyref.pop())); + console.log("getExpressionInfo(exnref.pop) = " + stringify(module.exnref.pop())); + console.log("getExpressionInfo(push) = " + stringify(module.push(module.i32.const(0)))); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/reloc.js b/test/binaryen.js/reloc.js index 9666d17fd..e9fdd6012 100644 --- a/test/binaryen.js/reloc.js +++ b/test/binaryen.js/reloc.js @@ -2,24 +2,28 @@ 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()); + assert(module.validate()); + console.log(module.emitText()); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/sieve.js b/test/binaryen.js/sieve.js index b2c278cbd..ef7c6cca8 100644 --- a/test/binaryen.js/sieve.js +++ b/test/binaryen.js/sieve.js @@ -1,75 +1,79 @@ -// Create a module to work on -var module = new Binaryen.Module(); +function test() { + // 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) + 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) ), - 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.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.i32.const(65536) - ), - module.memory.size() + 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) ), - 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 -); + // 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); -// Create the add function -// Note: no additional local variables (that's the []) -module.addFunction('sieve', Binaryen.i32, Binaryen.i32, [Binaryen.i32], body); + // 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'); -// 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'); + if (!module.validate()) throw 'did not validate :('; -if (!module.validate()) throw 'did not validate :('; + // Print out the text + console.log(module.emitText()); -// Print out the text -console.log(module.emitText()); + // Optimize the module! This removes the 'return', since the + // output of the add can just fall through + module.optimize(); -// Optimize the module! This removes the 'return', since the -// output of the add can just fall through -module.optimize(); + // Print out the optimized module's text + console.log('optimized:\n\n' + module.emitText()); +} -// Print out the optimized module's text -console.log('optimized:\n\n' + module.emitText()); +Binaryen.ready.then(test); diff --git a/test/binaryen.js/simd.js b/test/binaryen.js/simd.js index a6055a267..68785f9d7 100644 --- a/test/binaryen.js/simd.js +++ b/test/binaryen.js/simd.js @@ -1,5 +1,9 @@ -var module = new Binaryen.Module(); +function test() { + 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")); + 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); diff --git a/test/binaryen.js/sourcemap.js b/test/binaryen.js/sourcemap.js index 04f188e23..f8deecf3f 100644 --- a/test/binaryen.js/sourcemap.js +++ b/test/binaryen.js/sourcemap.js @@ -2,41 +2,45 @@ function assert(x) { if (!x) throw 'error!'; } -var module = new Binaryen.Module(); - -var fileIndex = module.addDebugInfoFileName("module.c"); - -console.log(module.getDebugInfoFileName(fileIndex)); -console.log(); - -var expr = module.i32.const(1); -var body = module.block("", [ - expr -], Binaryen.i32); - -var func = module.addFunction("main", Binaryen.none, Binaryen.i32, [], body); - -module.setDebugLocation(func, expr, fileIndex, 1, 2); -module.setDebugLocation(func, body, fileIndex, 0, 3); - -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); +function test() { + var module = new Binaryen.Module(); + + var fileIndex = module.addDebugInfoFileName("module.c"); + + console.log(module.getDebugInfoFileName(fileIndex)); + console.log(); + + var expr = module.i32.const(1); + var body = module.block("", [ + expr + ], Binaryen.i32); + + var func = module.addFunction("main", Binaryen.none, Binaryen.i32, [], body); + + module.setDebugLocation(func, expr, fileIndex, 1, 2); + module.setDebugLocation(func, body, fileIndex, 0, 3); + + 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(" ")); } - console.log(hex.join(" ")); + + dumpBinary(output.binary); + console.log(); + console.log(output.sourceMap); } -dumpBinary(output.binary); -console.log(); -console.log(output.sourceMap); +Binaryen.ready.then(test); diff --git a/test/binaryen.js/stackir.js b/test/binaryen.js/stackir.js index 929fbaa0e..324a99abe 100644 --- a/test/binaryen.js/stackir.js +++ b/test/binaryen.js/stackir.js @@ -20,13 +20,18 @@ var wast = ` ) ) `; -console.log("=== input wast ===" + wast); -var module = Binaryen.parseText(wast); -assert(module.validate()); +function test() { + 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()); + + console.log("=== optimize ==="); // should omit the second block + console.log(module.emitStackIR(true)); +} + +Binaryen.ready.then(test); diff --git a/test/binaryen.js/validation_errors.js b/test/binaryen.js/validation_errors.js index 16bc6f433..1251d37e6 100644 --- a/test/binaryen.js/validation_errors.js +++ b/test/binaryen.js/validation_errors.js @@ -1,25 +1,29 @@ -(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 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.local.get(0, Binaryen.i32) - ) - ]) - ); - mod.addFunctionExport("test", "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); |