diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-05 15:21:10 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-05 15:21:10 -0800 |
commit | b991b575a8b97a4ff83cb99448c0249526e86549 (patch) | |
tree | f860b0a2ab24466d26824a7c0186dd18ddbfe3af /src/wasm-s-parser.h | |
parent | 18ed75e5a7da5dfd14e5a2c8d3fee5b9eaf7f284 (diff) | |
download | binaryen-b991b575a8b97a4ff83cb99448c0249526e86549.tar.gz binaryen-b991b575a8b97a4ff83cb99448c0249526e86549.tar.bz2 binaryen-b991b575a8b97a4ff83cb99448c0249526e86549.zip |
parsing improvements for local unnamed
Diffstat (limited to 'src/wasm-s-parser.h')
-rw-r--r-- | src/wasm-s-parser.h | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 1e934a96f..5b8c2304c 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -196,9 +196,7 @@ private: class SExpressionWasmBuilder { Module& wasm; - MixedArena allocator; - std::function<void ()> onError; public: @@ -225,22 +223,38 @@ private: } std::map<Name, WasmType> currLocalTypes; + size_t localUnnamed; + + IString getNameWhenPossiblyUnnamed(Element& s, size_t& i, size_t& unnamed) { + if (s[i]->isStr()) return s[i++]->str(); + return IString(std::to_string(unnamed++).c_str(), false); + } void parseFunction(Element& s) { auto func = allocator.alloc<Function>(); - if (s[1]->isStr()) { - func->name = s[1]->str(); + size_t i = 1; + if (s[i]->isStr()) { + func->name = s[i]->str(); + i++; } else { // unnamed, use an index func->name = IString(std::to_string(wasm.functions.size()).c_str(), false); } func->body = nullptr; - for (unsigned i = 2; i < s.size(); i++) { + localUnnamed = 0; + for (;i < s.size(); i++) { Element& curr = *s[i]; IString id = curr[0]->str(); if (id == PARAM) { - IString name = curr[1]->str(); - WasmType type = stringToWasmType(curr[2]->str()); + size_t j = 1; + IString name; + if (curr.size() == 2) { + name = IString(std::to_string(localUnnamed++).c_str(), false); + } else { + name = curr[j]->str(); + j++; + } + WasmType type = stringToWasmType(curr[j]->str()); func->params.emplace_back(name, type); currLocalTypes[name] = type; } else if (id == RESULT) { @@ -446,6 +460,7 @@ public: abort_on(str); } case 'l': { + if (str[1] == 'a') return makeLabel(s); if (str[1] == 'o') return makeLoop(s); abort_on(str); } @@ -695,6 +710,14 @@ private: return ret; } + Expression* makeLabel(Element& s) { + auto ret = allocator.alloc<Label>(); + size_t i = 1; + ret->name = getNameWhenPossiblyUnnamed(s, i, localUnnamed); + ret->body = parseExpression(s[i]); + return ret; + } + Expression* makeLoop(Element& s) { auto ret = allocator.alloc<Loop>(); size_t i = 1; |