//===----------------------------------------------------------------------===//
// Composite attribute kinds
-class DictionaryAttrBase : Attr<CPred<"$_self.isa<DictionaryAttr>()">,
- "dictionary of named attribute values"> {
+class DictionaryAttrBase<Pred condition, string description> :
+ Attr<condition, description> {
let storageType = [{ DictionaryAttr }];
let returnType = [{ DictionaryAttr }];
let valueType = NoneType;
let convertFromStorage = "$_self";
}
-def DictionaryAttr : DictionaryAttrBase;
+def DictionaryAttr : DictionaryAttrBase<CPred<"$_self.isa<DictionaryAttr>()">,
+ "dictionary of named attribute values">;
class ElementsAttrBase<Pred condition, string description> :
Attr<condition, description> {
// validation method and set of accessors for a fixed set of fields. This is
// useful when representing data that would normally be in a structure.
class StructAttr<string name, Dialect dialect,
- list<StructFieldAttr> attributes> : DictionaryAttrBase {
+ list<StructFieldAttr> attributes> :
+ DictionaryAttrBase<CPred<"$_self.isa<" # name # ">()">,
+ "DictionaryAttr with field(s): " #
+ StrJoin<!foreach(a, attributes, "'" # a.name # "'"), ", ">.result #
+ " (each field having its own constraints)"> {
// Name for this StructAttr.
string className = name;
return
}
+//===----------------------------------------------------------------------===//
+// Test StructAttr
+//===----------------------------------------------------------------------===//
+
+// -----
+
+func @missing_fields() {
+ // expected-error @+1 {{failed to satisfy constraint: DictionaryAttr with field(s): 'some_field', 'some_other_field' (each field having its own constraints)}}
+ "test.struct_attr"() {the_struct_attr = {}} : () -> ()
+ return
+}
+
+// -----
+
+func @erroneous_fields() {
+ // expected-error @+1 {{failed to satisfy constraint: DictionaryAttr with field(s): 'some_field', 'some_other_field' (each field having its own constraints)}}
+ "test.struct_attr"() {the_struct_attr = {some_field = 1 : i8, some_other_field = 1}} : () -> ()
+ return
+}
+
mlir_tablegen(TestOpsDialect.h.inc -gen-dialect-decls)
mlir_tablegen(TestOpEnums.h.inc -gen-enum-decls)
mlir_tablegen(TestOpEnums.cpp.inc -gen-enum-defs)
+mlir_tablegen(TestOpStructs.h.inc -gen-struct-attr-decls)
+mlir_tablegen(TestOpStructs.cpp.inc -gen-struct-attr-defs)
mlir_tablegen(TestPatterns.inc -gen-rewriters)
add_public_tablegen_target(MLIRTestOpsIncGen)
let results = (outs I32:$val);
}
+def SomeStructAttr : StructAttr<"SomeStructAttr", Test_Dialect, [
+ StructFieldAttr<"some_field", I64Attr>,
+ StructFieldAttr<"some_other_field", I64Attr>
+]> {}
+
+def StructAttrOp : TEST_Op<"struct_attr"> {
+ let arguments = (ins SomeStructAttr:$the_struct_attr);
+ let results = (outs);
+}
def IntAttrOp : TEST_Op<"int_attrs"> {
let arguments = (ins