[Mlir-commits] [mlir] 8368528 - [mlir][tblgen][docs] Use correct introductionary prefix for the Syntax description of attributes and types

Markus Böck llvmlistbot at llvm.org
Wed Dec 7 03:25:51 PST 2022


Author: Markus Böck
Date: 2022-12-07T12:25:47+01:00
New Revision: 836852878c24c7552c4dbefe867112dd54d881f2

URL: https://github.com/llvm/llvm-project/commit/836852878c24c7552c4dbefe867112dd54d881f2
DIFF: https://github.com/llvm/llvm-project/commit/836852878c24c7552c4dbefe867112dd54d881f2.diff

LOG: [mlir][tblgen][docs] Use correct introductionary prefix for the Syntax description of attributes and types

The doc generator currently has the use of `!` as prefix hardcoded, despite being incorrect for Attributes. These start with `#`.

This patch fixes that little issue by using `#` for AttrDefs and `!` for TypeDefs in the `Syntax` field of the generated Markdown file.

Differential Revision: https://reviews.llvm.org/D139524

Added: 
    

Modified: 
    mlir/test/mlir-tblgen/gen-dialect-doc.td
    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
index 6c34db8df1463..11ced979c9df1 100644
--- a/mlir/test/mlir-tblgen/gen-dialect-doc.td
+++ b/mlir/test/mlir-tblgen/gen-dialect-doc.td
@@ -2,6 +2,7 @@
 // RUN: mlir-tblgen -gen-dialect-doc -I %S/../../include -dialect=test_toc %s | FileCheck %s --check-prefix=CHECK_TOC
 
 include "mlir/IR/OpBase.td"
+include "mlir/IR/AttrTypeBase.td"
 include "mlir/Interfaces/SideEffectInterfaces.td"
 
 def Test_Dialect : Dialect {
@@ -25,6 +26,28 @@ def TestType : DialectType<Test_Dialect, CPred<"true">> {
   let description = "type description";
 }
 
+def TestAttrDef : AttrDef<Test_Dialect, "TestAttrDef"> {
+  let mnemonic = "test_attr_def";
+}
+
+def TestAttrDefParams : AttrDef<Test_Dialect, "TestAttrDefParams"> {
+  let mnemonic = "test_attr_def_params";
+  let parameters = (ins "int":$value);
+
+  let assemblyFormat = "`<` $value `>`";
+}
+
+def TestTypeDef : TypeDef<Test_Dialect, "TestTypeDef"> {
+  let mnemonic = "test_type_def";
+}
+
+def TestTypeDefParams : TypeDef<Test_Dialect, "TestTypeDefParams"> {
+  let mnemonic = "test_type_def_params";
+  let parameters = (ins "int":$value);
+
+  let assemblyFormat = "`<` $value `>`";
+}
+
 // CHECK: Dialect without a [TOC] here.
 // CHECK: TOC added by tool.
 // CHECK: [TOC]
@@ -38,10 +61,25 @@ def TestType : DialectType<Test_Dialect, CPred<"true">> {
 // CHECK: ### attribute summary
 // CHECK: attribute description
 
+// CHECK: TestAttrDefAttr
+// CHECK: Syntax:
+// CHECK: #test.test_attr_def
+
+// CHECK: TestAttrDefParamsAttr
+// CHECK: Syntax:
+// CHECK: #test.test_attr_def_params
+
 // CHECK: ## Type constraint definition
 // CHECK: ### type summary
 // CHECK: type description
 
+// CHECK: TestTypeDefType
+// CHECK: Syntax:
+// CHECK: !test.test_type_def
+
+// CHECK: TestTypeDefParamsType
+// CHECK: Syntax:
+// CHECK: !test.test_type_def_params
 
 def Toc_Dialect : Dialect {
   let name = "test_toc";

diff  --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index c1aa0addb05d8..7c2f1e1ce51eb 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -248,14 +248,15 @@ static void emitTypeDoc(const Type &type, raw_ostream &os) {
 static void emitAttrOrTypeDefAssemblyFormat(const AttrOrTypeDef &def,
                                             raw_ostream &os) {
   ArrayRef<AttrOrTypeParameter> parameters = def.getParameters();
+  char prefix = isa<AttrDef>(def) ? '#' : '!';
   if (parameters.empty()) {
-    os << "\nSyntax: `!" << def.getDialect().getName() << "."
+    os << "\nSyntax: `" << prefix << def.getDialect().getName() << "."
        << def.getMnemonic() << "`\n";
     return;
   }
 
-  os << "\nSyntax:\n\n```\n!" << def.getDialect().getName() << "."
-     << def.getMnemonic() << "<\n";
+  os << "\nSyntax:\n\n```\n"
+     << prefix << def.getDialect().getName() << "." << def.getMnemonic() << "<\n";
   for (const auto &it : llvm::enumerate(parameters)) {
     const AttrOrTypeParameter &param = it.value();
     os << "  " << param.getSyntax();


        


More information about the Mlir-commits mailing list