From daa7e66be52285a0cbee04a7cf69886c63610097 Mon Sep 17 00:00:00 2001 From: Abbas Mashayekh Date: Wed, 31 Mar 2021 01:04:20 +0430 Subject: 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 --- src/passes/Print.cpp | 7 +++---- src/wasm/wasm-s-parser.cpp | 35 +++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'src') 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 { 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 ) + 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 ()) | () + 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( -- cgit v1.2.3