From c1d97e9c75c687faa81fe0ab4f1ac77c30487f47 Mon Sep 17 00:00:00 2001 From: Keith Winstein <208955+keithw@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:37:12 -0800 Subject: wat-writer.cc: update text serialization of data memuse (#2501) --- src/wat-writer.cc | 6 +++++- test/regress/write-memuse.txt | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/regress/write-memuse.txt diff --git a/src/wat-writer.cc b/src/wat-writer.cc index 88ff60ba..b458eca1 100644 --- a/src/wat-writer.cc +++ b/src/wat-writer.cc @@ -1504,7 +1504,11 @@ void WatWriter::WriteDataSegment(const DataSegment& segment) { WriteOpenSpace("data"); WriteNameOrIndex(segment.name, data_segment_index_, NextChar::Space); if (segment.kind != SegmentKind::Passive) { - WriteMemoryVarUnlessZero(segment.memory_var, NextChar::Space); + if (module.GetMemoryIndex(segment.memory_var) != 0) { + WriteOpenSpace("memory"); + WriteVar(segment.memory_var, NextChar::Space); + WriteCloseSpace(); + } WriteInitExpr(segment.offset); } WriteQuotedData(segment.data.data(), segment.data.size()); diff --git a/test/regress/write-memuse.txt b/test/regress/write-memuse.txt new file mode 100644 index 00000000..5217cfec --- /dev/null +++ b/test/regress/write-memuse.txt @@ -0,0 +1,4 @@ +;;; TOOL: run-roundtrip +;;; ARGS*: --enable-multi-memory --debug-names +(memory 0) +(memory $k (data)) -- cgit v1.2.3