summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.cpp2
-rw-r--r--src/wasm.h7
-rw-r--r--test/unit.asm.js6
-rw-r--r--test/unit.wast16
4 files changed, 28 insertions, 3 deletions
diff --git a/src/asm2wasm.cpp b/src/asm2wasm.cpp
index 609909ab8..b02b4aa52 100644
--- a/src/asm2wasm.cpp
+++ b/src/asm2wasm.cpp
@@ -780,6 +780,7 @@ Function* Asm2WasmModule::processFunction(Ref ast) {
ret->op = relational;
ret->left = process(ast[2]);
ret->right = process(ast[3]);
+ ret->inputType = ret->left->type;
return ret;
}
} else if (what == NUM) {
@@ -899,6 +900,7 @@ Function* Asm2WasmModule::processFunction(Ref ast) {
ret->op = Eq;
ret->left = process(ast[2]);
ret->right = allocator.alloc<Const>()->set(Literal(0));
+ ret->inputType = ret->left->type;
return ret;
}
abort_on("bad unary", ast);
diff --git a/src/wasm.h b/src/wasm.h
index 5a48aa3f2..2e383d83b 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -225,7 +225,7 @@ enum HostOp {
class Expression {
public:
- WasmType type;
+ WasmType type; // the type of the expression: its output, not necessarily its input(s)
Expression() : type(type) {}
@@ -607,15 +607,16 @@ public:
class Compare : public Expression {
public:
RelationalOp op;
+ WasmType inputType;
Expression *left, *right;
Compare() {
- type = WasmType::i32;
+ type = WasmType::i32; // output is always i32
}
std::ostream& print(std::ostream &o, unsigned indent) override {
o << '(';
- prepareColor(o) << printWasmType(type) << '.';
+ prepareColor(o) << printWasmType(inputType) << '.';
switch (op) {
case Eq: o << "eq"; break;
case Ne: o << "ne"; break;
diff --git a/test/unit.asm.js b/test/unit.asm.js
index 80bab6242..2b599d99a 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -15,6 +15,12 @@ function () {
var temp = 0.0;
temp = t + u + (-u) + (-t);
}
+ function doubleCompares(x, y) {
+ x = +x;
+ y = +y;
+ if (x < y) return +x;
+ return +y;
+ }
function z() {
}
diff --git a/test/unit.wast b/test/unit.wast
index 2c16af17d..9e4b19eb4 100644
--- a/test/unit.wast
+++ b/test/unit.wast
@@ -51,6 +51,22 @@
)
)
)
+ (func $doubleCompares (param $x f64) (param $y f64) (result f64)
+ (block $topmost
+ (if
+ (f64.lt
+ (get_local $x)
+ (get_local $y)
+ )
+ (break $topmost
+ (get_local $x)
+ )
+ )
+ (break $topmost
+ (get_local $y)
+ )
+ )
+ )
(func $z
(nop)
)