From 01b23987405d8d7b2f13e40ef906169163ac2a5f Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Wed, 17 Jan 2018 18:25:49 +0100 Subject: 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 --- test/binaryen.js/optimize-levels.js | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/binaryen.js/optimize-levels.js (limited to 'test/binaryen.js/optimize-levels.js') 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(); -- cgit v1.2.3