@@ -54,12 +54,12 @@ cl::opt<bool> allowHugoSpecificFeatures(
54
54
cl::cat(docCat));
55
55
56
56
void mlir::tblgen::emitSummary (StringRef summary, raw_ostream &os) {
57
- if (! summary.empty ()) {
58
- StringRef trimmed = summary. trim () ;
59
- char first = std::toupper (trimmed. front () );
60
- StringRef rest = trimmed.drop_front ( );
61
- os << " \n _ " << first << rest << " _ \n\n " ;
62
- }
57
+ if (summary.empty ())
58
+ return ;
59
+ StringRef trimmed = summary. trim ( );
60
+ char first = std::toupper ( trimmed.front () );
61
+ StringRef rest = trimmed. drop_front () ;
62
+ os << " \n _ " << first << rest << " _ \n " ;
63
63
}
64
64
65
65
// Emit the description by aligning the text to the left per line (e.g.,
@@ -69,6 +69,9 @@ void mlir::tblgen::emitSummary(StringRef summary, raw_ostream &os) {
69
69
// in a way the user wanted but has some additional indenting due to being
70
70
// nested in the op definition.
71
71
void mlir::tblgen::emitDescription (StringRef description, raw_ostream &os) {
72
+ if (description.empty ())
73
+ return ;
74
+ os << " \n " ;
72
75
raw_indented_ostream ros (os);
73
76
StringRef trimmed = description.rtrim (" \t " );
74
77
ros.printReindented (trimmed);
@@ -80,29 +83,22 @@ void mlir::tblgen::emitDescriptionComment(StringRef description,
80
83
raw_ostream &os, StringRef prefix) {
81
84
if (description.empty ())
82
85
return ;
86
+ os << " \n " ;
83
87
raw_indented_ostream ros (os);
84
88
StringRef trimmed = description.rtrim (" \t " );
85
89
ros.printReindented (trimmed, (Twine (prefix) + " /// " ).str ());
86
90
if (!trimmed.ends_with (" \n " ))
87
91
ros << " \n " ;
88
92
}
89
93
90
- // Emits `str` with trailing newline if not empty.
91
- static void emitIfNotEmpty (StringRef str, raw_ostream &os) {
92
- if (!str.empty ()) {
93
- emitDescription (str, os);
94
- os << " \n " ;
95
- }
96
- }
97
-
98
94
// / Emit the given named constraint.
99
95
template <typename T>
100
96
static void emitNamedConstraint (const T &it, raw_ostream &os) {
101
97
if (!it.name .empty ())
102
98
os << " | `" << it.name << " `" ;
103
99
else
104
- os << " «unnamed»" ;
105
- os << " | " << it.constraint .getSummary () << " \n " ;
100
+ os << " | «unnamed»" ;
101
+ os << " | " << it.constraint .getSummary () << " | \n " ;
106
102
}
107
103
108
104
// ===----------------------------------------------------------------------===//
@@ -112,6 +108,8 @@ static void emitNamedConstraint(const T &it, raw_ostream &os) {
112
108
// / Emit the assembly format of an operation.
113
109
static void emitAssemblyFormat (StringRef opName, StringRef format,
114
110
raw_ostream &os) {
111
+ if (format.empty ())
112
+ return ;
115
113
os << " \n Syntax:\n\n ```\n operation ::= `" << opName << " ` " ;
116
114
117
115
// Print the assembly format aligned.
@@ -124,7 +122,7 @@ static void emitAssemblyFormat(StringRef opName, StringRef format,
124
122
if (!formatChunk.empty ())
125
123
os.indent (indent) << formatChunk << " \n " ;
126
124
} while (!split.second .empty ());
127
- os << " ```\n\n " ;
125
+ os << " ```\n " ;
128
126
}
129
127
130
128
// / Place `text` between backticks so that the Markdown processor renders it as
@@ -199,7 +197,7 @@ static void emitOpDoc(const Operator &op, raw_ostream &os) {
199
197
std::string classNameStr = op.getQualCppClassName ();
200
198
StringRef className = classNameStr;
201
199
(void )className.consume_front (stripPrefix);
202
- os << formatv (" ### `{0}` ({1})\n " , op.getOperationName (), className);
200
+ os << formatv (" \n ### `{0}` ({1})\n " , op.getOperationName (), className);
203
201
204
202
// Emit the summary, syntax, and description if present.
205
203
if (op.hasSummary ())
@@ -281,8 +279,8 @@ static void emitSourceLink(StringRef inputFilename, raw_ostream &os) {
281
279
282
280
StringRef inputFromMlirInclude = inputFilename.substr (pathBegin);
283
281
284
- os << " [source](https://github.com/llvm/llvm-project/blob/main/"
285
- << inputFromMlirInclude << " )\n\n " ;
282
+ os << " \n [source](https://github.com/llvm/llvm-project/blob/main/"
283
+ << inputFromMlirInclude << " )\n " ;
286
284
}
287
285
288
286
static void emitOpDoc (const RecordKeeper &records, raw_ostream &os) {
@@ -299,19 +297,19 @@ static void emitOpDoc(const RecordKeeper &records, raw_ostream &os) {
299
297
// ===----------------------------------------------------------------------===//
300
298
301
299
static void emitAttrDoc (const Attribute &attr, raw_ostream &os) {
302
- os << " ### " << attr.getSummary () << " \n \n" ;
300
+ os << " \n ### " << attr.getSummary () << " \n " ;
303
301
emitDescription (attr.getDescription (), os);
304
- os << " \n\n " ;
302
+ os << " \n " ;
305
303
}
306
304
307
305
// ===----------------------------------------------------------------------===//
308
306
// Type Documentation
309
307
// ===----------------------------------------------------------------------===//
310
308
311
309
static void emitTypeDoc (const Type &type, raw_ostream &os) {
312
- os << " ### " << type.getSummary () << " \n \n" ;
310
+ os << " \n ### " << type.getSummary () << " \n " ;
313
311
emitDescription (type.getDescription (), os);
314
- os << " \n\n " ;
312
+ os << " \n " ;
315
313
}
316
314
317
315
// ===----------------------------------------------------------------------===//
@@ -342,19 +340,18 @@ static void emitAttrOrTypeDefAssemblyFormat(const AttrOrTypeDef &def,
342
340
}
343
341
344
342
static void emitAttrOrTypeDefDoc (const AttrOrTypeDef &def, raw_ostream &os) {
345
- os << formatv (" ### {0}\n " , def.getCppClassName ());
343
+ os << formatv (" \n ### {0}\n " , def.getCppClassName ());
346
344
347
345
// Emit the summary if present.
348
346
if (def.hasSummary ())
349
- os << " \n " << def.getSummary () << " \n " ;
347
+ emitSummary ( def.getSummary (), os) ;
350
348
351
349
// Emit the syntax if present.
352
350
if (def.getMnemonic () && !def.hasCustomAssemblyFormat ())
353
351
emitAttrOrTypeDefAssemblyFormat (def, os);
354
352
355
353
// Emit the description if present.
356
354
if (def.hasDescription ()) {
357
- os << " \n " ;
358
355
mlir::tblgen::emitDescription (def.getDescription (), os);
359
356
}
360
357
@@ -363,11 +360,11 @@ static void emitAttrOrTypeDefDoc(const AttrOrTypeDef &def, raw_ostream &os) {
363
360
if (!parameters.empty ()) {
364
361
os << " \n #### Parameters:\n\n " ;
365
362
os << " | Parameter | C++ type | Description |\n "
366
- << " | :-------: | :-------: | ----------- |\n " ;
363
+ << " | :-------: | :-------: | ----------- |" ;
367
364
for (const auto &it : parameters) {
368
365
auto desc = it.getSummary ();
369
- os << " | " << it.getName () << " | `" << it.getCppType () << " ` | "
370
- << (desc ? *desc : " " ) << " |\n " ;
366
+ os << " \n | " << it.getName () << " | `" << it.getCppType () << " ` | "
367
+ << (desc ? *desc : " " ) << " |" ;
371
368
}
372
369
}
373
370
@@ -388,20 +385,19 @@ static void emitAttrOrTypeDefDoc(const RecordKeeper &records, raw_ostream &os,
388
385
// ===----------------------------------------------------------------------===//
389
386
390
387
static void emitEnumDoc (const EnumAttr &def, raw_ostream &os) {
391
- os << formatv (" ### {0}\n " , def.getEnumClassName ());
388
+ os << formatv (" \n ### {0}\n " , def.getEnumClassName ());
392
389
393
390
// Emit the summary if present.
394
- if (!def.getSummary ().empty ())
395
- os << " \n " << def.getSummary () << " \n " ;
391
+ emitSummary (def.getSummary (), os);
396
392
397
393
// Emit case documentation.
398
394
std::vector<EnumAttrCase> cases = def.getAllCases ();
399
395
os << " \n #### Cases:\n\n " ;
400
396
os << " | Symbol | Value | String |\n "
401
- << " | :----: | :---: | ------ |\n " ;
397
+ << " | :----: | :---: | ------ |" ;
402
398
for (const auto &it : cases) {
403
- os << " | " << it.getSymbol () << " | `" << it.getValue () << " ` | "
404
- << it.getStr () << " |\n " ;
399
+ os << " \n | " << it.getSymbol () << " | `" << it.getValue () << " ` | "
400
+ << it.getStr () << " |" ;
405
401
}
406
402
407
403
os << " \n " ;
@@ -447,17 +443,17 @@ static void emitBlock(ArrayRef<Attribute> attributes, StringRef inputFilename,
447
443
ArrayRef<Type> types, ArrayRef<TypeDef> typeDefs,
448
444
ArrayRef<EnumAttr> enums, raw_ostream &os) {
449
445
if (!ops.empty ()) {
450
- os << " ## Operations\n \n" ;
446
+ os << " \n ## Operations\n " ;
451
447
emitSourceLink (inputFilename, os);
452
448
for (const OpDocGroup &grouping : ops) {
453
449
bool nested = !grouping.summary .empty ();
454
450
maybeNest (
455
451
nested,
456
452
[&](raw_ostream &os) {
457
453
if (nested) {
458
- os << " ## " << StringRef (grouping.summary ).trim () << " \n \n" ;
454
+ os << " \n ## " << StringRef (grouping.summary ).trim () << " \n " ;
459
455
emitDescription (grouping.description , os);
460
- os << " \n\n " ;
456
+ os << " \n " ;
461
457
}
462
458
for (const Operator &op : grouping.ops ) {
463
459
emitOpDoc (op, os);
@@ -468,32 +464,32 @@ static void emitBlock(ArrayRef<Attribute> attributes, StringRef inputFilename,
468
464
}
469
465
470
466
if (!attributes.empty ()) {
471
- os << " ## Attribute constraints\n \n" ;
467
+ os << " \n ## Attribute constraints\n " ;
472
468
for (const Attribute &attr : attributes)
473
469
emitAttrDoc (attr, os);
474
470
}
475
471
476
472
if (!attrDefs.empty ()) {
477
- os << " ## Attributes\n \n" ;
473
+ os << " \n ## Attributes\n " ;
478
474
for (const AttrDef &def : attrDefs)
479
475
emitAttrOrTypeDefDoc (def, os);
480
476
}
481
477
482
478
// TODO: Add link between use and def for types
483
479
if (!types.empty ()) {
484
- os << " ## Type constraints\n \n" ;
480
+ os << " \n ## Type constraints\n " ;
485
481
for (const Type &type : types)
486
482
emitTypeDoc (type, os);
487
483
}
488
484
489
485
if (!typeDefs.empty ()) {
490
- os << " ## Types\n \n" ;
486
+ os << " \n ## Types\n " ;
491
487
for (const TypeDef &def : typeDefs)
492
488
emitAttrOrTypeDefDoc (def, os);
493
489
}
494
490
495
491
if (!enums.empty ()) {
496
- os << " ## Enums\n \n" ;
492
+ os << " \n ## Enums\n " ;
497
493
for (const EnumAttr &def : enums)
498
494
emitEnumDoc (def, os);
499
495
}
@@ -504,14 +500,14 @@ static void emitDialectDoc(const Dialect &dialect, StringRef inputFilename,
504
500
ArrayRef<AttrDef> attrDefs, ArrayRef<OpDocGroup> ops,
505
501
ArrayRef<Type> types, ArrayRef<TypeDef> typeDefs,
506
502
ArrayRef<EnumAttr> enums, raw_ostream &os) {
507
- os << " # '" << dialect.getName () << " ' Dialect\n \n" ;
508
- emitIfNotEmpty (dialect.getSummary (), os);
509
- emitIfNotEmpty (dialect.getDescription (), os);
503
+ os << " \n # '" << dialect.getName () << " ' Dialect\n " ;
504
+ emitSummary (dialect.getSummary (), os);
505
+ emitDescription (dialect.getDescription (), os);
510
506
511
507
// Generate a TOC marker except if description already contains one.
512
508
Regex r (" ^[[:space:]]*\\ [TOC\\ ]$" , Regex::RegexFlags::Newline);
513
509
if (!r.match (dialect.getDescription ()))
514
- os << " [TOC]\n \n" ;
510
+ os << " \n [TOC]\n " ;
515
511
516
512
emitBlock (attributes, inputFilename, attrDefs, ops, types, typeDefs, enums,
517
513
os);
0 commit comments