diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-28 13:10:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-28 13:10:59 -0700 |
commit | 2da1b20451a744daa613e818f71e8f52de3a818e (patch) | |
tree | 62632269da091888b428b003c0ae703aa27ee2b3 /src/wasm.cpp | |
parent | ef22ce6c360b70b5bfad40b2930c481d48ed9780 (diff) | |
download | binaryen-2da1b20451a744daa613e818f71e8f52de3a818e.tar.gz binaryen-2da1b20451a744daa613e818f71e8f52de3a818e.tar.bz2 binaryen-2da1b20451a744daa613e818f71e8f52de3a818e.zip |
Type check block/loop/if sigs (#717)
* type check using block/loop/if types provided in text and binary formats.
* print if and loop sigs which were missing.
* remove dsl from OptimizeInstructions as after those changes it needs rethinking.
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; } |