diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-02-01 11:14:39 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-02-01 11:14:39 -0800 |
commit | b4e04afe0a74edf35642908e715e2497f6c18e7f (patch) | |
tree | f2b319b0982900aaa1d3fb3052f52870362d0021 /src | |
parent | 45aa22043f265eafe701d5dda76f78cf50b2bf9c (diff) | |
download | binaryen-b4e04afe0a74edf35642908e715e2497f6c18e7f.tar.gz binaryen-b4e04afe0a74edf35642908e715e2497f6c18e7f.tar.bz2 binaryen-b4e04afe0a74edf35642908e715e2497f6c18e7f.zip |
use getReachableWasmType in if_else and select
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-binary.h | 2 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 2 | ||||
-rw-r--r-- | src/wasm.h | 9 |
3 files changed, 9 insertions, 4 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index c020c3efb..26673a966 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1314,7 +1314,7 @@ public: readExpression(curr->ifTrue); if (code == BinaryConsts::IfElse) { readExpression(curr->ifFalse); - curr->type = curr->ifTrue->type; + curr->finalize(); } } void visitLoop(Loop *curr) { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index bf9cd239f..c8d4015ea 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -797,7 +797,7 @@ private: ret->ifTrue = parseExpression(s[2]); if (s.size() == 4) { ret->ifFalse = parseExpression(s[3]); - ret->type = ret->ifTrue->type == ret->ifFalse->type ? ret->ifTrue->type : none; // if not the same type, this does not return a value + ret->finalize(); } return ret; } diff --git a/src/wasm.h b/src/wasm.h index 52082f3a8..ca396fd24 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -432,6 +432,12 @@ public: if (ifFalse) printFullLine(o, indent, ifFalse); return decIndent(o, indent); } + + void finalize() { + if (condition) { + type = getReachableWasmType(ifTrue->type, ifFalse->type); + } + } }; class Loop : public Expression { @@ -892,8 +898,7 @@ public: } void finalize() { - type = ifTrue->type; - if (type == none) type = ifFalse->type; // ifTrue might be unreachable + type = getReachableWasmType(ifTrue->type, ifFalse->type); } }; |