[Mlir-commits] [mlir] [mlir][tblgen] Add custom parsing and printing within struct (PR #133939)
Jorn Tuyls
llvmlistbot at llvm.org
Wed Apr 9 05:44:33 PDT 2025
================
@@ -832,17 +871,24 @@ void DefFormat::genCommaSeparatedPrinter(
// The first printed element does not need to emit a comma.
os << "{\n";
os.indent() << "bool _firstPrinted = true;\n";
- for (ParameterElement *param : params) {
- if (param->isOptional()) {
- param->genPrintGuard(ctx, os << "if (") << ") {\n";
- os.indent();
+ for (FormatElement *arg : args) {
+ ParameterElement *param = getStructParameterElement(arg);
+ if (param) {
----------------
jtuyls wrote:
It should never be a nullptr as all arguments should be parameters or custom directives and that should be checked for in the struct verifier. There was a potential issue though with checks for `VariableElement` instead of `ParameterElement` so I changed that now: https://github.com/llvm/llvm-project/pull/133939/files#diff-45fcd0fba260dc191783b56cc9540bb8c4e8e51d6f76d2d66fde88ae2d04da0dR1121. And as `getStructParameterElement` should never encounter a `FormatElement` that is not a `ParameterElement` or `CustomDirective`, I added an assert there and removed the conditions on `param` here and below.
https://github.com/llvm/llvm-project/pull/133939
More information about the Mlir-commits
mailing list