@@ -265,10 +265,22 @@ static void emitOpDoc(const Operator &op, raw_ostream &os) {
265
265
os << " \n " ;
266
266
}
267
267
268
+ static void emitSourceLink (StringRef inputFilename, raw_ostream &os) {
269
+ size_t pathBegin = inputFilename.find (" mlir/include/mlir/" );
270
+ if (pathBegin == StringRef::npos)
271
+ return ;
272
+
273
+ StringRef inputFromMlirInclude = inputFilename.substr (pathBegin);
274
+
275
+ os << " [source](https://github.com/llvm/llvm-project/blob/main/"
276
+ << inputFromMlirInclude << " )\n\n " ;
277
+ }
278
+
268
279
static void emitOpDoc (const RecordKeeper &recordKeeper, raw_ostream &os) {
269
280
auto opDefs = getRequestedOpDefinitions (recordKeeper);
270
281
271
282
os << " <!-- Autogenerated by mlir-tblgen; don't manually edit -->\n " ;
283
+ emitSourceLink (recordKeeper.getInputFilename (), os);
272
284
for (const llvm::Record *opDef : opDefs)
273
285
emitOpDoc (Operator (opDef), os);
274
286
}
@@ -392,12 +404,13 @@ static void maybeNest(bool nest, llvm::function_ref<void(raw_ostream &os)> fn,
392
404
}
393
405
}
394
406
395
- static void emitBlock (ArrayRef<Attribute> attributes,
407
+ static void emitBlock (ArrayRef<Attribute> attributes, StringRef inputFilename,
396
408
ArrayRef<AttrDef> attrDefs, ArrayRef<OpDocGroup> ops,
397
409
ArrayRef<Type> types, ArrayRef<TypeDef> typeDefs,
398
410
raw_ostream &os) {
399
411
if (!ops.empty ()) {
400
- os << " ## Operation definition\n\n " ;
412
+ os << " ## Operations\n\n " ;
413
+ emitSourceLink (inputFilename, os);
401
414
for (const OpDocGroup &grouping : ops) {
402
415
bool nested = !grouping.summary .empty ();
403
416
maybeNest (
@@ -417,32 +430,32 @@ static void emitBlock(ArrayRef<Attribute> attributes,
417
430
}
418
431
419
432
if (!attributes.empty ()) {
420
- os << " ## Attribute constraint definition \n\n " ;
433
+ os << " ## Attribute constraints \n\n " ;
421
434
for (const Attribute &attr : attributes)
422
435
emitAttrDoc (attr, os);
423
436
}
424
437
425
438
if (!attrDefs.empty ()) {
426
- os << " ## Attribute definition \n\n " ;
439
+ os << " ## Attributes \n\n " ;
427
440
for (const AttrDef &def : attrDefs)
428
441
emitAttrOrTypeDefDoc (def, os);
429
442
}
430
443
431
444
// TODO: Add link between use and def for types
432
445
if (!types.empty ()) {
433
- os << " ## Type constraint definition \n\n " ;
446
+ os << " ## Type constraints \n\n " ;
434
447
for (const Type &type : types)
435
448
emitTypeDoc (type, os);
436
449
}
437
450
438
451
if (!typeDefs.empty ()) {
439
- os << " ## Type definition \n\n " ;
452
+ os << " ## Types \n\n " ;
440
453
for (const TypeDef &def : typeDefs)
441
454
emitAttrOrTypeDefDoc (def, os);
442
455
}
443
456
}
444
457
445
- static void emitDialectDoc (const Dialect &dialect,
458
+ static void emitDialectDoc (const Dialect &dialect, StringRef inputFilename,
446
459
ArrayRef<Attribute> attributes,
447
460
ArrayRef<AttrDef> attrDefs, ArrayRef<OpDocGroup> ops,
448
461
ArrayRef<Type> types, ArrayRef<TypeDef> typeDefs,
@@ -456,7 +469,7 @@ static void emitDialectDoc(const Dialect &dialect,
456
469
if (!r.match (dialect.getDescription ()))
457
470
os << " [TOC]\n\n " ;
458
471
459
- emitBlock (attributes, attrDefs, ops, types, typeDefs, os);
472
+ emitBlock (attributes, inputFilename, attrDefs, ops, types, typeDefs, os);
460
473
}
461
474
462
475
static bool emitDialectDoc (const RecordKeeper &recordKeeper, raw_ostream &os) {
@@ -536,8 +549,9 @@ static bool emitDialectDoc(const RecordKeeper &recordKeeper, raw_ostream &os) {
536
549
});
537
550
538
551
os << " <!-- Autogenerated by mlir-tblgen; don't manually edit -->\n " ;
539
- emitDialectDoc (*dialect, dialectAttrs, dialectAttrDefs, dialectOps,
540
- dialectTypes, dialectTypeDefs, os);
552
+ emitDialectDoc (*dialect, recordKeeper.getInputFilename (), dialectAttrs,
553
+ dialectAttrDefs, dialectOps, dialectTypes, dialectTypeDefs,
554
+ os);
541
555
return false ;
542
556
}
543
557
0 commit comments