summaryrefslogtreecommitdiff
path: root/test/decompile
diff options
context:
space:
mode:
authorWouter van Oortmerssen <aardappel@gmail.com>2020-01-02 14:51:23 -0800
committerGitHub <noreply@github.com>2020-01-02 14:51:23 -0800
commitd008411c9bb1ae11caf9912c625898bba6e12666 (patch)
tree1f894b9dbb1a9e0ce35f9d5dbd8bb731656d857a /test/decompile
parent76ff3af40040a90c15b6b9f2614f3a3869dbdab1 (diff)
downloadwabt-d008411c9bb1ae11caf9912c625898bba6e12666.tar.gz
wabt-d008411c9bb1ae11caf9912c625898bba6e12666.tar.bz2
wabt-d008411c9bb1ae11caf9912c625898bba6e12666.zip
wasm-decompile: added precedence support. (#1277)
Previously it would simply bracket all binary exps. Now it has a precedence system that is in line with what people know from most programming languages.
Diffstat (limited to 'test/decompile')
-rw-r--r--test/decompile/basic.txt2
-rw-r--r--test/decompile/loadstore.txt4
-rw-r--r--test/decompile/precedence.txt47
3 files changed, 50 insertions, 3 deletions
diff --git a/test/decompile/basic.txt b/test/decompile/basic.txt
index 90665103..ebb5dd46 100644
--- a/test/decompile/basic.txt
+++ b/test/decompile/basic.txt
@@ -82,7 +82,7 @@ export function f(a:int, b:int):int {
var c:long = 8L;
var d:float = 6.0f;
var e:double = 7.0;
- if (e < 10.0) { 1[4]:int = (2[3]:int + 5) }
+ if (e < 10.0) { 1[4]:int = 2[3]:int + 5 }
f(a + g_b, 9);
loop L_b {
block B_c {
diff --git a/test/decompile/loadstore.txt b/test/decompile/loadstore.txt
index 0a6cf58d..d1216950 100644
--- a/test/decompile/loadstore.txt
+++ b/test/decompile/loadstore.txt
@@ -69,8 +69,8 @@ export function f(a:{ a:float, b:float }, b:{ a:ushort, b:long }) {
var f:int;
var g:int;
var h:int;
- (a.a + c.a) + (a.b + c.b);
- (b.a + d.a) + (b.b + d.b);
+ a.a + c.a + a.b + c.b;
+ b.a + d.a + b.b + d.b;
e[0]:int;
e[0]:float;
f[0]:int;
diff --git a/test/decompile/precedence.txt b/test/decompile/precedence.txt
new file mode 100644
index 00000000..8980255a
--- /dev/null
+++ b/test/decompile/precedence.txt
@@ -0,0 +1,47 @@
+ ;;; TOOL: run-wasm-decompile
+
+(module
+ (memory $m1 1)
+
+ (func $precedence (param) (result)
+ ;; some exp in order that will generate no parens
+ i32.const 0
+ i32.load offset=0
+ i32.const 1
+ i32.mul
+ i32.const 2
+ i32.add
+ i32.const 3
+ i32.shl
+ i32.const 4
+ i32.eq
+ i32.const 5
+ i32.and
+ drop
+ ;; some exp in reverse order that will generate parens.
+ i32.const 6
+ i32.const 5
+ i32.and
+ i32.const 4
+ i32.eq
+ i32.const 3
+ i32.shl
+ i32.const 2
+ i32.add
+ i32.const 1
+ i32.mul
+ i32.load offset=0
+ drop
+ )
+ (export "precedence" (func $precedence))
+)
+
+(;; STDOUT ;;;
+memory M_a(initial: 1, max: 0);
+
+export function precedence() {
+ 0[0]:int * 1 + 2 << 3 == 4 & 5;
+ (((((6 & 5) == 4) << 3) + 2) * 1)[0]:int;
+}
+
+;;; STDOUT ;;)