Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Current Trunk
-------------
- The `tuple.make` pseudoinstruction now requires an immediate giving its
arity. For example, to make a tuple of two elements, use `tuple.make 2`.
- The text format for `if` expressions now requires `then` and `else` to
introduce the two branch arms, matching the spec.

v116
----
Expand Down
32 changes: 20 additions & 12 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {

// loop, if, and try can contain implicit blocks. But they are not needed to
// be printed in some cases.
void maybePrintImplicitBlock(Expression* curr, bool allowMultipleInsts);
void maybePrintImplicitBlock(Expression* curr);

// Generic visitor, overridden only when necessary.
void visitExpression(Expression* curr);
Expand Down Expand Up @@ -2563,11 +2563,9 @@ void PrintSExpression::printFullLine(Expression* expression) {
o << maybeNewLine;
}

void PrintSExpression::maybePrintImplicitBlock(Expression* curr,
bool allowMultipleInsts) {
void PrintSExpression::maybePrintImplicitBlock(Expression* curr) {
auto block = curr->dynCast<Block>();
if (!full && block && block->name.isNull() &&
(allowMultipleInsts || block->list.size() == 1)) {
if (!full && block && block->name.isNull()) {
for (auto expression : block->list) {
printFullLine(expression);
}
Expand Down Expand Up @@ -2657,13 +2655,23 @@ void PrintSExpression::visitIf(If* curr) {
printExpressionContents(curr);
incIndent();
printFullLine(curr->condition);
maybePrintImplicitBlock(curr->ifTrue, false);
doIndent(o, indent);
o << "(then";
incIndent();
maybePrintImplicitBlock(curr->ifTrue);
decIndent();
o << maybeNewLine;
if (curr->ifFalse) {
doIndent(o, indent);
o << "(else";
incIndent();
// Note: debug info here is not used as LLVM does not emit ifs, and since
// LLVM is the main source of DWARF, effectively we never encounter ifs
// with DWARF.
printDebugDelimiterLocation(curr, BinaryLocations::Else);
maybePrintImplicitBlock(curr->ifFalse, false);
maybePrintImplicitBlock(curr->ifFalse);
decIndent();
o << maybeNewLine;
}
decIndent();
if (full) {
Expand All @@ -2677,7 +2685,7 @@ void PrintSExpression::visitLoop(Loop* curr) {
o << '(';
printExpressionContents(curr);
incIndent();
maybePrintImplicitBlock(curr->body, true);
maybePrintImplicitBlock(curr->body);
decIndent();
if (full) {
o << " ;; end loop";
Expand Down Expand Up @@ -2722,7 +2730,7 @@ void PrintSExpression::visitTry(Try* curr) {
o << '(';
printMedium(o, "do");
incIndent();
maybePrintImplicitBlock(curr->body, true);
maybePrintImplicitBlock(curr->body);
decIndent();
o << "\n";
for (size_t i = 0; i < curr->catchTags.size(); i++) {
Expand All @@ -2732,7 +2740,7 @@ void PrintSExpression::visitTry(Try* curr) {
printMedium(o, "catch ");
printName(curr->catchTags[i], o);
incIndent();
maybePrintImplicitBlock(curr->catchBodies[i], true);
maybePrintImplicitBlock(curr->catchBodies[i]);
decIndent();
o << "\n";
}
Expand All @@ -2742,7 +2750,7 @@ void PrintSExpression::visitTry(Try* curr) {
o << '(';
printMedium(o, "catch_all");
incIndent();
maybePrintImplicitBlock(curr->catchBodies.back(), true);
maybePrintImplicitBlock(curr->catchBodies.back());
decIndent();
o << "\n";
}
Expand Down Expand Up @@ -2770,7 +2778,7 @@ void PrintSExpression::visitTryTable(TryTable* curr) {
o << '(';
printExpressionContents(curr);
incIndent();
maybePrintImplicitBlock(curr->body, true);
maybePrintImplicitBlock(curr->body);
decIndent();
if (full) {
o << " ;; end if";
Expand Down
Loading