summaryrefslogtreecommitdiff
path: root/test/wasm2js
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-04-25 17:10:06 -0700
committerGitHub <noreply@github.com>2019-04-25 17:10:06 -0700
commit78a4f9ef1afd6c209a5c69a8e7906ffe33575f58 (patch)
tree0f7443f2ca32ce1a6131a6cc95212de9b5ececb1 /test/wasm2js
parent21f014f4bd0ea1086895d8674f1473af222eb416 (diff)
downloadbinaryen-78a4f9ef1afd6c209a5c69a8e7906ffe33575f58.tar.gz
binaryen-78a4f9ef1afd6c209a5c69a8e7906ffe33575f58.tar.bz2
binaryen-78a4f9ef1afd6c209a5c69a8e7906ffe33575f58.zip
wasm2js2: optimize call_indirect and select operands (#2056)
Don't use temp vars to reorder them unless we need to.
Diffstat (limited to 'test/wasm2js')
-rw-r--r--test/wasm2js/call_indirect.2asm.js78
-rw-r--r--test/wasm2js/emscripten.2asm.js3
-rw-r--r--test/wasm2js/f32.2asm.js7
-rw-r--r--test/wasm2js/f64.2asm.js7
-rw-r--r--test/wasm2js/float_misc.2asm.js14
-rw-r--r--test/wasm2js/func-ptr-offset.2asm.js3
-rw-r--r--test/wasm2js/func.2asm.js19
-rw-r--r--test/wasm2js/func_ptrs.2asm.js9
-rw-r--r--test/wasm2js/left-to-right.2asm.js4
-rw-r--r--test/wasm2js/nested-selects.2asm.js3
-rw-r--r--test/wasm2js/ordering.2asm.js66
-rw-r--r--test/wasm2js/ordering.wast98
-rw-r--r--test/wasm2js/select.2asm.js15
13 files changed, 231 insertions, 95 deletions
diff --git a/test/wasm2js/call_indirect.2asm.js b/test/wasm2js/call_indirect.2asm.js
index a99d714fb..e4dfd0451 100644
--- a/test/wasm2js/call_indirect.2asm.js
+++ b/test/wasm2js/call_indirect.2asm.js
@@ -119,92 +119,83 @@ function asmFunc(global, env, buffer) {
}
function $16() {
- var wasm2js_i32$0 = 0;
- return (wasm2js_i32$0 = 0, FUNCTION_TABLE[wasm2js_i32$0]() | 0) | 0;
+ return FUNCTION_TABLE[0]() | 0;
}
function $17() {
- var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, wasm2js_i32$0 = 0;
- i64toi32_i32$0 = (wasm2js_i32$0 = 1, FUNCTION_TABLE[wasm2js_i32$0]() | 0);
+ var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0;
+ i64toi32_i32$0 = FUNCTION_TABLE[1]() | 0;
i64toi32_i32$1 = i64toi32_i32$HIGH_BITS;
i64toi32_i32$HIGH_BITS = i64toi32_i32$1;
return i64toi32_i32$0 | 0;
}
function $18() {
- var wasm2js_i32$0 = 0;
- return Math_fround((wasm2js_i32$0 = 2, Math_fround(FUNCTION_TABLE[wasm2js_i32$0]())));
+ return Math_fround(Math_fround(FUNCTION_TABLE[2]()));
}
function $19() {
- var wasm2js_i32$0 = 0;
- return +(wasm2js_i32$0 = 3, +FUNCTION_TABLE[wasm2js_i32$0]());
+ return +FUNCTION_TABLE[3]();
}
function $20() {
- var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0;
+ var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0;
i64toi32_i32$0 = 0;
- i64toi32_i32$0 = (((wasm2js_i32$1 = 100, wasm2js_i32$2 = i64toi32_i32$0), wasm2js_i32$0 = 5), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0, wasm2js_i32$2 | 0) | 0);
+ i64toi32_i32$0 = FUNCTION_TABLE[5](100, i64toi32_i32$0) | 0;
i64toi32_i32$1 = i64toi32_i32$HIGH_BITS;
i64toi32_i32$HIGH_BITS = i64toi32_i32$1;
return i64toi32_i32$0 | 0;
}
function $21() {
- var wasm2js_i32$0 = 0, wasm2js_i32$1 = 0;
- return ((wasm2js_i32$1 = 32, wasm2js_i32$0 = 4), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0) | 0) | 0;
+ return FUNCTION_TABLE[4](32) | 0;
}
function $22() {
- var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0;
+ var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0;
i64toi32_i32$0 = 0;
- i64toi32_i32$0 = (((wasm2js_i32$1 = 64, wasm2js_i32$2 = i64toi32_i32$0), wasm2js_i32$0 = 5), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0, wasm2js_i32$2 | 0) | 0);
+ i64toi32_i32$0 = FUNCTION_TABLE[5](64, i64toi32_i32$0) | 0;
i64toi32_i32$1 = i64toi32_i32$HIGH_BITS;
i64toi32_i32$HIGH_BITS = i64toi32_i32$1;
return i64toi32_i32$0 | 0;
}
function $23() {
- var wasm2js_i32$0 = 0, wasm2js_f32$0 = Math_fround(0);
- return Math_fround(((wasm2js_f32$0 = Math_fround(1.3200000524520874), wasm2js_i32$0 = 6), Math_fround(FUNCTION_TABLE[wasm2js_i32$0](Math_fround(wasm2js_f32$0)))));
+ return Math_fround(Math_fround(FUNCTION_TABLE[6](Math_fround(1.3200000524520874))));
}
function $24() {
- var wasm2js_i32$0 = 0, wasm2js_f64$0 = 0.0;
- return +((wasm2js_f64$0 = 1.64, wasm2js_i32$0 = 7), +FUNCTION_TABLE[wasm2js_i32$0](+wasm2js_f64$0));
+ return +FUNCTION_TABLE[7](1.64);
}
function $25() {
- var wasm2js_i32$0 = 0, wasm2js_f32$0 = Math_fround(0), wasm2js_i32$1 = 0;
- return (((wasm2js_f32$0 = Math_fround(32.099998474121094), wasm2js_i32$1 = 32), wasm2js_i32$0 = 8), FUNCTION_TABLE[wasm2js_i32$0](Math_fround(wasm2js_f32$0), wasm2js_i32$1 | 0) | 0) | 0;
+ return FUNCTION_TABLE[8](Math_fround(32.099998474121094), 32) | 0;
}
function $26() {
- var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0, wasm2js_i32$3 = 0;
+ var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0;
i64toi32_i32$0 = 0;
- i64toi32_i32$0 = ((((wasm2js_i32$1 = 32, wasm2js_i32$2 = 64), wasm2js_i32$3 = i64toi32_i32$0), wasm2js_i32$0 = 9), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0, wasm2js_i32$2 | 0, wasm2js_i32$3 | 0) | 0);
+ i64toi32_i32$0 = FUNCTION_TABLE[9](32, 64, i64toi32_i32$0) | 0;
i64toi32_i32$1 = i64toi32_i32$HIGH_BITS;
i64toi32_i32$HIGH_BITS = i64toi32_i32$1;
return i64toi32_i32$0 | 0;
}
function $27() {
- var wasm2js_i32$0 = 0, wasm2js_f64$0 = 0.0, wasm2js_f32$0 = Math_fround(0);
- return Math_fround((((wasm2js_f64$0 = 64.0, wasm2js_f32$0 = Math_fround(32.0)), wasm2js_i32$0 = 10), Math_fround(FUNCTION_TABLE[wasm2js_i32$0](+wasm2js_f64$0, Math_fround(wasm2js_f32$0)))));
+ return Math_fround(Math_fround(FUNCTION_TABLE[10](64.0, Math_fround(32.0))));
}
function $28() {
- var wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0, wasm2js_f64$0 = 0.0;
- return +((((wasm2js_i32$1 = 64, wasm2js_i32$2 = 0), wasm2js_f64$0 = 64.1), wasm2js_i32$0 = 11), +FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0, wasm2js_i32$2 | 0, +wasm2js_f64$0));
+ return +FUNCTION_TABLE[11](64, 0, 64.1);
}
function $29($0, $1, $1$hi) {
$0 = $0 | 0;
$1 = $1 | 0;
$1$hi = $1$hi | 0;
- var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0;
+ var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0;
i64toi32_i32$0 = $1$hi;
- i64toi32_i32$0 = (((wasm2js_i32$1 = $1, wasm2js_i32$2 = i64toi32_i32$0), wasm2js_i32$0 = $0), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0, wasm2js_i32$2 | 0) | 0);
+ i64toi32_i32$0 = FUNCTION_TABLE[$0]($1, i64toi32_i32$0) | 0;
i64toi32_i32$1 = i64toi32_i32$HIGH_BITS;
i64toi32_i32$HIGH_BITS = i64toi32_i32$1;
return i64toi32_i32$0 | 0;
@@ -212,9 +203,9 @@ function asmFunc(global, env, buffer) {
function $30($0) {
$0 = $0 | 0;
- var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0;
+ var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0;
i64toi32_i32$0 = 0;
- i64toi32_i32$0 = (((wasm2js_i32$1 = 9, wasm2js_i32$2 = i64toi32_i32$0), wasm2js_i32$0 = $0), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0, wasm2js_i32$2 | 0) | 0);
+ i64toi32_i32$0 = FUNCTION_TABLE[$0](9, i64toi32_i32$0) | 0;
i64toi32_i32$1 = i64toi32_i32$HIGH_BITS;
i64toi32_i32$HIGH_BITS = i64toi32_i32$1;
return i64toi32_i32$0 | 0;
@@ -223,7 +214,7 @@ function asmFunc(global, env, buffer) {
function fac($0, $0$hi) {
$0 = $0 | 0;
$0$hi = $0$hi | 0;
- var i64toi32_i32$5 = 0, i64toi32_i32$2 = 0, i64toi32_i32$0 = 0, $8 = 0, $8$hi = 0, i64toi32_i32$3 = 0, $6 = 0, $6$hi = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0;
+ var i64toi32_i32$5 = 0, i64toi32_i32$2 = 0, i64toi32_i32$0 = 0, $8 = 0, $8$hi = 0, i64toi32_i32$3 = 0, $6 = 0, $6$hi = 0;
i64toi32_i32$0 = $0$hi;
if (!($0 | i64toi32_i32$0)) {
{
@@ -238,7 +229,7 @@ function asmFunc(global, env, buffer) {
i64toi32_i32$3 = 1;
i64toi32_i32$5 = (i64toi32_i32$2 >>> 0 < i64toi32_i32$3 >>> 0) + 0 | 0;
i64toi32_i32$5 = i64toi32_i32$0 - i64toi32_i32$5 | 0;
- i64toi32_i32$5 = (((wasm2js_i32$1 = i64toi32_i32$2 - i64toi32_i32$3 | 0, wasm2js_i32$2 = i64toi32_i32$5), wasm2js_i32$0 = 12), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0, wasm2js_i32$2 | 0) | 0);
+ i64toi32_i32$5 = FUNCTION_TABLE[12](i64toi32_i32$2 - i64toi32_i32$3 | 0, i64toi32_i32$5) | 0;
i64toi32_i32$2 = i64toi32_i32$HIGH_BITS;
$6 = i64toi32_i32$5;
$6$hi = i64toi32_i32$2;
@@ -259,7 +250,7 @@ function asmFunc(global, env, buffer) {
function fib($0, $0$hi) {
$0 = $0 | 0;
$0$hi = $0$hi | 0;
- var i64toi32_i32$2 = 0, i64toi32_i32$3 = 0, i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, i64toi32_i32$5 = 0, i64toi32_i32$4 = 0, i64toi32_i32$6 = 0, $10 = 0, $10$hi = 0, $5 = 0, $5$hi = 0, $8 = 0, $8$hi = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0;
+ var i64toi32_i32$2 = 0, i64toi32_i32$3 = 0, i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, i64toi32_i32$5 = 0, i64toi32_i32$4 = 0, i64toi32_i32$6 = 0, $10 = 0, $10$hi = 0, $5 = 0, $5$hi = 0, $8 = 0, $8$hi = 0;
i64toi32_i32$0 = $0$hi;
i64toi32_i32$2 = $0;
i64toi32_i32$1 = 0;
@@ -280,7 +271,7 @@ function asmFunc(global, env, buffer) {
i64toi32_i32$6 = i64toi32_i32$3 >>> 0 < i64toi32_i32$1 >>> 0;
i64toi32_i32$5 = i64toi32_i32$6 + i64toi32_i32$0 | 0;
i64toi32_i32$5 = i64toi32_i32$2 - i64toi32_i32$5 | 0;
- i64toi32_i32$5 = (((wasm2js_i32$1 = i64toi32_i32$4, wasm2js_i32$2 = i64toi32_i32$5), wasm2js_i32$0 = 13), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0, wasm2js_i32$2 | 0) | 0);
+ i64toi32_i32$5 = FUNCTION_TABLE[13](i64toi32_i32$4, i64toi32_i32$5) | 0;
i64toi32_i32$3 = i64toi32_i32$HIGH_BITS;
$5 = i64toi32_i32$5;
$5$hi = i64toi32_i32$3;
@@ -293,7 +284,7 @@ function asmFunc(global, env, buffer) {
i64toi32_i32$6 = i64toi32_i32$2 >>> 0 < i64toi32_i32$1 >>> 0;
i64toi32_i32$4 = i64toi32_i32$6 + i64toi32_i32$5 | 0;
i64toi32_i32$4 = i64toi32_i32$3 - i64toi32_i32$4 | 0;
- i64toi32_i32$4 = (((wasm2js_i32$2 = i64toi32_i32$0, wasm2js_i32$1 = i64toi32_i32$4), wasm2js_i32$0 = 13), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$2 | 0, wasm2js_i32$1 | 0) | 0);
+ i64toi32_i32$4 = FUNCTION_TABLE[13](i64toi32_i32$0, i64toi32_i32$4) | 0;
i64toi32_i32$2 = i64toi32_i32$HIGH_BITS;
$8 = i64toi32_i32$4;
$8$hi = i64toi32_i32$2;
@@ -318,39 +309,36 @@ function asmFunc(global, env, buffer) {
function even($0) {
$0 = $0 | 0;
- var $6 = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0;
+ var $6 = 0;
if (!$0) {
$6 = 44
} else {
- $6 = ((wasm2js_i32$1 = $0 - 1 | 0, wasm2js_i32$0 = 15), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0) | 0)
+ $6 = FUNCTION_TABLE[15]($0 - 1 | 0) | 0
}
return $6 | 0;
}
function odd($0) {
$0 = $0 | 0;
- var $6 = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0;
+ var $6 = 0;
if (!$0) {
$6 = 99
} else {
- $6 = ((wasm2js_i32$1 = $0 - 1 | 0, wasm2js_i32$0 = 14), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0) | 0)
+ $6 = FUNCTION_TABLE[14]($0 - 1 | 0) | 0
}
return $6 | 0;
}
function runaway() {
- var wasm2js_i32$0 = 0;
- wasm2js_i32$0 = 16, FUNCTION_TABLE[wasm2js_i32$0]();
+ FUNCTION_TABLE[16]();
}
function mutual_runaway1() {
- var wasm2js_i32$0 = 0;
- wasm2js_i32$0 = 18, FUNCTION_TABLE[wasm2js_i32$0]();
+ FUNCTION_TABLE[18]();
}
function mutual_runaway2() {
- var wasm2js_i32$0 = 0;
- wasm2js_i32$0 = 17, FUNCTION_TABLE[wasm2js_i32$0]();
+ FUNCTION_TABLE[17]();
}
function legalstub$17() {
diff --git a/test/wasm2js/emscripten.2asm.js b/test/wasm2js/emscripten.2asm.js
index 5e4109c46..0b1d7ee67 100644
--- a/test/wasm2js/emscripten.2asm.js
+++ b/test/wasm2js/emscripten.2asm.js
@@ -27,10 +27,9 @@ function asmFunc(global, env, buffer) {
var syscall$54 = env.__syscall54;
// EMSCRIPTEN_START_FUNCS;
function main() {
- var wasm2js_i32$0 = 0;
syscall$6(1 | 0, 2 | 0) | 0;
syscall$54(3 | 0, 4 | 0) | 0;
- wasm2js_i32$0 = HEAP32[0 + 1030 >> 2], FUNCTION_TABLE[wasm2js_i32$0]();
+ FUNCTION_TABLE[HEAP32[0 + 1030 >> 2]]();
internal(1);
tabled(1);
exported(1);
diff --git a/test/wasm2js/f32.2asm.js b/test/wasm2js/f32.2asm.js
index 0c852356e..d136a94af 100644
--- a/test/wasm2js/f32.2asm.js
+++ b/test/wasm2js/f32.2asm.js
@@ -121,7 +121,7 @@ function asmFunc(global, env, buffer) {
}
function __wasm_nearest_f32(var$0) {
- var var$1 = Math_fround(0), var$2 = Math_fround(0), wasm2js_f32$0 = Math_fround(0), wasm2js_f32$1 = Math_fround(0), wasm2js_i32$0 = 0;
+ var var$1 = Math_fround(0), var$2 = Math_fround(0);
var$1 = Math_fround(Math_floor(var$0));
var$2 = Math_fround(var$0 - var$1);
if (!(var$2 < Math_fround(.5))) {
@@ -131,15 +131,14 @@ function asmFunc(global, env, buffer) {
return var$0
}
var$2 = Math_fround(var$1 * Math_fround(.5));
- var$1 = (wasm2js_f32$0 = var$1, wasm2js_f32$1 = var$0, wasm2js_i32$0 = Math_fround(var$2 - Math_fround(Math_floor(var$2))) == Math_fround(0.0), wasm2js_i32$0 ? wasm2js_f32$0 : wasm2js_f32$1);
+ var$1 = Math_fround(var$2 - Math_fround(Math_floor(var$2))) == Math_fround(0.0) ? var$1 : var$0;
}
}
return var$1;
}
function __wasm_trunc_f32(var$0) {
- var wasm2js_f32$0 = Math_fround(0), wasm2js_f32$1 = Math_fround(0), wasm2js_i32$0 = 0;
- return wasm2js_f32$0 = Math_fround(Math_ceil(var$0)), wasm2js_f32$1 = Math_fround(Math_floor(var$0)), wasm2js_i32$0 = var$0 < Math_fround(0.0), wasm2js_i32$0 ? wasm2js_f32$0 : wasm2js_f32$1;
+ return var$0 < Math_fround(0.0) ? Math_fround(Math_ceil(var$0)) : Math_fround(Math_floor(var$0));
}
var FUNCTION_TABLE = [];
diff --git a/test/wasm2js/f64.2asm.js b/test/wasm2js/f64.2asm.js
index 7eda48599..727bd7dc4 100644
--- a/test/wasm2js/f64.2asm.js
+++ b/test/wasm2js/f64.2asm.js
@@ -145,7 +145,7 @@ function asmFunc(global, env, buffer) {
}
function __wasm_nearest_f64(var$0) {
- var var$1 = 0.0, var$2 = 0.0, wasm2js_f64$0 = 0.0, wasm2js_f64$1 = 0.0, wasm2js_i32$0 = 0;
+ var var$1 = 0.0, var$2 = 0.0;
var$1 = Math_floor(var$0);
var$2 = var$0 - var$1;
if (!(var$2 < .5)) {
@@ -155,15 +155,14 @@ function asmFunc(global, env, buffer) {
return var$0
}
var$2 = var$1 * .5;
- var$1 = (wasm2js_f64$0 = var$1, wasm2js_f64$1 = var$0, wasm2js_i32$0 = var$2 - Math_floor(var$2) == 0.0, wasm2js_i32$0 ? wasm2js_f64$0 : wasm2js_f64$1);
+ var$1 = var$2 - Math_floor(var$2) == 0.0 ? var$1 : var$0;
}
}
return var$1;
}
function __wasm_trunc_f64(var$0) {
- var wasm2js_f64$0 = 0.0, wasm2js_f64$1 = 0.0, wasm2js_i32$0 = 0;
- return wasm2js_f64$0 = Math_ceil(var$0), wasm2js_f64$1 = Math_floor(var$0), wasm2js_i32$0 = var$0 < 0.0, wasm2js_i32$0 ? wasm2js_f64$0 : wasm2js_f64$1;
+ return var$0 < 0.0 ? Math_ceil(var$0) : Math_floor(var$0);
}
var FUNCTION_TABLE = [];
diff --git a/test/wasm2js/float_misc.2asm.js b/test/wasm2js/float_misc.2asm.js
index 0284b5623..b977cbede 100644
--- a/test/wasm2js/float_misc.2asm.js
+++ b/test/wasm2js/float_misc.2asm.js
@@ -230,7 +230,7 @@ function asmFunc(global, env, buffer) {
}
function __wasm_nearest_f32(var$0) {
- var var$1 = Math_fround(0), var$2 = Math_fround(0), wasm2js_f32$0 = Math_fround(0), wasm2js_f32$1 = Math_fround(0), wasm2js_i32$0 = 0;
+ var var$1 = Math_fround(0), var$2 = Math_fround(0);
var$1 = Math_fround(Math_floor(var$0));
var$2 = Math_fround(var$0 - var$1);
if (!(var$2 < Math_fround(.5))) {
@@ -240,14 +240,14 @@ function asmFunc(global, env, buffer) {
return var$0
}
var$2 = Math_fround(var$1 * Math_fround(.5));
- var$1 = (wasm2js_f32$0 = var$1, wasm2js_f32$1 = var$0, wasm2js_i32$0 = Math_fround(var$2 - Math_fround(Math_floor(var$2))) == Math_fround(0.0), wasm2js_i32$0 ? wasm2js_f32$0 : wasm2js_f32$1);
+ var$1 = Math_fround(var$2 - Math_fround(Math_floor(var$2))) == Math_fround(0.0) ? var$1 : var$0;
}
}
return var$1;
}
function __wasm_nearest_f64(var$0) {
- var var$1 = 0.0, var$2 = 0.0, wasm2js_f64$0 = 0.0, wasm2js_f64$1 = 0.0, wasm2js_i32$0 = 0;
+ var var$1 = 0.0, var$2 = 0.0;
var$1 = Math_floor(var$0);
var$2 = var$0 - var$1;
if (!(var$2 < .5)) {
@@ -257,20 +257,18 @@ function asmFunc(global, env, buffer) {
return var$0
}
var$2 = var$1 * .5;
- var$1 = (wasm2js_f64$0 = var$1, wasm2js_f64$1 = var$0, wasm2js_i32$0 = var$2 - Math_floor(var$2) == 0.0, wasm2js_i32$0 ? wasm2js_f64$0 : wasm2js_f64$1);
+ var$1 = var$2 - Math_floor(var$2) == 0.0 ? var$1 : var$0;
}
}
return var$1;
}
function __wasm_trunc_f32(var$0) {
- var wasm2js_f32$0 = Math_fround(0), wasm2js_f32$1 = Math_fround(0), wasm2js_i32$0 = 0;
- return wasm2js_f32$0 = Math_fround(Math_ceil(var$0)), wasm2js_f32$1 = Math_fround(Math_floor(var$0)), wasm2js_i32$0 = var$0 < Math_fround(0.0), wasm2js_i32$0 ? wasm2js_f32$0 : wasm2js_f32$1;
+ return var$0 < Math_fround(0.0) ? Math_fround(Math_ceil(var$0)) : Math_fround(Math_floor(var$0));
}
function __wasm_trunc_f64(var$0) {
- var wasm2js_f64$0 = 0.0, wasm2js_f64$1 = 0.0, wasm2js_i32$0 = 0;
- return wasm2js_f64$0 = Math_ceil(var$0), wasm2js_f64$1 = Math_floor(var$0), wasm2js_i32$0 = var$0 < 0.0, wasm2js_i32$0 ? wasm2js_f64$0 : wasm2js_f64$1;
+ return var$0 < 0.0 ? Math_ceil(var$0) : Math_floor(var$0);
}
var FUNCTION_TABLE = [];
diff --git a/test/wasm2js/func-ptr-offset.2asm.js b/test/wasm2js/func-ptr-offset.2asm.js
index 2a2a0b425..5789e47d4 100644
--- a/test/wasm2js/func-ptr-offset.2asm.js
+++ b/test/wasm2js/func-ptr-offset.2asm.js
@@ -35,8 +35,7 @@ function asmFunc(global, env, buffer) {
function $3($0) {
$0 = $0 | 0;
- var wasm2js_i32$0 = 0;
- return (wasm2js_i32$0 = $0, FUNCTION_TABLE[wasm2js_i32$0]() | 0) | 0;
+ return FUNCTION_TABLE[$0]() | 0;
}
var FUNCTION_TABLE = [null, t1, t2, t3];
diff --git a/test/wasm2js/func.2asm.js b/test/wasm2js/func.2asm.js
index b87622a7d..a8a0fbffa 100644
--- a/test/wasm2js/func.2asm.js
+++ b/test/wasm2js/func.2asm.js
@@ -393,35 +393,32 @@ function asmFunc(global, env, buffer) {
}
function $76() {
- var wasm2js_i32$0 = 0;
- wasm2js_i32$0 = 1, FUNCTION_TABLE[wasm2js_i32$0]();
- wasm2js_i32$0 = 4, FUNCTION_TABLE[wasm2js_i32$0]();
+ FUNCTION_TABLE[1]();
+ FUNCTION_TABLE[4]();
}
function $77() {
- var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, i64toi32_i32$2 = 0, wasm2js_i32$0 = 0, wasm2js_f64$0 = 0.0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0, wasm2js_f64$1 = 0.0, wasm2js_i32$3 = 0, wasm2js_i32$4 = 0, wasm2js_f64$2 = 0.0, wasm2js_i32$5 = 0, wasm2js_i32$6 = 0, wasm2js_f32$0 = Math_fround(0), wasm2js_i32$7 = 0;
+ var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, i64toi32_i32$2 = 0;
i64toi32_i32$0 = 0;
i64toi32_i32$1 = 0;
i64toi32_i32$2 = 0;
- (((((((((((wasm2js_f64$0 = 0.0, wasm2js_i32$1 = 0), wasm2js_i32$2 = i64toi32_i32$0), wasm2js_f64$1 = 0.0), wasm2js_i32$3 = 0), wasm2js_i32$4 = i64toi32_i32$1), wasm2js_f64$2 = 0.0), wasm2js_i32$5 = 0), wasm2js_i32$6 = i64toi32_i32$2), wasm2js_f32$0 = Math_fround(0.0)), wasm2js_i32$7 = 0), wasm2js_i32$0 = 0), FUNCTION_TABLE[wasm2js_i32$0](+wasm2js_f64$0, wasm2js_i32$1 | 0, wasm2js_i32$2 | 0, +wasm2js_f64$1, wasm2js_i32$3 | 0, wasm2js_i32$4 | 0, +wasm2js_f64$2, wasm2js_i32$5 | 0, wasm2js_i32$6 | 0, Math_fround(wasm2js_f32$0), wasm2js_i32$7 | 0);
+ FUNCTION_TABLE[0](0.0, 0, i64toi32_i32$0, 0.0, 0, i64toi32_i32$1, 0.0, 0, i64toi32_i32$2, Math_fround(0.0), 0);
i64toi32_i32$2 = 0;
i64toi32_i32$1 = 0;
i64toi32_i32$0 = 0;
- (((((((((((wasm2js_f64$2 = 0.0, wasm2js_i32$7 = 0), wasm2js_i32$6 = i64toi32_i32$2), wasm2js_f64$1 = 0.0), wasm2js_i32$5 = 0), wasm2js_i32$4 = i64toi32_i32$1), wasm2js_f64$0 = 0.0), wasm2js_i32$3 = 0), wasm2js_i32$2 = i64toi32_i32$0), wasm2js_f32$0 = Math_fround(0.0)), wasm2js_i32$1 = 0), wasm2js_i32$0 = 2), FUNCTION_TABLE[wasm2js_i32$0](+wasm2js_f64$2, wasm2js_i32$7 | 0, wasm2js_i32$6 | 0, +wasm2js_f64$1, wasm2js_i32$5 | 0, wasm2js_i32$4 | 0, +wasm2js_f64$0, wasm2js_i32$3 | 0, wasm2js_i32$2 | 0, Math_fround(wasm2js_f32$0), wasm2js_i32$1 | 0);
+ FUNCTION_TABLE[2](0.0, 0, i64toi32_i32$2, 0.0, 0, i64toi32_i32$1, 0.0, 0, i64toi32_i32$0, Math_fround(0.0), 0);
i64toi32_i32$0 = 0;
i64toi32_i32$1 = 0;
i64toi32_i32$2 = 0;
- (((((((((((wasm2js_f64$0 = 0.0, wasm2js_i32$1 = 0), wasm2js_i32$2 = i64toi32_i32$0), wasm2js_f64$1 = 0.0), wasm2js_i32$3 = 0), wasm2js_i32$4 = i64toi32_i32$1), wasm2js_f64$2 = 0.0), wasm2js_i32$5 = 0), wasm2js_i32$6 = i64toi32_i32$2), wasm2js_f32$0 = Math_fround(0.0)), wasm2js_i32$7 = 0), wasm2js_i32$0 = 3), FUNCTION_TABLE[wasm2js_i32$0](+wasm2js_f64$0, wasm2js_i32$1 | 0, wasm2js_i32$2 | 0, +wasm2js_f64$1, wasm2js_i32$3 | 0, wasm2js_i32$4 | 0, +wasm2js_f64$2, wasm2js_i32$5 | 0, wasm2js_i32$6 | 0, Math_fround(wasm2js_f32$0), wasm2js_i32$7 | 0);
+ FUNCTION_TABLE[3](0.0, 0, i64toi32_i32$0, 0.0, 0, i64toi32_i32$1, 0.0, 0, i64toi32_i32$2, Math_fround(0.0), 0);
}
function $78() {
- var wasm2js_i32$0 = 0;
- wasm2js_i32$0 = 1, FUNCTION_TABLE[wasm2js_i32$0]();
+ FUNCTION_TABLE[1]();
}
function $79() {
- var wasm2js_i32$0 = 0, wasm2js_f64$0 = 0.0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0, wasm2js_f64$1 = 0.0, wasm2js_i32$3 = 0, wasm2js_i32$4 = 0, wasm2js_f64$2 = 0.0, wasm2js_i32$5 = 0, wasm2js_i32$6 = 0, wasm2js_f32$0 = Math_fround(0), wasm2js_i32$7 = 0;
- (((((((((((wasm2js_f64$0 = 0.0, wasm2js_i32$1 = 0), wasm2js_i32$2 = 0), wasm2js_f64$1 = 0.0), wasm2js_i32$3 = 0), wasm2js_i32$4 = 0), wasm2js_f64$2 = 0.0), wasm2js_i32$5 = 0), wasm2js_i32$6 = 0), wasm2js_f32$0 = Math_fround(0.0)), wasm2js_i32$7 = 0), wasm2js_i32$0 = 0), FUNCTION_TABLE[wasm2js_i32$0](+wasm2js_f64$0, wasm2js_i32$1 | 0, wasm2js_i32$2 | 0, +wasm2js_f64$1, wasm2js_i32$3 | 0, wasm2js_i32$4 | 0, +wasm2js_f64$2, wasm2js_i32$5 | 0, wasm2js_i32$6 | 0, Math_fround(wasm2js_f32$0), wasm2js_i32$7 | 0);
+ FUNCTION_TABLE[0](0.0, 0, 0, 0.0, 0, 0, 0.0, 0, 0, Math_fround(0.0), 0);
}
function legalstub$24() {
diff --git a/test/wasm2js/func_ptrs.2asm.js b/test/wasm2js/func_ptrs.2asm.js
index b1936241d..708879e51 100644
--- a/test/wasm2js/func_ptrs.2asm.js
+++ b/test/wasm2js/func_ptrs.2asm.js
@@ -102,14 +102,12 @@ function asmFunc(global, env, buffer) {
function $5(i) {
i = i | 0;
- var wasm2js_i32$0 = 0;
- return (wasm2js_i32$0 = i, FUNCTION_TABLE[wasm2js_i32$0]() | 0) | 0;
+ return FUNCTION_TABLE[i]() | 0;
}
function $6(i) {
i = i | 0;
- var wasm2js_i32$0 = 0;
- return (wasm2js_i32$0 = i, FUNCTION_TABLE[wasm2js_i32$0]() | 0) | 0;
+ return FUNCTION_TABLE[i]() | 0;
}
var FUNCTION_TABLE = [t1, t2, t3, u1, u2, t1, t3];
@@ -156,8 +154,7 @@ function asmFunc(global, env, buffer) {
function $2(i) {
i = i | 0;
- var wasm2js_i32$0 = 0;
- return (wasm2js_i32$0 = i, FUNCTION_TABLE[wasm2js_i32$0]() | 0) | 0;
+ return FUNCTION_TABLE[i]() | 0;
}
var FUNCTION_TABLE = [t1, t2];
diff --git a/test/wasm2js/left-to-right.2asm.js b/test/wasm2js/left-to-right.2asm.js
index cb551e9ac..7f8a952d9 100644
--- a/test/wasm2js/left-to-right.2asm.js
+++ b/test/wasm2js/left-to-right.2asm.js
@@ -993,7 +993,7 @@ function asmFunc(global, env, buffer) {
}
function $92() {
- var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, $0 = 0, $0$hi = 0, $1 = 0, $1$hi = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0, wasm2js_i32$3 = 0, wasm2js_i32$4 = 0;
+ var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, $0 = 0, $0$hi = 0, $1 = 0, $1$hi = 0;
reset();
i64toi32_i32$0 = i64_left();
i64toi32_i32$1 = i64toi32_i32$HIGH_BITS;
@@ -1005,7 +1005,7 @@ function asmFunc(global, env, buffer) {
$1$hi = i64toi32_i32$0;
i64toi32_i32$0 = $0$hi;
i64toi32_i32$1 = $1$hi;
- ((((wasm2js_i32$1 = $0, wasm2js_i32$2 = i64toi32_i32$0), wasm2js_i32$3 = $1), wasm2js_i32$4 = i64toi32_i32$1), wasm2js_i32$0 = i64_callee()), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0, wasm2js_i32$2 | 0, wasm2js_i32$3 | 0, wasm2js_i32$4 | 0) | 0;
+ FUNCTION_TABLE[i64_callee()]($0, i64toi32_i32$0, $1, i64toi32_i32$1) | 0;
return get() | 0;
}
diff --git a/test/wasm2js/nested-selects.2asm.js b/test/wasm2js/nested-selects.2asm.js
index b0fd8fed0..129ea99c9 100644
--- a/test/wasm2js/nested-selects.2asm.js
+++ b/test/wasm2js/nested-selects.2asm.js
@@ -23,8 +23,7 @@ function asmFunc(global, env, buffer) {
var infinity = global.Infinity;
function $1($0) {
$0 = $0 | 0;
- var wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0, wasm2js_i32$3 = 0, wasm2js_i32$4 = 0, wasm2js_i32$5 = 0;
- return (wasm2js_i32$0 = -1, wasm2js_i32$1 = (wasm2js_i32$3 = 1, wasm2js_i32$4 = 0, wasm2js_i32$5 = ($0 | 0) > (0 | 0), wasm2js_i32$5 ? wasm2js_i32$3 : wasm2js_i32$4), wasm2js_i32$2 = ($0 | 0) < (0 | 0), wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1) | 0;
+ return (($0 | 0) < (0 | 0) ? -1 : ($0 | 0) > (0 | 0) ? 1 : 0) | 0;
}
var FUNCTION_TABLE = [];
diff --git a/test/wasm2js/ordering.2asm.js b/test/wasm2js/ordering.2asm.js
new file mode 100644
index 000000000..6e8f87af0
--- /dev/null
+++ b/test/wasm2js/ordering.2asm.js
@@ -0,0 +1,66 @@
+import { FUNCTION_TABLE } from 'env';
+
+function asmFunc(global, env, buffer) {
+ "almost asm";
+ var HEAP8 = new global.Int8Array(buffer);
+ var HEAP16 = new global.Int16Array(buffer);
+ var HEAP32 = new global.Int32Array(buffer);
+ var HEAPU8 = new global.Uint8Array(buffer);
+ var HEAPU16 = new global.Uint16Array(buffer);
+ var HEAPU32 = new global.Uint32Array(buffer);
+ var HEAPF32 = new global.Float32Array(buffer);
+ var HEAPF64 = new global.Float64Array(buffer);
+ var Math_imul = global.Math.imul;
+ var Math_fround = global.Math.fround;
+ var Math_abs = global.Math.abs;
+ var Math_clz32 = global.Math.clz32;
+ var Math_min = global.Math.min;
+ var Math_max = global.Math.max;
+ var Math_floor = global.Math.floor;
+ var Math_ceil = global.Math.ceil;
+ var Math_sqrt = global.Math.sqrt;
+ var abort = env.abort;
+ var nan = global.NaN;
+ var infinity = global.Infinity;
+ function main() {
+ var wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0;
+ FUNCTION_TABLE[foo(2)](1) | 0;
+ FUNCTION_TABLE[4](foo(3)) | 0;
+ (wasm2js_i32$1 = foo(5), wasm2js_i32$0 = bar(6)), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0) | 0;
+ FUNCTION_TABLE[8](7) | 0;
+ baz(11 ? 9 : 10);
+ baz((wasm2js_i32$0 = foo(12), wasm2js_i32$1 = 13, wasm2js_i32$2 = 14, wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1));
+ baz((wasm2js_i32$0 = 15, wasm2js_i32$1 = foo(16), wasm2js_i32$2 = 17, wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1));
+ baz(foo(20) ? 18 : 19);
+ baz((wasm2js_i32$0 = foo(21), wasm2js_i32$1 = 22, wasm2js_i32$2 = foo(23), wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1));
+ baz((wasm2js_i32$0 = 24, wasm2js_i32$1 = foo(25), wasm2js_i32$2 = foo(26), wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1));
+ baz((wasm2js_i32$0 = foo(27), wasm2js_i32$1 = foo(28), wasm2js_i32$2 = 29, wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1));
+ baz((wasm2js_i32$0 = foo(30), wasm2js_i32$1 = foo(31), wasm2js_i32$2 = foo(32), wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1));
+ }
+
+ function foo($0) {
+ $0 = $0 | 0;
+ return 1 | 0;
+ }
+
+ function bar($0) {
+ $0 = $0 | 0;
+ return 2 | 0;
+ }
+
+ function baz($0) {
+ $0 = $0 | 0;
+ return 3 | 0;
+ }
+
+ FUNCTION_TABLE[1] = foo;
+ FUNCTION_TABLE[2] = bar;
+ FUNCTION_TABLE[3] = baz;
+ return {
+ "main": main
+ };
+}
+
+var memasmFunc = new ArrayBuffer(65536);
+var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc);
+export var main = retasmFunc.main;
diff --git a/test/wasm2js/ordering.wast b/test/wasm2js/ordering.wast
new file mode 100644
index 000000000..a53caafb5
--- /dev/null
+++ b/test/wasm2js/ordering.wast
@@ -0,0 +1,98 @@
+(module
+ (type $0 (func (param i32) (result i32)))
+ (import "env" "table" (table $timport$9 7 funcref))
+ (elem (i32.const 1) $foo $bar $baz)
+ (export "main" (func $main))
+ (func $main
+ (drop
+ (call_indirect (type $0)
+ (i32.const 1)
+ (call $foo (i32.const 2))
+ )
+ )
+ (drop
+ (call_indirect (type $0)
+ (call $foo (i32.const 3))
+ (i32.const 4)
+ )
+ )
+ (drop
+ (call_indirect (type $0)
+ (call $foo (i32.const 5))
+ (call $bar (i32.const 6))
+ )
+ )
+ (drop
+ (call_indirect (type $0)
+ (i32.const 7)
+ (i32.const 8)
+ )
+ )
+ (drop (call $baz
+ (select
+ (i32.const 9)
+ (i32.const 10)
+ (i32.const 11)
+ )
+ ))
+ (drop (call $baz
+ (select
+ (call $foo (i32.const 12))
+ (i32.const 13)
+ (i32.const 14)
+ )
+ ))
+ (drop (call $baz
+ (select
+ (i32.const 15)
+ (call $foo (i32.const 16))
+ (i32.const 17)
+ )
+ ))
+ (drop (call $baz
+ (select
+ (i32.const 18)
+ (i32.const 19)
+ (call $foo (i32.const 20))
+ )
+ ))
+ (drop (call $baz
+ (select
+ (call $foo (i32.const 21))
+ (i32.const 22)
+ (call $foo (i32.const 23))
+ )
+ ))
+ (drop (call $baz
+ (select
+ (i32.const 24)
+ (call $foo (i32.const 25))
+ (call $foo (i32.const 26))
+ )
+ ))
+ (drop (call $baz
+ (select
+ (call $foo (i32.const 27))
+ (call $foo (i32.const 28))
+ (i32.const 29)
+ )
+ ))
+ (drop (call $baz
+ (select
+ (call $foo (i32.const 30))
+ (call $foo (i32.const 31))
+ (call $foo (i32.const 32))
+ )
+ ))
+ )
+ (func $foo (param i32) (result i32)
+ (i32.const 1)
+ )
+ (func $bar (param i32) (result i32)
+ (i32.const 2)
+ )
+ (func $baz (param i32) (result i32)
+ (i32.const 3)
+ )
+)
+
diff --git a/test/wasm2js/select.2asm.js b/test/wasm2js/select.2asm.js
index 07de1de95..efe720c21 100644
--- a/test/wasm2js/select.2asm.js
+++ b/test/wasm2js/select.2asm.js
@@ -28,8 +28,7 @@ function asmFunc(global, env, buffer) {
lhs = lhs | 0;
rhs = rhs | 0;
cond = cond | 0;
- var wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0;
- return (wasm2js_i32$0 = lhs, wasm2js_i32$1 = rhs, wasm2js_i32$2 = cond, wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1) | 0;
+ return (cond ? lhs : rhs) | 0;
}
function $1(lhs, lhs$hi, rhs, rhs$hi, cond) {
@@ -38,13 +37,13 @@ function asmFunc(global, env, buffer) {
rhs = rhs | 0;
rhs$hi = rhs$hi | 0;
cond = cond | 0;
- var i64toi32_i32$0 = 0, i64toi32_i32$4 = 0, i64toi32_i32$3 = 0, i64toi32_i32$2 = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0;
+ var i64toi32_i32$0 = 0, i64toi32_i32$4 = 0, i64toi32_i32$3 = 0, i64toi32_i32$2 = 0;
i64toi32_i32$0 = lhs$hi;
i64toi32_i32$0 = rhs$hi;
i64toi32_i32$4 = cond;
i64toi32_i32$0 = lhs$hi;
- i64toi32_i32$3 = (wasm2js_i32$0 = lhs, wasm2js_i32$1 = rhs, wasm2js_i32$2 = i64toi32_i32$4, wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1);
- i64toi32_i32$2 = (wasm2js_i32$0 = i64toi32_i32$0, wasm2js_i32$1 = rhs$hi, wasm2js_i32$2 = i64toi32_i32$4, wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1);
+ i64toi32_i32$3 = i64toi32_i32$4 ? lhs : rhs;
+ i64toi32_i32$2 = i64toi32_i32$4 ? i64toi32_i32$0 : rhs$hi;
i64toi32_i32$HIGH_BITS = i64toi32_i32$2;
return i64toi32_i32$3 | 0;
}
@@ -53,16 +52,14 @@ function asmFunc(global, env, buffer) {
lhs = Math_fround(lhs);
rhs = Math_fround(rhs);
cond = cond | 0;
- var wasm2js_f32$0 = Math_fround(0), wasm2js_f32$1 = Math_fround(0), wasm2js_i32$0 = 0;
- return Math_fround((wasm2js_f32$0 = lhs, wasm2js_f32$1 = rhs, wasm2js_i32$0 = cond, wasm2js_i32$0 ? wasm2js_f32$0 : wasm2js_f32$1));
+ return Math_fround(cond ? lhs : rhs);
}
function $3(lhs, rhs, cond) {
lhs = +lhs;
rhs = +rhs;
cond = cond | 0;
- var wasm2js_f64$0 = 0.0, wasm2js_f64$1 = 0.0, wasm2js_i32$0 = 0;
- return +(wasm2js_f64$0 = lhs, wasm2js_f64$1 = rhs, wasm2js_i32$0 = cond, wasm2js_i32$0 ? wasm2js_f64$0 : wasm2js_f64$1);
+ return +(cond ? lhs : rhs);
}
function $4(cond) {