diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-10-30 17:32:28 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-10-30 17:32:28 -0700 |
commit | 4a99322972bd744cd97825f6373f1eee3b3d35b1 (patch) | |
tree | 15f625e59e75f360cbc5831d66dc3cf6fd5a3543 | |
parent | b8b69e896b18efbe553bf1c01e4eb3acbfb909f1 (diff) | |
download | binaryen-4a99322972bd744cd97825f6373f1eee3b3d35b1.tar.gz binaryen-4a99322972bd744cd97825f6373f1eee3b3d35b1.tar.bz2 binaryen-4a99322972bd744cd97825f6373f1eee3b3d35b1.zip |
handle aliasing local and global
-rw-r--r-- | src/asm2wasm.cpp | 10 | ||||
-rw-r--r-- | test/unit.asm.js | 11 | ||||
-rw-r--r-- | test/unit.wast | 68 |
3 files changed, 73 insertions, 16 deletions
diff --git a/src/asm2wasm.cpp b/src/asm2wasm.cpp index c594e520d..7f43c7dbc 100644 --- a/src/asm2wasm.cpp +++ b/src/asm2wasm.cpp @@ -352,7 +352,9 @@ private: AsmType detectAsmType(Ref ast, AsmData *data) { if (ast[0] == NAME) { IString name = ast[1]->getIString(); - if (mappedGlobals.find(name) != mappedGlobals.end()) { + if (!data->isLocal(name)) { + // must be global + assert(mappedGlobals.find(name) != mappedGlobals.end()); return wasmToAsmType(mappedGlobals[name].type); } } @@ -385,12 +387,10 @@ private: #if 0 std::cout << "CHECK\n"; left->stringify(std::cout); - std::cout << " => "; - printWasmType(std::cout, leftType); + std::cout << " => " << printWasmType(leftType); std::cout << '\n'; right->stringify(std::cout); - std::cout << " => "; - printWasmType(std::cout, detectWasmType(right, asmData)); + std::cout << " => " << printWasmType(detectWasmType(right, asmData)) << "\n"; #endif bool isInteger = leftType == WasmType::i32; bool isUnsigned = isUnsignedCoercion(left) || isUnsignedCoercion(right); diff --git a/test/unit.asm.js b/test/unit.asm.js index db14f721b..987374fe2 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -2,6 +2,8 @@ function () { "use asm"; var t = global.NaN, u = global.Infinity; + var Int = 0; + var Double = 0.0; function big_negative() { var temp = 0.0; @@ -14,11 +16,18 @@ function () { function importedDoubles() { var temp = 0.0; temp = t + u + (-u) + (-t); + if (Int > 0) return -3.4; + if (Double > 0.0) return 5.6; + return 1.2; } function doubleCompares(x, y) { x = +x; y = +y; - if (x > 0.0) return 0.0; + var t = +0; + var Int = 0.0, Double = 0; // confusing with globals + if (x > 0.0) return 1.2; + if (Int > 0.0) return -3.4; + if (Double > 0) return 5.6; if (x < y) return +x; return +y; } diff --git a/test/unit.wast b/test/unit.wast index 72e124b41..554751130 100644 --- a/test/unit.wast +++ b/test/unit.wast @@ -24,34 +24,64 @@ ) ) ) - (func $importedDoubles + (func $importedDoubles (result f64) (local $temp f64) - (set_local $temp - (f64.add + (block $topmost + (set_local $temp (f64.add (f64.add - (f64.load align=8 - (i32.const 8) + (f64.add + (f64.load align=8 + (i32.const 8) + ) + (f64.load align=8 + (i32.const 16) + ) ) - (f64.load align=8 - (i32.const 16) + (f64.neg + (f64.load align=8 + (i32.const 16) + ) ) ) (f64.neg (f64.load align=8 - (i32.const 16) + (i32.const 8) ) ) ) - (f64.neg + ) + (if + (i32.gt_s + (i32.load align=4 + (i32.const 24) + ) + (i32.const 0) + ) + (break $topmost + (f64.const -3.4) + ) + ) + (if + (f64.gt (f64.load align=8 - (i32.const 8) + (i32.const 32) ) + (f64.const 0) ) + (break $topmost + (f64.const 5.6) + ) + ) + (break $topmost + (f64.const 1.2) ) ) ) (func $doubleCompares (param $x f64) (param $y f64) (result f64) + (local $t f64) + (local $Int f64) + (local $Double i32) (block $topmost (if (f64.gt @@ -59,8 +89,26 @@ (f64.const 0) ) (break $topmost + (f64.const 1.2) + ) + ) + (if + (f64.gt + (get_local $Int) (f64.const 0) ) + (break $topmost + (f64.const -3.4) + ) + ) + (if + (i32.gt_s + (get_local $Double) + (i32.const 0) + ) + (break $topmost + (f64.const 5.6) + ) ) (if (f64.lt |