summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp7
-rw-r--r--src/wasm/wasm-s-parser.cpp35
2 files changed, 24 insertions, 18 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 31a6ccaae..b4b4ef70f 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2803,12 +2803,11 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
printName(segment.name, o);
o << ' ';
}
- if (segment.isPassive) {
- printMedium(o, "passive");
- } else {
+ if (!segment.isPassive) {
visit(segment.offset);
+ o << ' ';
}
- o << " \"";
+ o << "\"";
for (size_t i = 0; i < segment.data.size(); i++) {
unsigned char c = segment.data[i];
switch (c) {
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(