diff options
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r-- | src/wasm-binary.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 16e24fcb8..79742a414 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -554,8 +554,18 @@ public: } void visitSwitch(Switch *curr) { o << int8_t(BinaryConsts::TableSwitch) << int16_t(curr->cases.size()) - << int16_t(curr->targets.size()); - abort(); // WTF + << int16_t(curr->targets.size()); + std::map<Name, int16_t> mapping; // target name => index in cases + for (size_t i = 0; i < curr->cases.size(); i++) { + mapping[curr->cases[i].name] = i; + } + for (auto target : curr->targets) { + o << mapping[target]; + } + visit(curr->value); + for (auto c : curr->cases) { + visit(c.body); + } } void visitCall(Call *curr) { o << int8_t(BinaryConsts::CallFunction) << LEB128(getFunctionIndex(curr->target)); |