summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r--src/wasm/wasm-s-parser.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 32f555d5a..d6cef72cd 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -2858,27 +2858,34 @@ void SExpressionWasmBuilder::parseData(Element& s) {
if (!wasm.memory.exists) {
throw ParseException("data but no memory", s.line, s.col);
}
- bool isPassive = false;
+ bool isPassive = true;
Expression* offset = nullptr;
Index i = 1;
Name name;
- if (s[i]->dollared()) {
+
+ if (s[i]->isStr() && s[i]->dollared()) {
name = s[i++]->str();
}
- if (s[i]->isStr()) {
- // data is passive or named
- if (s[i]->str() == PASSIVE) {
- isPassive = true;
+
+ if (s[i]->isList()) {
+ // Optional (memory <memoryidx>)
+ if (elementStartsWith(s[i], MEMORY)) {
+ // TODO: we're just skipping memory since we have only one. Assign the
+ // memory name to the segment when we support multiple memories.
+ i += 1;
}
- i++;
- }
- if (!isPassive) {
- offset = parseExpression(s[i]);
- }
- if (s.size() != 3 && s.size() != 4) {
- throw ParseException("Unexpected data items", s.line, s.col);
+
+ // Offset expression (offset (<expr>)) | (<expr>)
+ auto& inner = *s[i++];
+ if (elementStartsWith(inner, OFFSET)) {
+ offset = parseExpression(inner[1]);
+ } else {
+ offset = parseExpression(inner);
+ }
+ isPassive = false;
}
- parseInnerData(s, s.size() - 1, name, offset, isPassive);
+
+ parseInnerData(s, i, name, offset, isPassive);
}
void SExpressionWasmBuilder::parseInnerData(