diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-03-21 15:33:46 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2016-03-21 15:33:46 -0700 |
commit | b2489b81b9b6fef70e4cbb0af913734442d2bd03 (patch) | |
tree | 70fd888d74b9cf9996976352591f75343ecf81b5 | |
parent | c34ed229b2df8bf4e8d0773917d0301c034980e3 (diff) | |
download | binaryen-b2489b81b9b6fef70e4cbb0af913734442d2bd03.tar.gz binaryen-b2489b81b9b6fef70e4cbb0af913734442d2bd03.tar.bz2 binaryen-b2489b81b9b6fef70e4cbb0af913734442d2bd03.zip |
Make type of EqZ unary operators always i32
This makes them symmetric to binary relational operators.
Also support eqz in the s2wasm parser.
-rw-r--r-- | src/passes/Print.cpp | 2 | ||||
-rw-r--r-- | src/s2wasm.h | 3 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 2 | ||||
-rw-r--r-- | src/wasm.h | 9 |
4 files changed, 12 insertions, 4 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 0fdb4255f..77dcb6154 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -259,7 +259,7 @@ struct PrintSExpression : public WasmVisitor<PrintSExpression, void> { } void visitUnary(Unary *curr) { o << '('; - prepareColor(o) << printWasmType(curr->type) << '.'; + prepareColor(o) << printWasmType(curr->isRelational() ? curr->value->type : curr->type) << '.'; switch (curr->op) { case Clz: o << "clz"; break; case Ctz: o << "ctz"; break; diff --git a/src/s2wasm.h b/src/s2wasm.h index eeff5ba04..6725e305b 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -812,7 +812,8 @@ class S2WasmBuilder { break; } case 'e': { - if (match("eq")) makeBinary(BinaryOp::Eq, i32); + if (match("eqz")) makeUnary(UnaryOp::EqZ, i32); + else if (match("eq")) makeBinary(BinaryOp::Eq, i32); else if (match("extend_s/i32")) makeUnary(UnaryOp::ExtendSInt32, type); else if (match("extend_u/i32")) makeUnary(UnaryOp::ExtendUInt32, type); else abort_on("type.e"); diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 5bb2b44ee..965336857 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -489,7 +489,7 @@ public: case 'e': { if (op[1] == 'q') { if (op[2] == 0) return makeBinary(s, BinaryOp::Eq, type); - if (op[2] == 'z') return makeUnary(s, UnaryOp::EqZ, type); + if (op[2] == 'z') return makeUnary(s, UnaryOp::EqZ, i32); } if (op[1] == 'x') return makeUnary(s, op[7] == 'u' ? UnaryOp::ExtendUInt32 : UnaryOp::ExtendSInt32, type); abort_on(op); diff --git a/src/wasm.h b/src/wasm.h index 2fcc3cddc..7422dd85d 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -681,8 +681,10 @@ public: // Operators enum UnaryOp { - Clz, Ctz, Popcnt, EqZ, // int + Clz, Ctz, Popcnt, // int Neg, Abs, Ceil, Floor, Trunc, Nearest, Sqrt, // float + // relational + EqZ, // conversions ExtendSInt32, ExtendUInt32, WrapInt64, TruncSFloat32, TruncUFloat32, TruncSFloat64, TruncUFloat64, ReinterpretFloat, // int ConvertSInt32, ConvertUInt32, ConvertSInt64, ConvertUInt64, PromoteFloat32, DemoteFloat64, ReinterpretInt // float @@ -972,6 +974,11 @@ public: UnaryOp op; Expression *value; + + // the type is always the type of the operands, + // except for relationals + + bool isRelational() { return op == EqZ; } }; class Binary : public Expression { |