[Mlir-commits] [mlir] [mlir] Add struct parsing and printing utilities (PR #133939)
Mehdi Amini
llvmlistbot at llvm.org
Thu Apr 3 06:40:16 PDT 2025
================
@@ -316,6 +316,41 @@ static ParseResult parseCustomFloatAttr(AsmParser &p, StringAttr &typeStrAttr,
return success();
}
+//===----------------------------------------------------------------------===//
+// TestCustomStructAttr
+//===----------------------------------------------------------------------===//
+
+Attribute TestCustomStructAttr::parse(AsmParser &p, Type type) {
+ std::string typeStr;
+ int64_t value;
+ FailureOr<ArrayAttr> optParam;
+ if (failed(p.parseStruct(AsmParser::Delimiter::LessGreater,
+ {"type_str", "value", "opt_param"},
+ {[&]() { return p.parseString(&typeStr); },
+ [&]() { return p.parseInteger(value); },
+ [&]() {
+ optParam = mlir::FieldParser<ArrayAttr>::parse(p);
+ return success(succeeded(optParam));
+ }}))) {
+ p.emitError(p.getCurrentLocation())
+ << "failed parsing `TestCustomStructAttr`";
+ return {};
+ }
+ return get(p.getContext(), StringAttr::get(p.getContext(), typeStr), value,
+ optParam.value_or(ArrayAttr()));
+}
+
+void TestCustomStructAttr::print(AsmPrinter &p) const {
+ p << "<";
+ p.printStruct(std::make_pair("type_str", getTypeStr()),
+ std::make_pair("value", getValue()));
----------------
joker-eph wrote:
I'm not sure about this API for the print part: isn't this just something that is trivial with interleaveComma?
https://github.com/llvm/llvm-project/pull/133939
More information about the Mlir-commits
mailing list