summaryrefslogtreecommitdiff
path: root/test/binaryen.js
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2018-10-31 19:22:48 +0100
committerAlon Zakai <alonzakai@gmail.com>2018-10-31 11:22:48 -0700
commit7d3ddd09d5f68945160cda3f3749a217a13928bf (patch)
tree639fea7314e6ef263ab3091f1dbfcbf410727ccc /test/binaryen.js
parent9c7b910d88d1d08861dd35beccd4731cf2cb5354 (diff)
downloadbinaryen-7d3ddd09d5f68945160cda3f3749a217a13928bf.tar.gz
binaryen-7d3ddd09d5f68945160cda3f3749a217a13928bf.tar.bz2
binaryen-7d3ddd09d5f68945160cda3f3749a217a13928bf.zip
Add Module#emitStackIR to the JS-API (#1717)
Related to #1716 (comment)
Diffstat (limited to 'test/binaryen.js')
-rw-r--r--test/binaryen.js/stackir.js27
-rw-r--r--test/binaryen.js/stackir.js.txt50
2 files changed, 77 insertions, 0 deletions
diff --git a/test/binaryen.js/stackir.js b/test/binaryen.js/stackir.js
new file mode 100644
index 000000000..5c4b14f9d
--- /dev/null
+++ b/test/binaryen.js/stackir.js
@@ -0,0 +1,27 @@
+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)
+ (block (result i32)
+ (if (result i32)
+ (get_local $0)
+ (get_local $0)
+ (i32.const 0)
+ )
+ )
+ )
+ )
+)
+`;
+console.log("=== input wast ===" + wast);
+
+var module = Binaryen.parseText(wast);
+
+console.log("=== default ===");
+console.log(module.emitStackIR());
+
+console.log("=== optimize ==="); // should omit the second block
+console.log(module.emitStackIR(true));
diff --git a/test/binaryen.js/stackir.js.txt b/test/binaryen.js/stackir.js.txt
new file mode 100644
index 000000000..f0985ee5c
--- /dev/null
+++ b/test/binaryen.js/stackir.js.txt
@@ -0,0 +1,50 @@
+=== 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)
+ (block (result i32)
+ (if (result i32)
+ (get_local $0)
+ (get_local $0)
+ (i32.const 0)
+ )
+ )
+ )
+ )
+)
+
+=== default ===
+(module
+ (type $i (func (param i32) (result i32)))
+ (memory $0 0)
+ (export "test" (func $test))
+ (func $test (; 0 ;) (; has Stack IR ;) (type $i) (param $0 i32) (result i32)
+ block $block0 (result i32)
+ get_local $0
+ if (result i32)
+ get_local $0
+ else
+ i32.const 0
+ end
+ end
+ )
+)
+
+=== optimize ===
+(module
+ (type $i (func (param i32) (result i32)))
+ (memory $0 0)
+ (export "test" (func $test))
+ (func $test (; 0 ;) (; has Stack IR ;) (type $i) (param $0 i32) (result i32)
+ get_local $0
+ if (result i32)
+ get_local $0
+ else
+ i32.const 0
+ end
+ )
+)
+