summaryrefslogtreecommitdiff
path: root/src/wasm.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm.h')
-rw-r--r--src/wasm.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/wasm.h b/src/wasm.h
index 86bb91cc5..5a48aa3f2 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -166,6 +166,18 @@ struct Literal {
Literal(float init) : type(WasmType::f32), f32(init) {}
Literal(double init) : type(WasmType::f64), f64(init) {}
+ void printDouble(std::ostream &o, double d) {
+ const char *text = JSPrinter::numToString(d);
+ // spec interpreter hates floats starting with '.'
+ if (text[0] == '.') {
+ o << '0';
+ } else if (text[0] == '-' && text[1] == '.') {
+ o << "-0";
+ text++;
+ }
+ o << text;
+ }
+
friend std::ostream& operator<<(std::ostream &o, Literal literal) {
o << '(';
prepareMinorColor(o) << printWasmType(literal.type) << ".const ";
@@ -173,8 +185,8 @@ struct Literal {
case none: abort();
case WasmType::i32: o << literal.i32; break;
case WasmType::i64: o << literal.i64; break;
- case WasmType::f32: o << JSPrinter::numToString(literal.f32); break;
- case WasmType::f64: o << JSPrinter::numToString(literal.f64); break;
+ case WasmType::f32: literal.printDouble(o, literal.f32); break;
+ case WasmType::f64: literal.printDouble(o, literal.f64); break;
}
restoreNormalColor(o);
return o << ')';