summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-10-31 10:22:58 -0700
committerAlon Zakai <alonzakai@gmail.com>2015-10-31 10:22:58 -0700
commitf7c1b4907c40dfd46da8e86f2c23412f8603479a (patch)
tree8f49fceac4161b6ba79e73d1b4e87a47cb6719c4 /src
parent16414bf70e5143726907cbeecd868a5439e291c9 (diff)
downloadbinaryen-f7c1b4907c40dfd46da8e86f2c23412f8603479a.tar.gz
binaryen-f7c1b4907c40dfd46da8e86f2c23412f8603479a.tar.bz2
binaryen-f7c1b4907c40dfd46da8e86f2c23412f8603479a.zip
unary and binary
Diffstat (limited to 'src')
-rw-r--r--src/wasm-interpreter.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/wasm-interpreter.cpp b/src/wasm-interpreter.cpp
index b8593dbc2..92966f7c6 100644
--- a/src/wasm-interpreter.cpp
+++ b/src/wasm-interpreter.cpp
@@ -183,8 +183,43 @@ public:
return Flow(curr->value); // heh
}
Flow visitUnary(Unary *curr) override {
+ Flow flow = visit(curr->value);
+ if (flow.breaking()) return flow;
+ Literal value = flow.value;
+ switch (curr->op) { // rofl
+ case Clz: return Flow(Literal((int32_t)__builtin_clz(value.geti32())));
+ case Neg: return Flow(Literal(-value.getf64()));
+ case Floor: return Flow(Literal(floor(value.getf64())));
+ default: abort();
+ }
}
Flow visitBinary(Binary *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) { // lmao
+ 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())));
+ default: abort();
+ }
}
Flow visitCompare(Compare *curr) override {
}