I have been able to use enums to print it as either const or nonConst but that is not as readable as it would be to just have the const keyword or nothing. Furthermore enums cannot be used in combinations with DefaultValuedParameter since it only support EnumsAttr, or Optional which are both things i would like to avoid if possible.
Ideally i would like to be able to write something in the assembly format such as
but there does not seems to be any support for this pattern.
Is there a intended way to achieve this? If it is not present i can implement it myself and upstream it, either as suggested in the last snippet, or by supporting enums in DefaultValuedParameter.
the issue with that solution, which is the one i ended up using because i could not find an alternative, is that it prints const true instead of const alone.
auto Primitive = PrimitiveType::get(&context, PrimitiveKind::Signed, 4,
mlir::UnitAttr::get(&context));
builder.create<UndefOp>(builder.getUnknownLoc(), Primitive);
module.print(llvm::outs());
!int32_t = !dialect.primitive<const unit kind = Signed, byte_size = 4>
If I drop DefaultValuedParameter in favor of just "mlir::UnitAttr" then the parameter is not recognized as optional and thus it cannot be used a anchor of a optional group.
if i use UnitAttr without quotations then tablegen crashes due to a bad alloc in :DefGen::getBuilderParams(std::initializer_list<mlir::tblgen::MethodParameter>).
I guess there is no support to use UnitAttr within types?
i not sure i understand how a custom builder would solve the issue. from what i understand the issue is the attribute and type assembly format has no support for unitattr the same way operations do.
I looked into the tblgen code and i found the following relevant pieces of code.
In the parser printer generator for operations there is a hardcoded rule that specifies that if a attribute is called UnitAttr then it is omitted from the parser.
While there is no such rule for attributes and types.
Would it be a acceptable implementation to replicate the same logic for attributes and types?