[Mlir-commits] [mlir] [mlir][tblgen] Add custom parsing and printing within struct (PR #133939)

Jorn Tuyls llvmlistbot at llvm.org
Mon Apr 21 23:43:45 PDT 2025


================
@@ -316,6 +316,27 @@ static ParseResult parseCustomFloatAttr(AsmParser &p, StringAttr &typeStrAttr,
   return success();
 }
 
+//===----------------------------------------------------------------------===//
+// TestCustomStructAttr
+//===----------------------------------------------------------------------===//
+
+static void printCustomStructAttr(AsmPrinter &p, int64_t value) {
+  p.printStrippedAttrOrType(value);
+}
+
+static ParseResult parseCustomStructAttr(AsmParser &p, int64_t &value) {
+  return p.parseInteger(value);
+}
+
+static void printCustomOptStructFieldAttr(AsmPrinter &p, ArrayAttr attr) {
+  p.printStrippedAttrOrType(attr);
+}
+
+static ParseResult parseCustomOptStructFieldAttr(AsmParser &p,
+                                                 ArrayAttr &attr) {
+  return p.parseAttribute(attr);
+}
----------------
jtuyls wrote:

The purpose of these is not to test custom parsing, but to check a custom directive around both a required and optional parameter and verify that all the roundtrip and and invalid behavior is happening correctly in [custom-struct-attr-roundtrip.mlir](https://github.com/llvm/llvm-project/pull/133939/files#diff-2e687534c0cd522ab83b55a880dbb53aa6548e9f9a7ef4c10da0462006a14121). The actual implementation of these functions is not relevant to those tests.

https://github.com/llvm/llvm-project/pull/133939


More information about the Mlir-commits mailing list