diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-05 15:39:35 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-05 15:39:35 -0800 |
commit | b3ee570f3f513e580958e020806df5b014c8b7c0 (patch) | |
tree | 1ec8ff49e90e894cc452431db66f5981c6a93e9e | |
parent | 75e6a46d07ab4a641c2c5676e5276bab014555aa (diff) | |
download | binaryen-b3ee570f3f513e580958e020806df5b014c8b7c0.tar.gz binaryen-b3ee570f3f513e580958e020806df5b014c8b7c0.tar.bz2 binaryen-b3ee570f3f513e580958e020806df5b014c8b7c0.zip |
unnamed naming fixes
-rwxr-xr-x | check.py | 2 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 45 |
2 files changed, 27 insertions, 20 deletions
@@ -83,7 +83,7 @@ if len(requested) == 0: #spec_tests = [] # XXX [os.path.join('spec', t) for t in sorted(os.listdir(os.path.join('test', 'spec')))] # 'address' : filed issue, test looks invalid # 'exports' : has a "return" https://github.com/WebAssembly/spec/issues/164 - spec_tests = [os.path.join('spec', t + '.wast') for t in ['conversions', 'endianness', 'f32_cmp', 'f32', 'f64_cmp', 'f64']] + spec_tests = [os.path.join('spec', t + '.wast') for t in ['conversions', 'endianness', 'f32_cmp', 'f32', 'f64_cmp', 'f64', 'float_exprs', 'forward']] else: spec_tests = requested[:] diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 5b8c2304c..6beadcf8b 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -222,12 +222,25 @@ private: onError(); } + // function parsing state std::map<Name, WasmType> currLocalTypes; - size_t localUnnamed; + size_t localIndex; // params and locals + size_t labelIndex; - 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); + IString getNameWhenNextNotString(Element& s, size_t& i, size_t& index) { + if (s[i]->isStr()) { + index++; + return s[i++]->str(); + } + return IString(std::to_string(index++).c_str(), false); + } + + IString getNameOnCondition(Element& s, size_t& i, size_t& index, bool givenName) { + if (givenName) { + index++; + return s[i++]->str(); + } + return IString(std::to_string(index++).c_str(), false); } void parseFunction(Element& s) { @@ -241,29 +254,23 @@ private: func->name = IString(std::to_string(wasm.functions.size()).c_str(), false); } func->body = nullptr; - localUnnamed = 0; + localIndex = 0; + labelIndex = 0; for (;i < s.size(); i++) { Element& curr = *s[i]; IString id = curr[0]->str(); - if (id == PARAM) { + if (id == PARAM || id == LOCAL) { size_t j = 1; - IString name; - if (curr.size() == 2) { - name = IString(std::to_string(localUnnamed++).c_str(), false); + IString name = getNameOnCondition(curr, j, localIndex, curr.size() == 3); + WasmType type = stringToWasmType(curr[j]->str()); + if (id == PARAM) { + func->params.emplace_back(name, type); } else { - name = curr[j]->str(); - j++; + func->locals.emplace_back(name, type); } - WasmType type = stringToWasmType(curr[j]->str()); - func->params.emplace_back(name, type); currLocalTypes[name] = type; } else if (id == RESULT) { func->result = stringToWasmType(curr[1]->str()); - } else if (id == LOCAL) { - IString name = curr[1]->str(); - WasmType type = stringToWasmType(curr[2]->str()); - func->locals.emplace_back(name, type); - currLocalTypes[name] = type; } else { Expression* ex = parseExpression(curr); if (!func->body) { @@ -713,7 +720,7 @@ private: Expression* makeLabel(Element& s) { auto ret = allocator.alloc<Label>(); size_t i = 1; - ret->name = getNameWhenPossiblyUnnamed(s, i, localUnnamed); + ret->name = getNameWhenNextNotString(s, i, labelIndex); ret->body = parseExpression(s[i]); return ret; } |