diff options
-rw-r--r-- | src/asm2wasm.cpp | 18 | ||||
-rw-r--r-- | test/unit.asm.js | 11 | ||||
-rw-r--r-- | test/unit.wast | 19 |
3 files changed, 43 insertions, 5 deletions
diff --git a/src/asm2wasm.cpp b/src/asm2wasm.cpp index 6e597ab94..4273793ba 100644 --- a/src/asm2wasm.cpp +++ b/src/asm2wasm.cpp @@ -446,8 +446,14 @@ private: if (ast[0] == NUM) { return Literal((int32_t)ast[1]->getInteger()); } else if (ast[0] == UNARY_PREFIX) { - assert(ast[1] == MINUS && ast[2][0] == NUM); - return Literal((int32_t)-ast[2][1]->getInteger()); + if (ast[1] == MINUS && ast[2][0] == NUM) { + double num = -ast[2][1]->getNumber(); + assert(isInteger32(num)); + return Literal((int32_t)num); + } + if (ast[1] == MINUS && ast[2][0] == UNARY_PREFIX && ast[2][1] == PLUS && ast[2][2][0] == NUM) { + return Literal((double)-ast[2][2][1]->getNumber()); + } } abort(); } @@ -625,8 +631,10 @@ void Asm2WasmModule::processAsm(Ref ast) { } Function* Asm2WasmModule::processFunction(Ref ast) { + //if (ast[1] !=IString("_fmod")) return nullptr; + if (debug) { - std::cout << "func: "; + std::cout << "\nfunc: "; ast->stringify(std::cout); std::cout << '\n'; } @@ -836,7 +844,7 @@ Function* Asm2WasmModule::processFunction(Ref ast) { ret->type = BasicType::f64; // we add it here for e.g. call coercions return ret; } else if (ast[1] == MINUS) { - if (ast[2][0] == NUM) { + if (ast[2][0] == NUM || (ast[2][0] == UNARY_PREFIX && ast[2][1] == PLUS && ast[2][2][0] == NUM)) { auto ret = allocator.alloc<Const>(); ret->value = getLiteral(ast); ret->type = ret->value.type; @@ -1192,7 +1200,7 @@ int main(int argc, char **argv) { char *infile = argv[1]; - if (debug) std::cerr << "loading '%s'...\n", infile; + if (debug) std::cerr << "loading '" << infile << "'...\n"; FILE *f = fopen(argv[1], "r"); assert(f); fseek(f, 0, SEEK_END); diff --git a/test/unit.asm.js b/test/unit.asm.js new file mode 100644 index 000000000..fd05746d6 --- /dev/null +++ b/test/unit.asm.js @@ -0,0 +1,11 @@ +function () { + "use asm"; + function big_negative() { + var temp = 0.0; + temp = -2147483648; + temp = -2147483648.0; + temp = -21474836480.0; + } + return { big_negative: big_negative }; +} + diff --git a/test/unit.wast b/test/unit.wast new file mode 100644 index 000000000..b5e054593 --- /dev/null +++ b/test/unit.wast @@ -0,0 +1,19 @@ +(module + (memory 16777216) + (export "big_negative" $big_negative) + (func $big_negative + (local $temp f64) + (block + (set_local $temp + (i32.const -2147483648) + ) + (set_local $temp + (f64.const -2147483648) + ) + (set_local $temp + (f64.const -21474836480) + ) + ) + ) +) + |