diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -2929,28 +2929,9 @@ let arguments = (ins StrAttr:$lenparam, APIntAttr:$intval); - let parser = [{ - llvm::StringRef fieldName; - if (failed(parser.parseOptionalKeyword(&fieldName))) { - mlir::StringAttr fieldAttr; - if (parser.parseAttribute(fieldAttr, lenParamAttrName(), - result.attributes)) - return mlir::failure(); - } else { - result.addAttribute(lenParamAttrName(), - parser.getBuilder().getStringAttr(fieldName)); - } - mlir::IntegerAttr constant; - if (parser.parseComma() || - parser.parseAttribute(constant, intAttrName(), result.attributes)) - return mlir::failure(); - return mlir::success(); - }]; + let parser = "return parseGlobalLenOp(parser, result);"; - let printer = [{ - p << ' ' << (*this)->getAttr(lenParamAttrName()) - << ", " << (*this)->getAttr(intAttrName()); - }]; + let printer = "::print(p, *this);"; let extraClassDeclaration = [{ static constexpr llvm::StringRef lenParamAttrName() { return "lenparam"; } diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -1213,6 +1213,35 @@ return mlir::ArrayAttr::get(ctxt, attrs); } +//===----------------------------------------------------------------------===// +// GlobalLenOp +//===----------------------------------------------------------------------===// + +static mlir::ParseResult parseGlobalLenOp(mlir::OpAsmParser &parser, + mlir::OperationState &result) { + llvm::StringRef fieldName; + if (failed(parser.parseOptionalKeyword(&fieldName))) { + mlir::StringAttr fieldAttr; + if (parser.parseAttribute(fieldAttr, fir::GlobalLenOp::lenParamAttrName(), + result.attributes)) + return mlir::failure(); + } else { + result.addAttribute(fir::GlobalLenOp::lenParamAttrName(), + parser.getBuilder().getStringAttr(fieldName)); + } + mlir::IntegerAttr constant; + if (parser.parseComma() || + parser.parseAttribute(constant, fir::GlobalLenOp::intAttrName(), + result.attributes)) + return mlir::failure(); + return mlir::success(); +} + +static void print(mlir::OpAsmPrinter &p, fir::GlobalLenOp &op) { + p << ' ' << op.getOperation()->getAttr(fir::GlobalLenOp::lenParamAttrName()) + << ", " << op.getOperation()->getAttr(fir::GlobalLenOp::intAttrName()); +} + //===----------------------------------------------------------------------===// // ExtractValueOp //===----------------------------------------------------------------------===//