This structure is necessary to be able to use AttrDef as arguments on operations.
Differential Revision: https://reviews.llvm.org/D113327
mlir_tablegen(TestOpInterfaces.cpp.inc -gen-op-interface-defs)
add_public_tablegen_target(MLIRTestInterfaceIncGen)
-set(LLVM_TARGET_DEFINITIONS TestAttrDefs.td)
+set(LLVM_TARGET_DEFINITIONS TestOps.td)
mlir_tablegen(TestAttrDefs.h.inc -gen-attrdef-decls)
mlir_tablegen(TestAttrDefs.cpp.inc -gen-attrdef-defs)
add_public_tablegen_target(MLIRTestAttrDefIncGen)
#ifndef MLIR_TESTDIALECT_H
#define MLIR_TESTDIALECT_H
+#include "TestAttributes.h"
#include "TestInterfaces.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/DLTI/Traits.h"
void registerAttributes();
void registerTypes();
- ::mlir::Attribute parseAttribute(::mlir::DialectAsmParser &parser,
- ::mlir::Type type) const override;
- void printAttribute(::mlir::Attribute attr,
- ::mlir::DialectAsmPrinter &printer) const override;
-
// Provides a custom printing/parsing for some operations.
::llvm::Optional<ParseOpHook>
getParseOperationHook(::llvm::StringRef opName) const override;
}];
}
+// Include the attribute definitions.
+include "TestAttrDefs.td"
+
+
class TEST_Op<string mnemonic, list<OpTrait> traits = []> :
Op<Test_Dialect, mnemonic, traits>;
let assemblyFormat = "(`then` $isFirstBranchPresent^):(`else`)? attr-dict";
}
+def FormatCompoundAttr : TEST_Op<"format_compound_attr"> {
+ let arguments = (ins CompoundAttrA:$compound);
+ let assemblyFormat = "$compound attr-dict-with-keyword";
+}
+
//===----------------------------------------------------------------------===//
// Custom Directives
test.format_optional_else else
//===----------------------------------------------------------------------===//
+// Format a custom attribute
+//===----------------------------------------------------------------------===//
+
+// CHECK: test.format_compound_attr #test.cmpnd_a<1, !test.smpla, [5, 6]>
+test.format_compound_attr #test.cmpnd_a<1, !test.smpla, [5, 6]>
+
+//===----------------------------------------------------------------------===//
// Format custom directives
//===----------------------------------------------------------------------===//
),
],
tblgen = "//mlir:mlir-tblgen",
- td_file = "lib/Dialect/Test/TestAttrDefs.td",
+ td_file = "lib/Dialect/Test/TestOps.td",
test = True,
deps = [
":TestOpTdFiles",