diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-26 21:22:29 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-26 21:22:29 -0800 |
commit | 6f91d9e310b206ae801768f45f4a82aa647df1c6 (patch) | |
tree | ca2ea5d0b34dedd7c4255605210ff3325ee80f6c | |
parent | a7bfbd7ab12aca7d1592e04165c3d0ec00c962e8 (diff) | |
download | binaryen-6f91d9e310b206ae801768f45f4a82aa647df1c6.tar.gz binaryen-6f91d9e310b206ae801768f45f4a82aa647df1c6.tar.bz2 binaryen-6f91d9e310b206ae801768f45f4a82aa647df1c6.zip |
wasm2asm progress
-rw-r--r-- | src/emscripten-optimizer/simple_ast.h | 7 | ||||
-rw-r--r-- | src/wasm2asm.h | 35 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h index 9e19249ab..632e9053d 100644 --- a/src/emscripten-optimizer/simple_ast.h +++ b/src/emscripten-optimizer/simple_ast.h @@ -1336,6 +1336,13 @@ public: .push_back(target) .push_back(makeRawArray()); } + static Ref makeCall(IString target, Ref arg) { + auto ret = &makeRawArray(3)->push_back(makeRawString(CALL)) + .push_back(makeName(target)) + .push_back(makeRawArray()); + ret[2]->push_back(arg); + return ret; + } static void appendToCall(Ref call, Ref element) { assert(call[0] == CALL); diff --git a/src/wasm2asm.h b/src/wasm2asm.h index 4785f7322..01f3758d4 100644 --- a/src/wasm2asm.h +++ b/src/wasm2asm.h @@ -583,6 +583,41 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { } } void visitUnary(Unary *curr) override { + if (isStatement(curr)) { + ScopedTemp temp(curr->value->type, parent); + GetLocal fakeLocal; + fakeLocal.name = temp.getName(); + Unary fakeUnary = *curr; + fakeUnary.value = &fakeLocal; + Ref ret = blockify(visitAndAssign(curr->value, temp)); + ret[1]->push_back(visit(&fakeUnary, result)); + return ret; + } + // normal unary + Ref value = visit(curr->value, EXPRESSION_RESULT); + switch (curr-type) { + case i32: { + switch (curr->op) { + case Clz: return ValueBuilder::makeCall(MATH_CLZ32, value); + case Ctz: return ValueBuilder::makeCall(MATH_CTZ32, value); + case Popcnt: return ValueBuilder::makeCall(MATH_POPCNT32, value); + default: abort(); + } + } + case f64: { + switch (curr->op) { + case Neg: return ValueBuilder::makeBinary(ValueBuilder::makeDouble(0), MINUS, value); + case Abs: return ValueBuilder::makeCall(MATH_ABS, value); + case Ceil: return ValueBuilder::makeCall(MATH_CEIL, value); + case Floor: return ValueBuilder::makeCall(MATH_FLOOR, value); + case Trunc: return ValueBuilder::makeCall(MATH_TRUNC, value); + case Nearest: return ValueBuilder::makeCall(MATH_NEAREST, value); + case Sqrt: return ValueBuilder::makeCall(MATH_SQRT, value); + default: abort(); + } + } + default: abort(); + } } void visitBinary(Binary *curr) override { } |