1 // RUN: mlir-tblgen -gen-attrdef-defs -I %S/../../include %s | FileCheck %s --check-prefix=ATTR
2 // RUN: mlir-tblgen -gen-typedef-defs -I %S/../../include %s | FileCheck %s --check-prefix=TYPE
4 include "mlir/IR/AttrTypeBase.td"
5 include "mlir/IR/OpBase.td"
7 /// Test that attribute and type printers and parsers are correctly generated.
8 def Test_Dialect : Dialect {
9 let name = "TestDialect";
10 let cppNamespace = "::test";
12 let useDefaultAttributePrinterParser = 1;
14 let useDefaultTypePrinterParser = 1;
17 class TestAttr<string name> : AttrDef<Test_Dialect, name>;
18 class TestType<string name> : TypeDef<Test_Dialect, name>;
20 def AttrA : TestAttr<"AttrA"> {
21 let mnemonic = "attr_a";
24 // ATTR: namespace test {
26 // ATTR: ::mlir::Attribute TestDialect::parseAttribute(::mlir::DialectAsmParser &parser,
27 // ATTR: ::mlir::Type type) const {
28 // ATTR: ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
29 // ATTR: ::llvm::StringRef attrTag;
31 // ATTR: ::mlir::Attribute attr;
32 // ATTR: auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
33 // ATTR: if (parseResult.has_value())
36 // ATTR: parser.emitError(typeLoc) << "unknown attribute `"
37 // ATTR: << attrTag << "` in dialect `" << getNamespace() << "`";
41 // ATTR: void TestDialect::printAttribute(::mlir::Attribute attr,
42 // ATTR: ::mlir::DialectAsmPrinter &printer) const {
43 // ATTR: if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
47 // ATTR: } // namespace test
49 def TypeA : TestType<"TypeA"> {
50 let mnemonic = "type_a";
53 // TYPE: namespace test {
55 // TYPE: ::mlir::Type TestDialect::parseType(::mlir::DialectAsmParser &parser) const {
56 // TYPE: ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
57 // TYPE: ::llvm::StringRef mnemonic;
58 // TYPE: ::mlir::Type genType;
59 // TYPE: auto parseResult = generatedTypeParser(parser, &mnemonic, genType);
60 // TYPE: if (parseResult.has_value())
61 // TYPE: return genType;
62 // TYPE: parser.emitError(typeLoc) << "unknown type `"
63 // TYPE: << mnemonic << "` in dialect `" << getNamespace() << "`";
67 // TYPE: void TestDialect::printType(::mlir::Type type,
68 // TYPE: ::mlir::DialectAsmPrinter &printer) const {
69 // TYPE: if (::mlir::succeeded(generatedTypePrinter(type, printer)))
73 // TYPE: } // namespace test