diff --git a/mlir/test/mlir-tblgen/gen-dialect-doc.td b/mlir/test/mlir-tblgen/gen-dialect-doc.td --- 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 @@ let description = "type description"; } +def TestAttrDef : AttrDef { + let mnemonic = "test_attr_def"; +} + +def TestAttrDefParams : AttrDef { + let mnemonic = "test_attr_def_params"; + let parameters = (ins "int":$value); + + let assemblyFormat = "`<` $value `>`"; +} + +def TestTypeDef : TypeDef { + let mnemonic = "test_type_def"; +} + +def TestTypeDefParams : TypeDef { + 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 @@ // 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 --- a/mlir/tools/mlir-tblgen/OpDocGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp @@ -248,14 +248,15 @@ static void emitAttrOrTypeDefAssemblyFormat(const AttrOrTypeDef &def, raw_ostream &os) { ArrayRef parameters = def.getParameters(); + char prefix = isa(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 ¶m = it.value(); os << " " << param.getSyntax();