summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h14
-rw-r--r--src/emscripten-optimizer/simple_ast.h4
2 files changed, 10 insertions, 8 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 377b6b20b..87fd10649 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -443,9 +443,13 @@ private:
std::map<unsigned, Ref> tempNums;
- Literal checkLiteral(Ref ast) {
+ Literal checkLiteral(Ref ast, bool rawIsInteger = true) {
if (ast[0] == NUM) {
- return Literal((int32_t)ast[1]->getInteger());
+ if (rawIsInteger) {
+ return Literal((int32_t)ast[1]->getInteger());
+ } else {
+ return Literal(ast[1]->getNumber());
+ }
} else if (ast[0] == UNARY_PREFIX) {
if (ast[1] == PLUS && ast[2][0] == NUM) {
return Literal((double)ast[2][1]->getNumber());
@@ -1475,10 +1479,8 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
}
if (name == Math_fround) {
assert(ast[2]->size() == 1);
- Literal lit = checkLiteral(ast[2][0]);
- if (lit.type == i32) {
- return builder.makeConst(Literal((float)lit.geti32()));
- } else if (lit.type == f64) {
+ Literal lit = checkLiteral(ast[2][0], false /* raw is float */);
+ if (lit.type == f64) {
return builder.makeConst(Literal((float)lit.getf64()));
}
auto ret = allocator.alloc<Unary>();
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h
index 3f0d363df..20de952c1 100644
--- a/src/emscripten-optimizer/simple_ast.h
+++ b/src/emscripten-optimizer/simple_ast.h
@@ -225,9 +225,9 @@ struct Value {
return boo;
}
- int getInteger() { // convenience function to get a known integer
+ int32_t getInteger() { // convenience function to get a known integer
assert(fmod(getNumber(), 1) == 0);
- int ret = int(getNumber());
+ int32_t ret = getNumber();
assert(double(ret) == getNumber()); // no loss in conversion
return ret;
}