diff options
author | Daniel Wirtz <dcode@dcode.io> | 2018-01-17 18:25:49 +0100 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2018-01-17 09:25:49 -0800 |
commit | 01b23987405d8d7b2f13e40ef906169163ac2a5f (patch) | |
tree | 7b76946e0392eb65ad773cbb6524ad0fdbddde38 /test/binaryen.js/optimize-levels.js | |
parent | 3d8358f8e10a01869ef59189539ab1d17d52cb10 (diff) | |
download | binaryen-01b23987405d8d7b2f13e40ef906169163ac2a5f.tar.gz binaryen-01b23987405d8d7b2f13e40ef906169163ac2a5f.tar.bz2 binaryen-01b23987405d8d7b2f13e40ef906169163ac2a5f.zip |
Add optimize, shrink level and debug info options to C/JS (#1357)
* Add optimize, shrink level and debug info options to C/JS
* Add instantiate functionality for creating additional unique instances of the API
* Use a workaround when running tests in node
Tests misuse a module as a script by concatenating, so instead of catching this case in the library, catch it there
* Update sieve test
Seems optimized output changed due to running with optimize levels 2/1 now
* Use the options with all pass runners
* Update relooper-fuzz C-API test
* Share defaults between tools and the C-API
* Add a test for optimize levels
* Unify node test support in check.by and auto_update_tests.py
* Also add getters for optimize levels and test them
* Also test debugInfo
* Add debug info to C tests that used it as well
* Fix missing NODEJS import in auto_update_tests
* Detect node.js version (WASM support)
* Update hello-world JS test (now also runs with node)
* feature-test WebAssembly in node instead
* Document that these options apply globally, and where
* Make sure hello-world.js output doesn't differ between mozjs/node
Diffstat (limited to 'test/binaryen.js/optimize-levels.js')
-rw-r--r-- | test/binaryen.js/optimize-levels.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/binaryen.js/optimize-levels.js b/test/binaryen.js/optimize-levels.js new file mode 100644 index 000000000..1ee4943ca --- /dev/null +++ b/test/binaryen.js/optimize-levels.js @@ -0,0 +1,60 @@ +var wast = ` +(module + (type $i (func (param i32) (result i32))) + (memory $0 0) + (export "test" (func $test)) + (func $test (; 0 ;) (type $i) (param $0 i32) (result i32) + (block (result i32) + (if (result i32) + (get_local $0) + (get_local $0) + (i32.const 0) + ) + ) + ) +) +`; +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 ==="); +module.validate(); +console.log(module.emitText()); + +module.optimize(); +console.log("=== optimized using defaults ==="); +printOptions(); +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(); +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(); +module.validate(); +console.log(module.emitText()); +module.dispose(); |