[Mlir-commits] [mlir] a232a48 - [mlir][ods] Skip adding TOC in doc gen when present
Jacques Pienaar
llvmlistbot at llvm.org
Fri Aug 20 07:02:12 PDT 2021
Author: Jacques Pienaar
Date: 2021-08-20T07:01:54-07:00
New Revision: a232a48dca77b12427c289b2cbf70c35925614dc
URL: https://github.com/llvm/llvm-project/commit/a232a48dca77b12427c289b2cbf70c35925614dc
DIFF: https://github.com/llvm/llvm-project/commit/a232a48dca77b12427c289b2cbf70c35925614dc.diff
LOG: [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.
Added:
mlir/test/mlir-tblgen/gen-dialect-doc.td
Modified:
mlir/tools/mlir-tblgen/OpDocGen.cpp
Removed:
################################################################################
diff --git a/mlir/test/mlir-tblgen/gen-dialect-doc.td b/mlir/test/mlir-tblgen/gen-dialect-doc.td
new file mode 100644
index 000000000000..a49ebaae8800
--- /dev/null
+++ b/mlir/test/mlir-tblgen/gen-dialect-doc.td
@@ -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.
diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index d4a60e30ced1..ab3248390ea8 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -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";
More information about the Mlir-commits
mailing list