diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-02 14:40:44 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-02 14:52:28 -0800 |
commit | 0da73c1845a58823c0fde138115849a65f79e0ea (patch) | |
tree | e50e275ca25442846ea86fe5c5ef25ff7b0ff688 /src/wasm-interpreter.h | |
parent | 25a335b740da7e7f199edcad617251d19aa6b18b (diff) | |
download | binaryen-0da73c1845a58823c0fde138115849a65f79e0ea.tar.gz binaryen-0da73c1845a58823c0fde138115849a65f79e0ea.tar.bz2 binaryen-0da73c1845a58823c0fde138115849a65f79e0ea.zip |
implement switch
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 022b274af..6e1c960bc 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -163,7 +163,33 @@ public: } Flow visitSwitch(Switch *curr) override { NOTE_ENTER("Switch"); - abort(); + Flow flow = visit(curr->value); + if (flow.breaking()) { + flow.clearIf(curr->name); + return flow; + } + int32_t index = flow.value.geti32(); + Name target = curr->default_; + if (index >= 0 && index < curr->targets.size()) { + target = curr->targets[index]; + } + auto iter = curr->caseMap.find(target); + if (iter == curr->caseMap.end()) { + // not in the cases, so this is a break outside + return Flow(target); + } + size_t caseIndex = iter->second; + assert(caseIndex < curr->cases.size()); + while (caseIndex < curr->cases.size()) { + Switch::Case& c = curr->cases[caseIndex]; + Flow flow = visit(c.body); + if (flow.breaking()) { + flow.clearIf(c.name); + return flow; + } + caseIndex++; + } + return Flow(); } Flow generateArguments(const ExpressionList& operands, LiteralList& arguments) { |