summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-interpreter.h9
-rw-r--r--src/wasm-s-parser.h6
-rw-r--r--src/wasm.h2
3 files changed, 13 insertions, 4 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index f72dc524e..0843de8b4 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -359,13 +359,18 @@ public:
case ExtendSInt32: return Flow(Literal(int64_t(value.geti32())));
case ExtendUInt32: return Flow(Literal(uint64_t((uint32_t)value.geti32())));
case WrapInt64: return Flow(Literal(int32_t(value.geti64())));
- case TruncSFloat32: {
+ case TruncSFloat32: {
float val = value.getf32();
if (isnan(val)) instance.externalInterface->trap();
if (val > (double)INT_MAX || val < (double)INT_MIN) instance.externalInterface->trap();
return Flow(Literal(int32_t(val)));
}
- case TruncUFloat32: return Flow(Literal(uint32_t(value.getf32())));
+ case TruncUFloat32: {
+ float val = value.getf32();
+ if (isnan(val)) instance.externalInterface->trap();
+ if (val > (double)UINT_MAX || val <= (double)-1) instance.externalInterface->trap();
+ return Flow(Literal(uint32_t(val)));
+ }
case TruncSFloat64: return Flow(Literal(int32_t(value.getf64())));
case TruncUFloat64: return Flow(Literal(int32_t((uint32_t)value.getf64())));
case ReinterpretFloat: return curr->type == i32 ? Flow(Literal(value.reinterpreti32())) : Flow(Literal(value.reinterpreti64()));
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 81c0e73b4..9bffbba0a 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -381,7 +381,11 @@ public:
abort_on(op);
}
case 't': {
- if (op[1] == 'r') return makeConvert(s, type == i32 ? ConvertOp::TruncSFloat32 : ConvertOp::TruncSFloat64, type);
+ if (op[1] == 'r') {
+ if (type == i32) return makeConvert(s, op[6] == 's' ? ConvertOp::TruncSFloat32 : ConvertOp::TruncUFloat32, type);
+ if (type == i64) return makeConvert(s, op[6] == 's' ? ConvertOp::TruncSFloat64 : ConvertOp::TruncUFloat64, type);
+ abort();
+ }
abort_on(op);
}
case 'w': {
diff --git a/src/wasm.h b/src/wasm.h
index 2c78182f8..db0abcba7 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -692,7 +692,7 @@ public:
std::ostream& doPrint(std::ostream &o, unsigned indent) {
o << '(';
- prepareColor(o) << printWasmType(type);
+ prepareColor(o) << printWasmType(type) << '.';
switch (op) {
case ExtendSInt32: o << "extend_s/i32"; break;
case ExtendUInt32: o << "extend_u/i32"; break;