[flang-commits] [flang] a6fc555 - [fir][NFC] Move parser/printer for fir.global_len

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Thu Sep 30 07:27:35 PDT 2021


Author: Valentin Clement
Date: 2021-09-30T16:27:30+02:00
New Revision: a6fc555202ac1bd77d9c6c9325d797ae7d83b30d

URL: https://github.com/llvm/llvm-project/commit/a6fc555202ac1bd77d9c6c9325d797ae7d83b30d
DIFF: https://github.com/llvm/llvm-project/commit/a6fc555202ac1bd77d9c6c9325d797ae7d83b30d.diff

LOG: [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

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIROps.td
    flang/lib/Optimizer/Dialect/FIROps.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 761bc9903c8c..986892730139 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 eca9f144eb3c..974765a293d7 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -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
 //===----------------------------------------------------------------------===//


        


More information about the flang-commits mailing list