summaryrefslogtreecommitdiff
path: root/src/wat-writer.cc
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2023-02-28 16:30:42 -0800
committerGitHub <noreply@github.com>2023-02-28 16:30:42 -0800
commit86d025bff8cac969b3f3e69f2b2a2b00116b496c (patch)
tree69b1386268c83dcaef6d971e9521c1395deef6d1 /src/wat-writer.cc
parent297e6593288ff8b3db1bfc94ee59cb9b42d962ef (diff)
downloadwabt-86d025bff8cac969b3f3e69f2b2a2b00116b496c.tar.gz
wabt-86d025bff8cac969b3f3e69f2b2a2b00116b496c.tar.bz2
wabt-86d025bff8cac969b3f3e69f2b2a2b00116b496c.zip
Always do a full roundtrip in run-roundtrip.py (#1661)
Even when the result is to be printed rather than compared byte for byte with the first version its still good to process the resulting wat output file so that we know we can parse what we generate. Case in point, this changed caused me to fix two latent bugs: 1. We were not correctly parsing events with inline import/export. 2. We were output element segment names even when bulk memory was not enabled (See #1651) The fix for (2) is a little more involved that we might like since for the first time the wat writer needs to know what features are enabled. Fixes: #1651
Diffstat (limited to 'src/wat-writer.cc')
-rw-r--r--src/wat-writer.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/wat-writer.cc b/src/wat-writer.cc
index 5b0e6599..99d5901e 100644
--- a/src/wat-writer.cc
+++ b/src/wat-writer.cc
@@ -1435,7 +1435,15 @@ void WatWriter::WriteTable(const Table& table) {
void WatWriter::WriteElemSegment(const ElemSegment& segment) {
WriteOpenSpace("elem");
- WriteNameOrIndex(segment.name, elem_segment_index_, NextChar::Space);
+ // The first name we encounter here, pre-bulk-memory, was intended to refer to
+ // the table while segment names were not supported at all. For this reason
+ // we cannot emit a segment name here without bulk-memory enabled, otherwise
+ // the name will be assumed to be the name of a table and parsing will fail.
+ if (options_.features.bulk_memory_enabled()) {
+ WriteNameOrIndex(segment.name, elem_segment_index_, NextChar::Space);
+ } else {
+ Writef("(;%u;)", elem_segment_index_);
+ }
uint8_t flags = segment.GetFlags(&module);