diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2019-04-05 19:48:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-05 19:48:54 -0700 |
commit | 37443aef8c22f100dc59e81aff6af5a252f3217d (patch) | |
tree | ae68bcc8b6bbc4f2b7fdd1f50349b9980e59f10f /src/wasm/wasm-s-parser.cpp | |
parent | 5b24f039ba1f55520a61f6dd6bb8ca46556c592b (diff) | |
download | binaryen-37443aef8c22f100dc59e81aff6af5a252f3217d.tar.gz binaryen-37443aef8c22f100dc59e81aff6af5a252f3217d.tar.bz2 binaryen-37443aef8c22f100dc59e81aff6af5a252f3217d.zip |
Passive segments (#1976)
Adds support for the bulk memory proposal's passive segments. Uses a
new (data passive ...) s-expression syntax to mark sections as
passive.
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index ddda991cd..3ba8e0622 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -1454,7 +1454,8 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) { } else { if (!(inner.size() > 0 ? inner[0]->str() != IMPORT : true)) throw ParseException("bad import ending"); // (memory (data ..)) format - parseInnerData(*s[i]); + auto offset = allocator.alloc<Const>()->set(Literal(int32_t(0))); + parseInnerData(*s[i], 1, offset, false); wasm.memory.initial = wasm.memory.segments[0].data.size(); return; } @@ -1488,16 +1489,26 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) { void SExpressionWasmBuilder::parseData(Element& s) { if (!wasm.memory.exists) throw ParseException("data but no memory"); + bool isPassive = false; + Expression* offset = nullptr; Index i = 1; - if (!s[i]->isList()) { - // the memory is named + if (s[i]->isStr()) { + // data is passive or named + if (s[i]->str() == PASSIVE) { + isPassive = true; + } i++; } - auto* offset = parseExpression(s[i++]); - parseInnerData(s, i, offset); + if (!isPassive) { + offset = parseExpression(s[i]); + } + if (s.size() != 3 && s.size() != 4) { + throw ParseException("Unexpected data items"); + } + parseInnerData(s, s.size() - 1, offset, isPassive); } -void SExpressionWasmBuilder::parseInnerData(Element& s, Index i, Expression* offset) { +void SExpressionWasmBuilder::parseInnerData(Element& s, Index i, Expression* offset, bool isPassive) { std::vector<char> data; while (i < s.size()) { const char *input = s[i++]->c_str(); @@ -1505,10 +1516,7 @@ void SExpressionWasmBuilder::parseInnerData(Element& s, Index i, Expression* off stringToBinary(input, size, data); } } - if (!offset) { - offset = allocator.alloc<Const>()->set(Literal(int32_t(0))); - } - wasm.memory.segments.emplace_back(offset, data.data(), data.size()); + wasm.memory.segments.emplace_back(isPassive, offset, data.data(), data.size()); } void SExpressionWasmBuilder::parseExport(Element& s) { |