diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-02-08 11:26:33 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-02-08 11:40:55 -0800 |
commit | 7dc054d36488bdea267dfb394758fc56a28e397e (patch) | |
tree | 3d6c7eab469df3e37adbc637cf3d3ee913053231 | |
parent | 74d54530b2405f67332d636de19f79894cb2a419 (diff) | |
download | binaryen-7dc054d36488bdea267dfb394758fc56a28e397e.tar.gz binaryen-7dc054d36488bdea267dfb394758fc56a28e397e.tar.bz2 binaryen-7dc054d36488bdea267dfb394758fc56a28e397e.zip |
check break types in validator
-rw-r--r-- | src/wasm-validator.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/wasm-validator.h b/src/wasm-validator.h index ba4e5fe08..fad33a081 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -28,6 +28,8 @@ namespace wasm { struct WasmValidator : public WasmWalker<WasmValidator> { bool valid; + std::map<Name, WasmType> breakTypes; // breaks to a label must all have the same type, and the right type + public: bool validate(Module& module) { valid = true; @@ -37,6 +39,15 @@ public: // visitors + void visitBlock(Block *curr) { + // if we are break'ed to, then the value must be right for us + if (curr->name.is()) { + if (breakTypes.count(curr->name) > 0) { + shouldBeTrue(curr->type == breakTypes[curr->name]); + breakTypes.erase(curr->name); + } + } + } void visitLoop(Loop *curr) { if (curr->in.is()) { LoopChildChecker childChecker(curr->in); @@ -44,6 +55,17 @@ public: shouldBeTrue(childChecker.valid); } } + void visitBreak(Break *curr) { + WasmType valueType = none; + if (curr->value) { + valueType = curr->value->type; + } + if (breakTypes.count(curr->name) == 0) { + breakTypes[curr->name] = valueType; + } else { + shouldBeTrue(valueType == breakTypes[curr->name]); + } + } void visitSetLocal(SetLocal *curr) { shouldBeTrue(curr->type == curr->value->type); } |