@@ -393,6 +393,19 @@ class AsmPrinter::Impl {
393393 // / Returns the output stream of the printer.
394394 raw_ostream &getStream () { return os; }
395395
396+ // / Print a newline and indent the printer to the start of the current
397+ // / operation.
398+ void printNewline () {
399+ os << newLine;
400+ os.indent (currentIndent);
401+ }
402+
403+ // / Increase indentation.
404+ void increaseIndent () { currentIndent += indentWidth; }
405+
406+ // / Decrease indentation.
407+ void decreaseIndent () { currentIndent -= indentWidth; }
408+
396409 template <typename Container, typename UnaryFunctor>
397410 inline void interleaveComma (const Container &c, UnaryFunctor eachFn) const {
398411 llvm::interleaveComma (c, os, eachFn);
@@ -507,6 +520,12 @@ class AsmPrinter::Impl {
507520
508521 // / A tracker for the number of new lines emitted during printing.
509522 NewLineCounter newLine;
523+
524+ // / The number of spaces used for indenting nested operations.
525+ const static unsigned indentWidth = 2 ;
526+
527+ // / This is the current indentation level for nested structures.
528+ unsigned currentIndent = 0 ;
510529};
511530} // namespace mlir
512531
@@ -959,6 +978,9 @@ class DummyAliasDialectAsmPrinter : public DialectAsmPrinter {
959978
960979 // / The following are hooks of `DialectAsmPrinter` that are not necessary for
961980 // / determining potential aliases.
981+ void printNewline () override {}
982+ void increaseIndent () override {}
983+ void decreaseIndent () override {}
962984 void printFloat (const APFloat &) override {}
963985 void printKeywordOrString (StringRef) override {}
964986 void printString (StringRef) override {}
@@ -2738,6 +2760,13 @@ void AsmPrinter::Impl::printDialectAttribute(Attribute attr) {
27382760 {
27392761 llvm::raw_string_ostream attrNameStr (attrName);
27402762 Impl subPrinter (attrNameStr, state);
2763+
2764+ // The values of currentIndent and newLine are assigned to the created
2765+ // subprinter, so that the indent level and number of printed lines can be
2766+ // tracked.
2767+ subPrinter.currentIndent = currentIndent;
2768+ subPrinter.newLine = newLine;
2769+
27412770 DialectAsmPrinter printer (subPrinter);
27422771 dialect.printAttribute (attr, printer);
27432772 }
@@ -2752,6 +2781,13 @@ void AsmPrinter::Impl::printDialectType(Type type) {
27522781 {
27532782 llvm::raw_string_ostream typeNameStr (typeName);
27542783 Impl subPrinter (typeNameStr, state);
2784+
2785+ // The values of currentIndent and newLine are assigned to the created
2786+ // subprinter, so that the indent level and number of printed lines can be
2787+ // tracked.
2788+ subPrinter.currentIndent = currentIndent;
2789+ subPrinter.newLine = newLine;
2790+
27552791 DialectAsmPrinter printer (subPrinter);
27562792 dialect.printType (type, printer);
27572793 }
@@ -2792,6 +2828,21 @@ raw_ostream &AsmPrinter::getStream() const {
27922828 return impl->getStream ();
27932829}
27942830
2831+ void AsmPrinter::printNewline () {
2832+ assert (impl && " expected AsmPrinter::printNewLine to be overriden" );
2833+ impl->printNewline ();
2834+ }
2835+
2836+ void AsmPrinter::increaseIndent () {
2837+ assert (impl && " expected AsmPrinter::increaseIndent to be overriden" );
2838+ impl->increaseIndent ();
2839+ }
2840+
2841+ void AsmPrinter::decreaseIndent () {
2842+ assert (impl && " expected AsmPrinter::decreaseIndent to be overriden" );
2843+ impl->decreaseIndent ();
2844+ }
2845+
27952846// / Print the given floating point value in a stablized form.
27962847void AsmPrinter::printFloat (const APFloat &value) {
27972848 assert (impl && " expected AsmPrinter::printFloat to be overriden" );
@@ -3117,19 +3168,6 @@ class OperationPrinter : public AsmPrinter::Impl, private OpAsmPrinter {
31173168 printTrailingLocation (loc);
31183169 }
31193170
3120- // / Print a newline and indent the printer to the start of the current
3121- // / operation.
3122- void printNewline () override {
3123- os << newLine;
3124- os.indent (currentIndent);
3125- }
3126-
3127- // / Increase indentation.
3128- void increaseIndent () override { currentIndent += indentWidth; }
3129-
3130- // / Decrease indentation.
3131- void decreaseIndent () override { currentIndent -= indentWidth; }
3132-
31333171 // / Print a block argument in the usual format of:
31343172 // / %ssaName : type {attr1=42} loc("here")
31353173 // / where location printing is controlled by the standard internal option.
@@ -3255,12 +3293,6 @@ class OperationPrinter : public AsmPrinter::Impl, private OpAsmPrinter {
32553293 // top-level we start with "builtin" as the default, so that the top-level
32563294 // `module` operation prints as-is.
32573295 SmallVector<StringRef> defaultDialectStack{" builtin" };
3258-
3259- // / The number of spaces used for indenting nested operations.
3260- const static unsigned indentWidth = 2 ;
3261-
3262- // This is the current indentation level for nested structures.
3263- unsigned currentIndent = 0 ;
32643296};
32653297} // namespace
32663298
0 commit comments