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

Jorn Tuyls llvmlistbot at llvm.org
Wed Apr 9 05:46:22 PDT 2025


================
@@ -1068,17 +1114,39 @@ DefFormatParser::verifyOptionalGroupElements(llvm::SMLoc loc,
     // arguments is a bound parameter.
     if (auto *custom = dyn_cast<CustomDirective>(anchor)) {
       const auto *bound =
-          llvm::find_if(custom->getArguments(), [](FormatElement *el) {
+          llvm::find_if(custom->getElements(), [](FormatElement *el) {
             return isa<ParameterElement>(el);
           });
-      if (bound == custom->getArguments().end())
+      if (bound == custom->getElements().end())
         return emitError(loc, "`custom` directive with no bound parameters "
                               "cannot be used as optional group anchor");
     }
   }
   return success();
 }
 
+LogicalResult
+DefFormatParser::verifyStructArguments(SMLoc loc,
+                                       ArrayRef<FormatElement *> arguments) {
+  for (FormatElement *el : arguments) {
+    if (!isa<VariableElement, CustomDirective, ParamsDirective>(el)) {
+      return emitError(loc, "expected a variable, custom directive or params "
+                            "directive in `struct` arguments list");
+    }
+    if (auto custom = dyn_cast<CustomDirective>(el)) {
+      if (custom->getNumElements() != 1) {
+        return emitError(loc, "`struct` can only contain `custom` directives "
+                              "with a single argument");
+      }
+      if (failed(custom->template getFrontAs<ParameterElement>())) {
----------------
jtuyls wrote:

Yes, thanks for catching this, removed it.

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


More information about the Mlir-commits mailing list