diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-11 20:51:05 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-11 21:27:07 -0700 |
commit | 4ed9d8f6608d768fe9ef2e2916e770d605e6b0e1 (patch) | |
tree | 8a771418f0eca742e2375073e02d2765ce645f42 /src/ast_utils.h | |
parent | 6eccbd4c70fb31a788e6a93ee2a163bb7dc6d06b (diff) | |
download | binaryen-4ed9d8f6608d768fe9ef2e2916e770d605e6b0e1.tar.gz binaryen-4ed9d8f6608d768fe9ef2e2916e770d605e6b0e1.tar.bz2 binaryen-4ed9d8f6608d768fe9ef2e2916e770d605e6b0e1.zip |
remove final elements in vacuum carefully: we must preserve a return value if there is one
Diffstat (limited to 'src/ast_utils.h')
-rw-r--r-- | src/ast_utils.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h index e785a8daa..f883d5f66 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -28,18 +28,26 @@ namespace wasm { struct BreakSeeker : public PostWalker<BreakSeeker, Visitor<BreakSeeker>> { Name target; // look for this one XXX looking by name may fall prey to duplicate names Index found; + WasmType valueType; - BreakSeeker(Name target) : target(target), found(false) {} + BreakSeeker(Name target) : target(target), found(0) {} + + void noteFound(Expression* value) { + found++; + if (found == 1) valueType = unreachable; + if (!value) valueType = none; + else if (value->type != unreachable) valueType = value->type; + } void visitBreak(Break *curr) { - if (curr->name == target) found++; + if (curr->name == target) noteFound(curr->value); } void visitSwitch(Switch *curr) { for (auto name : curr->targets) { - if (name == target) found++; + if (name == target) noteFound(curr->value); } - if (curr->default_ == target) found++; + if (curr->default_ == target) noteFound(curr->value); } static bool has(Expression* tree, Name target) { |