diff options
author | Abbas Mashayekh <martianboy2005@gmail.com> | 2021-04-21 03:41:32 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-20 16:11:32 -0700 |
commit | 304658d67102d3ddd5aa8ea59bcc94402d8338b8 (patch) | |
tree | 7404815766468730b1338967e61afcdb5701f69c /src | |
parent | 1afe9d4374f6920981be132e1538f63b8f053c02 (diff) | |
download | binaryen-304658d67102d3ddd5aa8ea59bcc94402d8338b8.tar.gz binaryen-304658d67102d3ddd5aa8ea59bcc94402d8338b8.tar.bz2 binaryen-304658d67102d3ddd5aa8ea59bcc94402d8338b8.zip |
Fix element segment ordering in Print (#3818)
We used to print active element segments right after corresponding
tables, and passive segments came after those. We didn't print internal
segment names, and empty segments weren't being printed at all. This
meant that there was no way for instructions to refer to those table
segments after round tripping.
This will fix those issues by printing segments in the order they were
defined, including segment names when necessary and not omitting
empty segments anymore.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Print.cpp | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index fa61a3d1c..1392ccb6f 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2634,23 +2634,8 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { printTableHeader(curr); o << maybeNewLine; } - - ModuleUtils::iterTableSegments( - *currModule, curr->name, [&](ElementSegment* segment) { - printElementSegment(segment); - }); } void visitElementSegment(ElementSegment* curr) { - if (curr->table.is()) { - return; - } - printElementSegment(curr); - } - void printElementSegment(ElementSegment* curr) { - // Don't print empty segments - if (curr->data.empty()) { - return; - } bool allElementsRefFunc = std::all_of(curr->data.begin(), curr->data.end(), [](Expression* entry) { return entry->is<RefFunc>(); @@ -2666,7 +2651,9 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { doIndent(o, indent); o << '('; printMedium(o, "elem"); - if (curr->hasExplicitName) { + // If there is no explicit name, and there are multiple segments, use our + // internal names to differentiate them. + if (curr->hasExplicitName || currModule->elementSegments.size() > 1) { o << ' '; printName(curr->name, o); } |