mlir/tblgen test: add a test for EnumAttr customAssemblyFormat
authorRamkumar Ramachandra <r@artagnon.com>
Wed, 14 Dec 2022 17:55:07 +0000 (18:55 +0100)
committerRamkumar Ramachandra <r@artagnon.com>
Thu, 22 Dec 2022 16:31:16 +0000 (17:31 +0100)
attr-or-type-format.td contains tests for various attributes and types,
but nowhere in the testsuite is the customAssemblyFormat for an EnumAttr
(enum class in C++) exercised. Fix this by adding a test.

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>
Differential Revision: https://reviews.llvm.org/D140034

mlir/test/mlir-tblgen/attr-or-type-format.td

index 675104a..d4794c2 100644 (file)
@@ -2,6 +2,7 @@
 // RUN: mlir-tblgen -gen-typedef-defs -I %S/../../include %s | FileCheck %s --check-prefix=TYPE
 
 include "mlir/IR/AttrTypeBase.td"
+include "mlir/IR/EnumAttr.td"
 include "mlir/IR/OpBase.td"
 
 /// Test that attribute and type printers and parsers are correctly generated.
@@ -194,6 +195,23 @@ def AttrE : TestAttr<"TestH"> {
   let assemblyFormat = "custom<UseType>(ref($type))";
 }
 
+def TestEnum : I32EnumAttr<"TestEnum", "TestEnumType", [
+  I32EnumAttrCase<"first", 0>,
+  I32EnumAttrCase<"second", 1>
+]> {
+  let genSpecializedAttr = 0;
+}
+
+// ATTR-LABEL: TestEnumAttr::parse
+// ATTR: parseFoo(odsParser,
+// ATTR-NEXT: _result_value
+// ATTR-LABEL: TestEnumAttr::print
+// ATTR: printFoo(odsPrinter,
+// ATTR-NEXT: getValue()
+def EnumAttrA : EnumAttr<Test_Dialect, TestEnum, "EnumAttrA"> {
+  let assemblyFormat = "custom<Foo>($value)";
+}
+
 /// Test type parser and printer that mix variables and struct are generated
 /// correctly.