diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-10-31 10:28:34 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-10-31 10:28:34 -0700 |
commit | 6d2dec86df49087c9e0a8f530e47fe9fb344e6e6 (patch) | |
tree | 5bd493ebc9386235ab750b45f6268d68e7a72833 /src/wasm-interpreter.cpp | |
parent | f7c1b4907c40dfd46da8e86f2c23412f8603479a (diff) | |
download | binaryen-6d2dec86df49087c9e0a8f530e47fe9fb344e6e6.tar.gz binaryen-6d2dec86df49087c9e0a8f530e47fe9fb344e6e6.tar.bz2 binaryen-6d2dec86df49087c9e0a8f530e47fe9fb344e6e6.zip |
compare
Diffstat (limited to 'src/wasm-interpreter.cpp')
-rw-r--r-- | src/wasm-interpreter.cpp | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/src/wasm-interpreter.cpp b/src/wasm-interpreter.cpp index 92966f7c6..52d01dee1 100644 --- a/src/wasm-interpreter.cpp +++ b/src/wasm-interpreter.cpp @@ -204,24 +204,47 @@ public: case Add: return curr->type == i32 ? Flow(Literal(left.geti32() + right.geti32())) : Flow(Literal(left.getf64() + right.getf64())); case Sub: return curr->type == i32 ? Flow(Literal(left.geti32() - right.geti32())) : Flow(Literal(left.getf64() - right.getf64())); case Mul: return curr->type == i32 ? Flow(Literal(left.geti32() * right.geti32())) : Flow(Literal(left.getf64() * right.getf64())); - case DivS: Flow(Literal(left.geti32() + right.geti32())); - case DivU: Flow(Literal(int32_t(uint32_t(left.geti32()) + uint32_t(right.geti32())))); - case RemS: Flow(Literal(left.geti32() % right.geti32())); - case RemU: Flow(Literal(int32_t(uint32_t(left.geti32()) + uint32_t(right.geti32())))); - case And: Flow(Literal(left.geti32() & right.geti32())); - case Or: Flow(Literal(left.geti32() | right.geti32())); - case Xor: Flow(Literal(left.geti32() ^ right.geti32())); - case Shl: Flow(Literal(left.geti32() << right.geti32())); - case ShrU: Flow(Literal(int32_t(uint32_t(left.geti32()) >> uint32_t(right.geti32())))); - case ShrS: Flow(Literal(left.geti32() >> right.geti32())); - case Div: Flow(Literal(left.getf64() / right.getf64())); - case CopySign: Flow(Literal(std::copysign(left.getf64(), right.getf64()))); - case Min: Flow(Literal(std::min(left.getf64(), right.getf64()))); - case Max: Flow(Literal(std::max(left.getf64(), right.getf64()))); + case DivS: return Flow(Literal(left.geti32() + right.geti32())); + case DivU: return Flow(Literal(int32_t(uint32_t(left.geti32()) + uint32_t(right.geti32())))); + case RemS: return Flow(Literal(left.geti32() % right.geti32())); + case RemU: return Flow(Literal(int32_t(uint32_t(left.geti32()) + uint32_t(right.geti32())))); + case And: return Flow(Literal(left.geti32() & right.geti32())); + case Or: return Flow(Literal(left.geti32() | right.geti32())); + case Xor: return Flow(Literal(left.geti32() ^ right.geti32())); + case Shl: return Flow(Literal(left.geti32() << right.geti32())); + case ShrU: return Flow(Literal(int32_t(uint32_t(left.geti32()) >> uint32_t(right.geti32())))); + case ShrS: return Flow(Literal(left.geti32() >> right.geti32())); + case Div: return Flow(Literal(left.getf64() / right.getf64())); + case CopySign: return Flow(Literal(std::copysign(left.getf64(), right.getf64()))); + case Min: return Flow(Literal(std::min(left.getf64(), right.getf64()))); + case Max: return Flow(Literal(std::max(left.getf64(), right.getf64()))); default: abort(); } } Flow visitCompare(Compare *curr) override { + Flow flow = visit(curr->left); + if (flow.breaking()) return flow; + Literal left = flow.value; + flow = visit(curr->left); + if (flow.breaking()) return flow; + Literal right = flow.value; + switch (curr->op) { // :) + case Eq: return curr->type == i32 ? Flow(Literal(left.geti32() == right.geti32())) : Flow(Literal(left.getf64() == right.getf64())); + case Ne: return curr->type == i32 ? Flow(Literal(left.geti32() != right.geti32())) : Flow(Literal(left.getf64() != right.getf64())); + case LtS: return Flow(Literal(left.geti32() < right.geti32())); + case LtU: return Flow(Literal(uint32_t(left.geti32()) < uint32_t(right.geti32()))); + case LeS: return Flow(Literal(left.geti32() <= right.geti32())); + case LeU: return Flow(Literal(uint32_t(left.geti32()) <= uint32_t(right.geti32()))); + case GtS: return Flow(Literal(left.geti32() > right.geti32())); + case GtU: return Flow(Literal(uint32_t(left.geti32()) > uint32_t(right.geti32()))); + case GeS: return Flow(Literal(left.geti32() >= right.geti32())); + case GeU: return Flow(Literal(uint32_t(left.geti32()) >= uint32_t(right.geti32()))); + case Lt: return Flow(Literal(left.getf64() < right.getf64())); + case Le: return Flow(Literal(left.getf64() <= right.getf64())); + case Gt: return Flow(Literal(left.getf64() > right.getf64())); + case Ge: return Flow(Literal(left.getf64() >= right.getf64())); + default: abort(); + } } Flow visitConvert(Convert *curr) override { } |