diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/binaryen.js/debug-info.js | 40 | ||||
-rw-r--r-- | test/binaryen.js/debug-info.js.txt | 33 | ||||
-rw-r--r-- | test/binaryen.js/hello-world.js | 2 | ||||
-rw-r--r-- | test/binaryen.js/hello-world.js.txt | 4 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js | 2 | ||||
-rw-r--r-- | test/binaryen.js/optimize-levels.js | 60 | ||||
-rw-r--r-- | test/binaryen.js/optimize-levels.js.txt | 77 | ||||
-rw-r--r-- | test/binaryen.js/sieve.js.txt | 3 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 2 | ||||
-rw-r--r-- | test/example/c-api-unused-mem.cpp | 1 |
10 files changed, 218 insertions, 6 deletions
diff --git a/test/binaryen.js/debug-info.js b/test/binaryen.js/debug-info.js new file mode 100644 index 000000000..ea7dd4fa4 --- /dev/null +++ b/test/binaryen.js/debug-info.js @@ -0,0 +1,40 @@ +var wast = ` +(module + (type $v (func)) + (memory $0 0) + (export "test" (func $test)) + (func $test (; 0 ;) (type $v)) +) +`; + +// 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()); +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()); +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()); +module.dispose(); diff --git a/test/binaryen.js/debug-info.js.txt b/test/binaryen.js/debug-info.js.txt new file mode 100644 index 000000000..8825b135f --- /dev/null +++ b/test/binaryen.js/debug-info.js.txt @@ -0,0 +1,33 @@ +=== default === +debugInfo=false +(module + (type $0 (func)) + (memory $0 0) + (export "test" (func $0)) + (func $0 (; 0 ;) (type $0) + (nop) + ) +) + +=== with debug info === +debugInfo=true +(module + (type $0 (func)) + (memory $0 0) + (export "test" (func $test)) + (func $test (; 0 ;) (type $0) + (nop) + ) +) + +=== without debug info === +debugInfo=false +(module + (type $0 (func)) + (memory $0 0) + (export "test" (func $0)) + (func $0 (; 0 ;) (type $0) + (nop) + ) +) + diff --git a/test/binaryen.js/hello-world.js b/test/binaryen.js/hello-world.js index 1cc5b89b7..2a9a56ed0 100644 --- a/test/binaryen.js/hello-world.js +++ b/test/binaryen.js/hello-world.js @@ -45,7 +45,7 @@ module.dispose(); // Compile the binary and create an instance var wasm = new WebAssembly.Instance(new WebAssembly.Module(binary), {}) -console.log(wasm); // prints something like "[object WebAssembly.Instance]" +console.log("exports: " + Object.keys(wasm.exports).sort().join(",")); console.log(); // Call the code! diff --git a/test/binaryen.js/hello-world.js.txt b/test/binaryen.js/hello-world.js.txt index e1aff31c5..c3cfae20b 100644 --- a/test/binaryen.js/hello-world.js.txt +++ b/test/binaryen.js/hello-world.js.txt @@ -24,8 +24,8 @@ optimized: ) ) -binary size: 60 +binary size: 43 -[object WebAssembly.Instance] +exports: adder an addition: 42 diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index f1f67ea28..09828817a 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -490,7 +490,9 @@ function test_binaries() { y = module.getLocal(1, Binaryen.i32); var add = module.i32.add(x, y); var adder = module.addFunction("adder", iii, [], add); + Binaryen.setDebugInfo(true); // include names section buffer = module.emitBinary(); + Binaryen.setDebugInfo(false); size = buffer.length; // write out the module module.dispose(); } 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(); diff --git a/test/binaryen.js/optimize-levels.js.txt b/test/binaryen.js/optimize-levels.js.txt new file mode 100644 index 000000000..78190fc0d --- /dev/null +++ b/test/binaryen.js/optimize-levels.js.txt @@ -0,0 +1,77 @@ +=== input 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) + ) + ) + ) +) + +=== unoptimized === +(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 $block (result i32) + (if (result i32) + (get_local $0) + (get_local $0) + (i32.const 0) + ) + ) + ) +) + +=== optimized using defaults === +optimizeLevel=2 +shrinkLevel=1 +(module + (type $i (func (param i32) (result i32))) + (export "test" (func $test)) + (func $test (; 0 ;) (type $i) (param $0 i32) (result i32) + (select + (get_local $0) + (i32.const 0) + (get_local $0) + ) + ) +) + +=== optimized with -O0 === +optimizeLevel=0 +shrinkLevel=0 +(module + (type $i (func (param i32) (result i32))) + (export "test" (func $test)) + (func $test (; 0 ;) (type $i) (param $0 i32) (result i32) + (if (result i32) + (get_local $0) + (get_local $0) + (i32.const 0) + ) + ) +) + +=== optimized with -Os === +optimizeLevel=2 +shrinkLevel=1 +(module + (type $i (func (param i32) (result i32))) + (export "test" (func $test)) + (func $test (; 0 ;) (type $i) (param $0 i32) (result i32) + (select + (get_local $0) + (i32.const 0) + (get_local $0) + ) + ) +) + diff --git a/test/binaryen.js/sieve.js.txt b/test/binaryen.js/sieve.js.txt index 3400215e1..cd1c47362 100644 --- a/test/binaryen.js/sieve.js.txt +++ b/test/binaryen.js/sieve.js.txt @@ -81,9 +81,6 @@ optimized: ) ) ) - (set_local $1 - (i32.const 0) - ) (loop $clear (i32.store8 (get_local $1) diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index bb7a95209..8c41ea124 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -514,7 +514,9 @@ void test_binaries() { y = BinaryenGetLocal(module, 1, BinaryenTypeInt32()); BinaryenExpressionRef add = BinaryenBinary(module, BinaryenAddInt32(), x, y); BinaryenFunctionRef adder = BinaryenAddFunction(module, "adder", iii, NULL, 0, add); + BinaryenSetDebugInfo(1); // include names section size = BinaryenModuleWrite(module, buffer, 1024); // write out the module + BinaryenSetDebugInfo(0); BinaryenModuleDispose(module); } diff --git a/test/example/c-api-unused-mem.cpp b/test/example/c-api-unused-mem.cpp index 852e53b94..dd8fb2e8f 100644 --- a/test/example/c-api-unused-mem.cpp +++ b/test/example/c-api-unused-mem.cpp @@ -81,6 +81,7 @@ int main() { // check that binary read-write works { char buffer[1024]; + BinaryenSetDebugInfo(1); size_t size = BinaryenModuleWrite(the_module, buffer, 1024); printf("%d\n", size); BinaryenModuleRef copy = BinaryenModuleRead(buffer, size); |