@@ -418,6 +418,19 @@ class AsmPrinter::Impl {
418418 // / Returns the output stream of the printer.
419419 raw_ostream &getStream () { return os; }
420420
421+ // / Print a newline and indent the printer to the start of the current
422+ // / operation.
423+ void printNewline () {
424+ os << newLine;
425+ os.indent (currentIndent);
426+ }
427+
428+ // / Increase indentation.
429+ void increaseIndent () { currentIndent += indentWidth; }
430+
431+ // / Decrease indentation.
432+ void decreaseIndent () { currentIndent -= indentWidth; }
433+
421434 template <typename Container, typename UnaryFunctor>
422435 inline void interleaveComma (const Container &c, UnaryFunctor eachFn) const {
423436 llvm::interleaveComma (c, os, eachFn);
@@ -532,6 +545,12 @@ class AsmPrinter::Impl {
532545
533546 // / A tracker for the number of new lines emitted during printing.
534547 NewLineCounter newLine;
548+
549+ // / The number of spaces used for indenting nested operations.
550+ const static unsigned indentWidth = 2 ;
551+
552+ // / This is the current indentation level for nested structures.
553+ unsigned currentIndent = 0 ;
535554};
536555} // namespace mlir
537556
@@ -1004,6 +1023,9 @@ class DummyAliasDialectAsmPrinter : public DialectAsmPrinter {
10041023
10051024 // / The following are hooks of `DialectAsmPrinter` that are not necessary for
10061025 // / determining potential aliases.
1026+ void printNewline () override {}
1027+ void increaseIndent () override {}
1028+ void decreaseIndent () override {}
10071029 void printFloat (const APFloat &) override {}
10081030 void printKeywordOrString (StringRef) override {}
10091031 void printString (StringRef) override {}
@@ -2892,6 +2914,13 @@ void AsmPrinter::Impl::printDialectAttribute(Attribute attr) {
28922914 {
28932915 llvm::raw_string_ostream attrNameStr (attrName);
28942916 Impl subPrinter (attrNameStr, state);
2917+
2918+ // The values of currentIndent and newLine are assigned to the created
2919+ // subprinter, so that the indent level and number of printed lines can be
2920+ // tracked.
2921+ subPrinter.currentIndent = currentIndent;
2922+ subPrinter.newLine = newLine;
2923+
28952924 DialectAsmPrinter printer (subPrinter);
28962925 dialect.printAttribute (attr, printer);
28972926 }
@@ -2906,6 +2935,13 @@ void AsmPrinter::Impl::printDialectType(Type type) {
29062935 {
29072936 llvm::raw_string_ostream typeNameStr (typeName);
29082937 Impl subPrinter (typeNameStr, state);
2938+
2939+ // The values of currentIndent and newLine are assigned to the created
2940+ // subprinter, so that the indent level and number of printed lines can be
2941+ // tracked.
2942+ subPrinter.currentIndent = currentIndent;
2943+ subPrinter.newLine = newLine;
2944+
29092945 DialectAsmPrinter printer (subPrinter);
29102946 dialect.printType (type, printer);
29112947 }
@@ -2946,6 +2982,21 @@ raw_ostream &AsmPrinter::getStream() const {
29462982 return impl->getStream ();
29472983}
29482984
2985+ void AsmPrinter::printNewline () {
2986+ assert (impl && " expected AsmPrinter::printNewLine to be overriden" );
2987+ impl->printNewline ();
2988+ }
2989+
2990+ void AsmPrinter::increaseIndent () {
2991+ assert (impl && " expected AsmPrinter::increaseIndent to be overriden" );
2992+ impl->increaseIndent ();
2993+ }
2994+
2995+ void AsmPrinter::decreaseIndent () {
2996+ assert (impl && " expected AsmPrinter::decreaseIndent to be overriden" );
2997+ impl->decreaseIndent ();
2998+ }
2999+
29493000// / Print the given floating point value in a stablized form.
29503001void AsmPrinter::printFloat (const APFloat &value) {
29513002 assert (impl && " expected AsmPrinter::printFloat to be overriden" );
@@ -3276,19 +3327,6 @@ class OperationPrinter : public AsmPrinter::Impl, private OpAsmPrinter {
32763327 printTrailingLocation (loc);
32773328 }
32783329
3279- // / Print a newline and indent the printer to the start of the current
3280- // / operation.
3281- void printNewline () override {
3282- os << newLine;
3283- os.indent (currentIndent);
3284- }
3285-
3286- // / Increase indentation.
3287- void increaseIndent () override { currentIndent += indentWidth; }
3288-
3289- // / Decrease indentation.
3290- void decreaseIndent () override { currentIndent -= indentWidth; }
3291-
32923330 // / Print a block argument in the usual format of:
32933331 // / %ssaName : type {attr1=42} loc("here")
32943332 // / where location printing is controlled by the standard internal option.
@@ -3414,12 +3452,6 @@ class OperationPrinter : public AsmPrinter::Impl, private OpAsmPrinter {
34143452 // top-level we start with "builtin" as the default, so that the top-level
34153453 // `module` operation prints as-is.
34163454 SmallVector<StringRef> defaultDialectStack{" builtin" };
3417-
3418- // / The number of spaces used for indenting nested operations.
3419- const static unsigned indentWidth = 2 ;
3420-
3421- // This is the current indentation level for nested structures.
3422- unsigned currentIndent = 0 ;
34233455};
34243456} // namespace
34253457
0 commit comments