From: Valentin Clement Date: Thu, 30 Sep 2021 14:27:02 +0000 (+0200) Subject: [fir][NFC] Move parser/printer for fir.global_len X-Git-Tag: upstream/15.0.7~30042 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a6fc555202ac1bd77d9c6c9325d797ae7d83b30d;p=platform%2Fupstream%2Fllvm.git [fir][NFC] Move parser/printer for fir.global_len Move parser and printer to the .cpp file. Follow up to https://reviews.llvm.org/D110626. This patch is part of the upstreaming effort from fir-dev branch. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D110828 --- diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td index 761bc99..9868927 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -2895,28 +2895,9 @@ def fir_GlobalLenOp : fir_Op<"global_len", []> { 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 index eca9f14..974765a 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -1214,6 +1214,35 @@ static mlir::ArrayAttr collectAsAttributes(mlir::MLIRContext *ctxt, } //===----------------------------------------------------------------------===// +// 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 //===----------------------------------------------------------------------===//