diff options
-rw-r--r-- | src/wasm-s-parser.h | 27 | ||||
-rw-r--r-- | src/wasm.h | 2 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 677052984..0166d0726 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -491,6 +491,7 @@ public: if (op[1] == 'u') return makeBinary(s, BinaryOp::Sub, type); if (op[1] == 'q') return makeUnary(s, UnaryOp::Sqrt, type); if (op[1] == 't') return makeStore(s, type); + if (op[1] == 'w') return makeSwitch(s, type); abort_on(op); } case 't': { @@ -930,6 +931,32 @@ private: return ret; } + Expression* makeSwitch(Element& s, WasmType type) { + abort(); + auto ret = allocator.alloc<Switch>(); + ret->type = type; + size_t i = 1; + if (s[i]->isStr()) { + ret->name = s[i]->str(); + i++; + } + ret->value = parseExpression(s[i]); + i++; + Element& targets = *s[i]; + i++; + for (size_t j = 0; j < targets.size(); j++) { + ret->targets.push_back(targets[i]->str()); + } + Element& cases = *s[i]; + i++; + for (size_t j = 0; j < cases.size(); j++) { + Element& curr = *cases[i]; + ret->cases.emplace_back(curr[0]->str(), parseExpression(curr[1])); + } + ret->updateCaseMap(); + return ret; + } + void parseMemory(Element& s) { wasm.memory.initial = atoi(s[1]->c_str()); if (s.size() == 2) return; diff --git a/src/wasm.h b/src/wasm.h index 62a263ae9..6eee9d8a2 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -359,6 +359,8 @@ public: struct Case { Name name; Expression *body; + Case() {} + Case(Name name, Expression *body) : name(name), body(body) {} }; Name name; |