diff options
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 4346fe705..6dfd495c0 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2704,6 +2704,18 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { if (curr->data.empty()) { return; } + bool allElementsRefFunc = + std::all_of(curr->data.begin(), curr->data.end(), [](Expression* entry) { + return entry->is<RefFunc>(); + }); + auto printElemType = [&]() { + if (allElementsRefFunc) { + TypeNamePrinter(o, currModule).print(HeapType::func); + } else { + TypeNamePrinter(o, currModule).print(Type::funcref); + } + }; + doIndent(o, indent); o << '('; printMedium(o, "elem"); @@ -2714,7 +2726,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { if (curr->table.is()) { // TODO(reference-types): check for old-style based on the complete spec - if (currModule->tables.size() > 1) { + if (!allElementsRefFunc || currModule->tables.size() > 1) { // tableuse o << " (table "; printName(curr->table, o); @@ -2724,18 +2736,26 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { o << ' '; visit(curr->offset); - if (currModule->tables.size() > 1) { + if (!allElementsRefFunc || currModule->tables.size() > 1) { o << ' '; - TypeNamePrinter(o, currModule).print(HeapType::func); + printElemType(); } } else { o << ' '; - TypeNamePrinter(o, currModule).print(HeapType::func); + printElemType(); } - for (auto name : curr->data) { - o << ' '; - printName(name, o); + if (allElementsRefFunc) { + for (auto* entry : curr->data) { + auto* refFunc = entry->cast<RefFunc>(); + o << ' '; + printName(refFunc->func, o); + } + } else { + for (auto* entry : curr->data) { + o << ' '; + printExpression(entry, o); + } } o << ')' << maybeNewLine; } |