summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-18 11:43:26 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-18 11:43:26 -0800
commit876495a6c436a0a0fe6980e3dce49d3a7f0a5cf6 (patch)
tree2cd495bbac379a012750dfd1109f1a368616c25a /src
parentcb41c9a8b11970a01e3f2f1eb2d8d38e29e7489b (diff)
downloadbinaryen-876495a6c436a0a0fe6980e3dce49d3a7f0a5cf6.tar.gz
binaryen-876495a6c436a0a0fe6980e3dce49d3a7f0a5cf6.tar.bz2
binaryen-876495a6c436a0a0fe6980e3dce49d3a7f0a5cf6.zip
HEAPF32 is an f32 heap, and we need to cast f64s before writing to it
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 505e3ee87..07e771108 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -481,7 +481,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
} else if (heap == UINT32ARRAY) {
bytes = 4; integer = true; signed_ = false; asmType = ASM_INT;
} else if (heap == FLOAT32ARRAY) {
- bytes = 4; integer = false; signed_ = true; asmType = ASM_DOUBLE;
+ bytes = 4; integer = false; signed_ = true; asmType = ASM_FLOAT;
} else if (heap == FLOAT64ARRAY) {
bytes = 8; integer = false; signed_ = true; asmType = ASM_DOUBLE;
}
@@ -671,7 +671,19 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
ret->align = view.bytes;
ret->ptr = processUnshifted(target[2], view.bytes);
ret->value = process(ast[3]);
- ret->type = ret->value->type;
+ ret->type = asmToWasmType(view.type);
+ if (ret->type != ret->value->type) {
+ // in asm.js we have some implicit coercions that we must do explicitly here
+ if (ret->type == f32 && ret->value->type == f64) {
+ auto conv = allocator.alloc<Convert>();
+ conv->op = DemoteFloat64;
+ conv->value = ret->value;
+ conv->type = WasmType::f32;
+ ret->value = conv;
+ } else {
+ abort();
+ }
+ }
return ret;
}
abort_on("confusing assign", ast);