forked from OSchip/llvm-project
[mlir][ods] Skip adding TOC in doc gen when present
Enables adding a TOC in the description to be able to interleave documentation before and after the TOC.
This commit is contained in:
parent
417a49e78e
commit
a232a48dca
|
@ -0,0 +1,37 @@
|
|||
// RUN: mlir-tblgen -gen-dialect-doc -I %S/../../include %s | FileCheck %s
|
||||
|
||||
include "mlir/IR/OpBase.td"
|
||||
|
||||
def Test_Dialect : Dialect {
|
||||
let name = "test";
|
||||
let summary = "Dialect of ops to test";
|
||||
let description = [{
|
||||
Dialect without a [TOC] here.
|
||||
TOC added by tool.
|
||||
}];
|
||||
let cppNamespace = "NS";
|
||||
}
|
||||
def AOp : Op<Test_Dialect, "a", []>;
|
||||
|
||||
// CHECK: Dialect without a [TOC] here.
|
||||
// CHECK: TOC added by tool.
|
||||
// CHECK: [TOC]
|
||||
// CHECK-NOT: [TOC]
|
||||
|
||||
def Toc_Dialect : Dialect {
|
||||
let name = "test_toc";
|
||||
let summary = "Dialect of ops to test";
|
||||
let description = [{
|
||||
Dialect with
|
||||
|
||||
[TOC]
|
||||
|
||||
here.
|
||||
}];
|
||||
let cppNamespace = "NS";
|
||||
}
|
||||
def BOp : Op<Toc_Dialect, "b", []>;
|
||||
|
||||
// CHECK: Dialect with
|
||||
// CHECK: [TOC]
|
||||
// CHECK: here.
|
|
@ -21,6 +21,7 @@
|
|||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/Regex.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
#include "llvm/TableGen/Error.h"
|
||||
#include "llvm/TableGen/Record.h"
|
||||
|
@ -247,7 +248,10 @@ static void emitDialectDoc(const Dialect &dialect, ArrayRef<AttrDef> attrDefs,
|
|||
emitIfNotEmpty(dialect.getSummary(), os);
|
||||
emitIfNotEmpty(dialect.getDescription(), os);
|
||||
|
||||
os << "[TOC]\n\n";
|
||||
// Generate a TOC marker except if description already contains one.
|
||||
llvm::Regex r("^[[:space:]]*\\[TOC\\]$", llvm::Regex::RegexFlags::Newline);
|
||||
if (!r.match(dialect.getDescription()))
|
||||
os << "[TOC]\n\n";
|
||||
|
||||
if (!attrDefs.empty()) {
|
||||
os << "## Attribute definition\n\n";
|
||||
|
|
Loading…
Reference in New Issue