diff options
Diffstat (limited to 'src/wasm.cpp')
-rw-r--r-- | src/wasm.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/wasm.cpp b/src/wasm.cpp index b5a4314de..cf58949de 100644 --- a/src/wasm.cpp +++ b/src/wasm.cpp @@ -133,6 +133,17 @@ static WasmType mergeTypes(std::vector<WasmType>& types) { return type; } +void Block::finalize(WasmType type_) { + type = type_; + if (type == none && list.size() > 0) { + if (list.back()->type == unreachable) { + if (!BreakSeeker::has(this, name)) { + type = unreachable; // the last element is unreachable, and this block truly cannot be exited, so it is unreachable itself + } + } + } +} + void Block::finalize() { if (!name.is()) { // nothing branches here, so this is easy @@ -148,6 +159,38 @@ void Block::finalize() { type = mergeTypes(seeker.types); } +void If::finalize(WasmType type_) { + type = type_; + if (type == none && (condition->type == unreachable || (ifTrue->type == unreachable && (!ifFalse || ifFalse->type == unreachable)))) { + type = unreachable; + } +} + +void If::finalize() { + if (condition->type == unreachable) { + type = unreachable; + } else if (ifFalse) { + if (ifTrue->type == ifFalse->type) { + type = ifTrue->type; + } else if (isConcreteWasmType(ifTrue->type) && ifFalse->type == unreachable) { + type = ifTrue->type; + } else if (isConcreteWasmType(ifFalse->type) && ifTrue->type == unreachable) { + type = ifFalse->type; + } else { + type = none; + } + } else { + type = none; // if without else + } +} + +void Loop::finalize(WasmType type_) { + type = type_; + if (type == none && body->type == unreachable) { + type = unreachable; + } +} + void Loop::finalize() { type = body->type; } |