diff options
author | Abbas Mashayekh <martianboy2005@gmail.com> | 2021-03-31 01:04:20 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-30 13:34:20 -0700 |
commit | daa7e66be52285a0cbee04a7cf69886c63610097 (patch) | |
tree | fbbec2d89c46b809f64e429af932542adbe945f3 /src | |
parent | 4441588c356ece316a36019715e511b7eed36021 (diff) | |
download | binaryen-daa7e66be52285a0cbee04a7cf69886c63610097.tar.gz binaryen-daa7e66be52285a0cbee04a7cf69886c63610097.tar.bz2 binaryen-daa7e66be52285a0cbee04a7cf69886c63610097.zip |
Remove passive keyword from data segment parser (#3757)
The passive keyword has been removed from spec's text format, and now
any data segment that doesn't have an offset is considered as passive.
This PR remove that from both parser and the Print pass, plus all tests
that used that syntax.
Fixes #2339
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Print.cpp | 7 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 35 |
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( |