I try to understand how the assembly format works with EnumAttr
. I have the following piece of code for TestDialect
that defines an EnumAttr
and a few operations that use the enum.
def TestEnum
: I32EnumAttr<"TestEnum", "a test enum", [
I32EnumAttrCase<"First", 0, "first">,
I32EnumAttrCase<"Second", 1, "second">,
I32EnumAttrCase<"Third", 2, "third">,
]> {
let genSpecializedAttr = 0;
let cppNamespace = "test";
}
def TestEnumAttr : EnumAttr<Test_Dialect, TestEnum, "enum">;
def TestEnumArrayAttr : TypedArrayAttrBase<TestEnumAttr, "">;
def OpWithSingleEnum : TEST_Op<"op_with_single_enum"> {
let arguments = (ins TestEnumAttr:$value);
let assemblyFormat = "$value attr-dict";
}
def OpWithArrayEnum : TEST_Op<"op_with_array_enum"> {
let arguments = (ins TestEnumArrayAttr:$values);
let assemblyFormat = "$values attr-dict";
}
When EnumAttr is a simple attribute in “op_with_single_enum”, we get a nice print format:
test.op_with_single_enum first
But once wrapped into an array, the only option is
test.op_with_array_enum [#test<enum first>, #test<enum second>]
It’s a bit sad and counterintuitive that information about the type from TypedArrayAttrBase
is not used to have a nicer printing/parsing of arrays.
What would be really nice to have is:
test.op_with_array_enum [first, second]
And even:
test.op_with_array_enum { array_of_enums = [first, second] }
Are there any plans to do that? Is that even feasible?