[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
This commit is contained in:
Valentin Clement 2021-09-30 16:27:02 +02:00
parent 452714f8f8
commit a6fc555202
No known key found for this signature in database
GPG Key ID: 086D54783C928776
2 changed files with 31 additions and 21 deletions

View File

@ -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"; }

View File

@ -1213,6 +1213,35 @@ static mlir::ArrayAttr collectAsAttributes(mlir::MLIRContext *ctxt,
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
//===----------------------------------------------------------------------===//