diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-07 21:25:14 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-07 21:25:14 -0800 |
commit | bc74a6478aa229abf6dbf7269e67aeeb570e7554 (patch) | |
tree | f24fd1e1ed75184abd5d2710a93a4b9a889a3d94 /src/wasm-interpreter.h | |
parent | 8efa11fbb9ff8cfd8bacc9d16642e13e2bbac9b4 (diff) | |
parent | 9407880de631fb4e9f8caa0c746e4d39f40be91d (diff) | |
download | binaryen-bc74a6478aa229abf6dbf7269e67aeeb570e7554.tar.gz binaryen-bc74a6478aa229abf6dbf7269e67aeeb570e7554.tar.bz2 binaryen-bc74a6478aa229abf6dbf7269e67aeeb570e7554.zip |
Merge pull request #231 from WebAssembly/spec-updates
Spec updates
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index a7405e948..223a9e1a5 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -256,40 +256,24 @@ private: } Flow visitSwitch(Switch *curr) { NOTE_ENTER("Switch"); - Flow flow = visit(curr->value); - if (flow.breaking()) { - flow.clearIf(curr->name); - return flow; - } + Flow flow = visit(curr->condition); + if (flow.breaking()) return flow; NOTE_EVAL1(flow.value); int64_t index = flow.value.getInteger(); + + if (curr->value) { + flow = visit(curr->value); + if (flow.breaking()) return flow; + NOTE_EVAL1(flow.value); + } else { + flow = Flow(); + } + Name target = curr->default_; if (index >= 0 && (size_t)index < curr->targets.size()) { target = curr->targets[index]; } - // This is obviously very inefficient. This should be a cached data structure - std::map<Name, size_t> caseMap; // name => index in cases - for (size_t i = 0; i < curr->cases.size(); i++) { - caseMap[curr->cases[i].name] = i; - } - auto iter = caseMap.find(target); - if (iter == caseMap.end()) { - // not in the cases, so this is a break - Flow flow(target); - flow.clearIf(curr->name); - return flow; - } - size_t caseIndex = iter->second; - assert(caseIndex < curr->cases.size()); - while (caseIndex < curr->cases.size()) { - Switch::Case& c = curr->cases[caseIndex]; - flow = visit(c.body); - if (flow.breaking()) { - flow.clearIf(curr->name); - break; - } - caseIndex++; - } + flow.breakTo = target; return flow; } |