diff options
-rw-r--r-- | src/emscripten-optimizer/simple_ast.h | 6 | ||||
-rw-r--r-- | src/wasm2asm.h | 11 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h index 942121015..94cae9f2f 100644 --- a/src/emscripten-optimizer/simple_ast.h +++ b/src/emscripten-optimizer/simple_ast.h @@ -1615,6 +1615,12 @@ public: .push_back(target) .push_back(value); } + static Ref makeAssign(IString target, Ref value) { + return &makeRawArray(3)->push_back(makeRawString(ASSIGN)) + .push_back(&arena.alloc()->setBool(true)) + .push_back(makeName(target)) + .push_back(value); + } static Ref makeSub(Ref obj, Ref index) { return &makeRawArray(2)->push_back(makeRawString(SUB)) diff --git a/src/wasm2asm.h b/src/wasm2asm.h index b09d4ef7c..eabea83ea 100644 --- a/src/wasm2asm.h +++ b/src/wasm2asm.h @@ -453,7 +453,7 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { if (result != NO_RESULT) { ret[1]->push_back(ValueBuilder::makeStatement( ValueBuilder::makeAssign( - ValueBuilder::makeName(result), + result, visit(curr->list[size-1], result) ) )); @@ -648,7 +648,12 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { Unary fakeUnary = *curr; fakeUnary.value = &fakeLocal; Ref ret = blockify(visitAndAssign(curr->value, temp)); - ret[1]->push_back(visit(&fakeUnary, result)); + ret[1]->push_back(ValueBuilder::makeStatement( + ValueBuilder::makeAssign( + result, + visit(&fakeUnary, result) + ) + )); return ret; } // normal unary @@ -666,7 +671,7 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { case f64: { Ref ret; switch (curr->op) { - case Neg: ret = ValueBuilder::makeBinary(ValueBuilder::makeDouble(0), MINUS, value); break; + case Neg: ret = ValueBuilder::makeUnary(MINUS, value); break; case Abs: ret = ValueBuilder::makeCall(MATH_ABS, value); break; case Ceil: ret = ValueBuilder::makeCall(MATH_CEIL, value); break; case Floor: ret = ValueBuilder::makeCall(MATH_FLOOR, value); break; |