12
12
// ===----------------------------------------------------------------------===//
13
13
14
14
#include " DocGenUtilities.h"
15
- #include " mlir/Support/IndentedOstream.h"
16
15
#include " mlir/TableGen/GenInfo.h"
17
16
#include " mlir/TableGen/Operator.h"
18
17
#include " llvm/ADT/DenseMap.h"
@@ -36,8 +35,39 @@ using mlir::tblgen::Operator;
36
35
// in a way the user wanted but has some additional indenting due to being
37
36
// nested in the op definition.
38
37
void mlir::tblgen::emitDescription (StringRef description, raw_ostream &os) {
39
- raw_indented_ostream ros (os);
40
- ros.reindent (description.rtrim (" \t " ));
38
+ // Determine the minimum number of spaces in a line.
39
+ size_t min_indent = -1 ;
40
+ StringRef remaining = description;
41
+ while (!remaining.empty ()) {
42
+ auto split = remaining.split (' \n ' );
43
+ size_t indent = split.first .find_first_not_of (" \t " );
44
+ if (indent != StringRef::npos)
45
+ min_indent = std::min (indent, min_indent);
46
+ remaining = split.second ;
47
+ }
48
+
49
+ // Print out the description indented.
50
+ os << " \n " ;
51
+ remaining = description;
52
+ bool printed = false ;
53
+ while (!remaining.empty ()) {
54
+ auto split = remaining.split (' \n ' );
55
+ if (split.second .empty ()) {
56
+ // Skip last line with just spaces.
57
+ if (split.first .ltrim ().empty ())
58
+ break ;
59
+ }
60
+ // Print empty new line without spaces if line only has spaces, unless no
61
+ // text has been emitted before.
62
+ if (split.first .ltrim ().empty ()) {
63
+ if (printed)
64
+ os << " \n " ;
65
+ } else {
66
+ os << split.first .substr (min_indent) << " \n " ;
67
+ printed = true ;
68
+ }
69
+ remaining = split.second ;
70
+ }
41
71
}
42
72
43
73
// Emits `str` with trailing newline if not empty.
@@ -86,7 +116,7 @@ static void emitOpDoc(Operator op, raw_ostream &os) {
86
116
87
117
// Emit the summary, syntax, and description if present.
88
118
if (op.hasSummary ())
89
- os << " \n " << op.getSummary () << " \n\n " ;
119
+ os << " \n " << op.getSummary () << " \n " ;
90
120
if (op.hasAssemblyFormat ())
91
121
emitAssemblyFormat (op.getOperationName (), op.getAssemblyFormat ().trim (),
92
122
os);
@@ -198,7 +228,7 @@ static void emitDialectDoc(const RecordKeeper &recordKeeper, raw_ostream &os) {
198
228
}
199
229
200
230
os << " <!-- Autogenerated by mlir-tblgen; don't manually edit -->\n " ;
201
- for (const auto & dialectWithOps : dialectOps)
231
+ for (auto dialectWithOps : dialectOps)
202
232
emitDialectDoc (dialectWithOps.first , dialectWithOps.second ,
203
233
dialectTypes[dialectWithOps.first ], os);
204
234
}
0 commit comments