summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-04-02 10:36:19 -0700
committerGitHub <noreply@github.com>2020-04-02 10:36:19 -0700
commit80c5164e1f50ed26e6fab373a563fd7a84135429 (patch)
treeac944407ac6bf1b26e524d31a3db8c410e4599e7 /src/wasm/wasm-s-parser.cpp
parent702b99508487bc5f56c409d890644b3b9212ae81 (diff)
downloadbinaryen-80c5164e1f50ed26e6fab373a563fd7a84135429.tar.gz
binaryen-80c5164e1f50ed26e6fab373a563fd7a84135429.tar.bz2
binaryen-80c5164e1f50ed26e6fab373a563fd7a84135429.zip
Tuple globals (#2718)
Since it wasn't easy to support tuples in Asyncify's call support using temporary functions, we decided to allow tuple-typed globals after all. This PR adds support for parsing, printing, lowering, and interpreting tuple globals and also adds validation ensuring that imported and exported globals do not have tuple types.
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r--src/wasm/wasm-s-parser.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 4354b747a..a39e52b6d 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -546,12 +546,7 @@ SExpressionWasmBuilder::parseParamOrLocal(Element& s, size_t& localIndex) {
throw ParseException(
"params may not have tuple types", s[i]->line, s[i]->col);
}
- auto& tuple = s[i]->list();
- std::vector<Type> types;
- for (size_t j = 0; j < s[i]->size(); ++j) {
- types.push_back(stringToType(tuple[j]->str()));
- }
- type = Type(types);
+ type = elementToType(*s[i]);
}
namedParams.emplace_back(name, type);
}
@@ -886,6 +881,18 @@ Type SExpressionWasmBuilder::stringToType(const char* str,
throw ParseException(std::string("invalid wasm type: ") + str);
}
+Type SExpressionWasmBuilder::elementToType(Element& s) {
+ if (s.isStr()) {
+ return stringToType(s.str(), false, false);
+ }
+ auto& tuple = s.list();
+ std::vector<Type> types;
+ for (size_t i = 0; i < s.size(); ++i) {
+ types.push_back(stringToType(tuple[i]->str()));
+ }
+ return Type(types);
+}
+
Type SExpressionWasmBuilder::stringToLaneType(const char* str) {
if (strcmp(str, "i8x16") == 0) {
return Type::i32;
@@ -2278,7 +2285,7 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) {
bool exported = false;
Name importModule, importBase;
while (i < s.size() && s[i]->isList()) {
- auto& inner = *s[i];
+ auto& inner = *s[i++];
if (elementStartsWith(inner, EXPORT)) {
auto ex = make_unique<Export>();
ex->name = inner[1]->str();
@@ -2289,16 +2296,15 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) {
}
wasm.addExport(ex.release());
exported = true;
- i++;
} else if (elementStartsWith(inner, IMPORT)) {
importModule = inner[1]->str();
importBase = inner[2]->str();
- i++;
} else if (elementStartsWith(inner, MUT)) {
mutable_ = true;
- type = stringToType(inner[1]->str());
- i++;
+ type = elementToType(*inner[1]);
+ break;
} else {
+ type = elementToType(inner);
break;
}
}