diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-02-08 13:33:34 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-02-08 13:33:34 -0800 |
commit | 2262204746437423211930d83d8ea336be3efac2 (patch) | |
tree | 7d85bb4d6ab8531abc074d3a5043fb00963fdb9e /src/wasm-validator.h | |
parent | 271504de91e3f396251041f94c0f29094af92207 (diff) | |
parent | 28ac77ff3f5668d543a6c7a99f3e1b1dceff6201 (diff) | |
download | binaryen-2262204746437423211930d83d8ea336be3efac2.tar.gz binaryen-2262204746437423211930d83d8ea336be3efac2.tar.bz2 binaryen-2262204746437423211930d83d8ea336be3efac2.zip |
Merge pull request #189 from WebAssembly/br_if-changes
br_if updates
Diffstat (limited to 'src/wasm-validator.h')
-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); } |