summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2017-06-27 14:24:21 -0700
committerGitHub <noreply@github.com>2017-06-27 14:24:21 -0700
commit21e08eeef1ccc489cd06495e4370e1dffccfe088 (patch)
treecf10711c6eb26acf378da8cdcc4d7e961ef582bf /src/wasm/wasm-s-parser.cpp
parentbf37733de319b5e0f0b6b0205c1745c5214fea1e (diff)
downloadbinaryen-21e08eeef1ccc489cd06495e4370e1dffccfe088.tar.gz
binaryen-21e08eeef1ccc489cd06495e4370e1dffccfe088.tar.bz2
binaryen-21e08eeef1ccc489cd06495e4370e1dffccfe088.zip
Add shared memories (#1069)
Begin to implement wasm threading proposal in https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md This PR just has shared memory attribute with wast and binary support.
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r--src/wasm/wasm-s-parser.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 59043f3b8..6bf030302 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1440,10 +1440,28 @@ void SExpressionWasmBuilder::stringToBinary(const char* input, size_t size, std:
data.resize(actual);
}
+Index SExpressionWasmBuilder::parseMemoryLimits(Element& s, Index i) {
+ wasm.memory.initial = getCheckedAddress(s[i++], "excessive memory init");
+ if (i == s.size()) return i;
+ while (i < s.size() && s[i]->isStr()) {
+ auto* curr = s[i]->c_str();
+ i++;
+ if (strstr(curr, "shared")) {
+ wasm.memory.shared = strncmp(curr, "notshared", 9) != 0;
+ break;
+ }
+ uint64_t max = atoll(curr);
+ if (max > Memory::kMaxSize) throw ParseException("total memory must be <= 4GB");
+ wasm.memory.max = max;
+ }
+ return i;
+}
+
void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
if (wasm.memory.exists) throw ParseException("too many memories");
wasm.memory.exists = true;
wasm.memory.imported = preParseImport;
+ wasm.memory.shared = false;
Index i = 1;
if (s[i]->dollared()) {
wasm.memory.name = s[i++]->str();
@@ -1478,14 +1496,9 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
return;
}
}
- wasm.memory.initial = getCheckedAddress(s[i++], "excessive memory init");
- if (i == s.size()) return;
- if (s[i]->isStr()) {
- uint64_t max = atoll(s[i]->c_str());
- if (max > Memory::kMaxSize) throw ParseException("total memory must be <= 4GB");
- wasm.memory.max = max;
- i++;
- }
+ i = parseMemoryLimits(s, i);
+
+ // Parse memory initializers.
while (i < s.size()) {
Element& curr = *s[i];
size_t j = 1;
@@ -1683,12 +1696,7 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
}
// ends with the table element type
} else if (im->kind == ExternalKind::Memory) {
- if (j < inner.size()) {
- wasm.memory.initial = getCheckedAddress(inner[j++], "excessive memory init size");
- }
- if (j < inner.size()) {
- wasm.memory.max = getCheckedAddress(inner[j++], "excessive memory max size");
- }
+ j = parseMemoryLimits(inner, j);
}
if (wasm.getImportOrNull(im->name)) throw ParseException("duplicate import", s.line, s.col);
wasm.addImport(im.release());