diff options
-rw-r--r-- | src/wasm-binary.h | 7 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 28 |
2 files changed, 13 insertions, 22 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index b5de9b100..4110c9cd6 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -619,8 +619,9 @@ public: uint16_t getInt16(); uint32_t getInt32(); uint64_t getInt64(); - float getFloat32(); - double getFloat64(); + // it is unsafe to return a float directly, due to ABI issues with the signalling bit + Literal getFloat32Literal(); + Literal getFloat64Literal(); uint32_t getU32LEB(); uint64_t getU64LEB(); int32_t getS32LEB(); @@ -632,8 +633,6 @@ public: void verifyInt16(int16_t x); void verifyInt32(int32_t x); void verifyInt64(int64_t x); - void verifyFloat32(float x); - void verifyFloat64(double x); void ungetInt8(); void readHeader(); void readStart(); diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 5398edfdc..74169fce2 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -636,11 +636,11 @@ void WasmBinaryWriter::visitConst(Const *curr) { break; } case f32: { - o << int8_t(BinaryConsts::F32Const) << curr->value.getf32(); + o << int8_t(BinaryConsts::F32Const) << curr->value.reinterpreti32(); break; } case f64: { - o << int8_t(BinaryConsts::F64Const) << curr->value.getf64(); + o << int8_t(BinaryConsts::F64Const) << curr->value.reinterpreti64(); break; } default: abort(); @@ -919,16 +919,18 @@ uint64_t WasmBinaryBuilder::getInt64() { return ret; } -float WasmBinaryBuilder::getFloat32() { +Literal WasmBinaryBuilder::getFloat32Literal() { if (debug) std::cerr << "<==" << std::endl; - auto ret = Literal(getInt32()).reinterpretf32(); + auto ret = Literal(getInt32()); + ret = ret.castToF32(); if (debug) std::cerr << "getFloat32: " << ret << " ==>" << std::endl; return ret; } -double WasmBinaryBuilder::getFloat64() { +Literal WasmBinaryBuilder::getFloat64Literal() { if (debug) std::cerr << "<==" << std::endl; - auto ret = Literal(getInt64()).reinterpretf64(); + auto ret = Literal(getInt64()); + ret = ret.castToF64(); if (debug) std::cerr << "getFloat64: " << ret << " ==>" << std::endl; return ret; } @@ -1024,16 +1026,6 @@ void WasmBinaryBuilder::verifyInt64(int64_t x) { if (x != y) throw ParseException("surprising value", 0, pos); } -void WasmBinaryBuilder::verifyFloat32(float x) { - float y = getFloat32(); - if (x != y) throw ParseException("surprising value", 0, pos); -} - -void WasmBinaryBuilder::verifyFloat64(double x) { - double y = getFloat64(); - if (x != y) throw ParseException("surprising value", 0, pos); -} - void WasmBinaryBuilder::ungetInt8() { assert(pos > 0); if (debug) std::cerr << "ungetInt8 (at " << pos << ")" << std::endl; @@ -1704,8 +1696,8 @@ bool WasmBinaryBuilder::maybeVisitConst(Expression*& out, uint8_t code) { switch (code) { case BinaryConsts::I32Const: curr = allocator.alloc<Const>(); curr->value = Literal(getS32LEB()); break; case BinaryConsts::I64Const: curr = allocator.alloc<Const>(); curr->value = Literal(getS64LEB()); break; - case BinaryConsts::F32Const: curr = allocator.alloc<Const>(); curr->value = Literal(getFloat32()); break; - case BinaryConsts::F64Const: curr = allocator.alloc<Const>(); curr->value = Literal(getFloat64()); break; + case BinaryConsts::F32Const: curr = allocator.alloc<Const>(); curr->value = getFloat32Literal(); break; + case BinaryConsts::F64Const: curr = allocator.alloc<Const>(); curr->value = getFloat64Literal(); break; default: return false; } curr->type = curr->value.type; |