summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h28
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) {