summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 5504373f5..2a483efd3 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -57,6 +57,28 @@ static std::ostream& printLocal(Index index, Function* func, std::ostream& o) {
return printName(name, o);
}
+// Unlike the default format, tuple types in s-expressions should not have
+// commas.
+struct LocalType {
+ Type type;
+ LocalType(Type type) : type(type){};
+};
+
+static std::ostream& operator<<(std::ostream& o, const LocalType& localType) {
+ Type type = localType.type;
+ if (type.isMulti()) {
+ const std::vector<Type>& types = type.expand();
+ o << '(' << types[0];
+ for (size_t i = 1; i < types.size(); ++i) {
+ o << ' ' << types[i];
+ }
+ o << ')';
+ return o;
+ }
+ o << type;
+ return o;
+}
+
// Wrapper for printing signature names
struct SigName {
Signature sig;
@@ -1387,6 +1409,11 @@ struct PrintExpressionContents
o << ".pop";
restoreNormalColor(o);
}
+ void visitTupleMake(TupleMake* curr) { printMedium(o, "tuple.make"); }
+ void visitTupleExtract(TupleExtract* curr) {
+ printMedium(o, "tuple.extract ");
+ o << curr->index;
+ }
};
// Prints an expression in s-expr format, including both the
@@ -1955,6 +1982,22 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
PrintExpressionContents(currFunction, o).visit(curr);
o << ')';
}
+ void visitTupleMake(TupleMake* curr) {
+ o << '(';
+ PrintExpressionContents(currFunction, o).visit(curr);
+ incIndent();
+ for (auto operand : curr->operands) {
+ printFullLine(operand);
+ }
+ decIndent();
+ }
+ void visitTupleExtract(TupleExtract* curr) {
+ o << '(';
+ PrintExpressionContents(currFunction, o).visit(curr);
+ incIndent();
+ printFullLine(curr->tuple);
+ decIndent();
+ }
// Module-level visitors
void handleSignature(Signature curr, Name* funcName = nullptr) {
o << "(func";
@@ -2093,7 +2136,8 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
doIndent(o, indent);
o << '(';
printMinor(o, "local ");
- printLocal(i, currFunction, o) << ' ' << curr->getLocalType(i) << ')';
+ printLocal(i, currFunction, o)
+ << ' ' << LocalType(curr->getLocalType(i)) << ')';
o << maybeNewLine;
}
// Print the body.