[flang-commits] [flang] bca0619 - [flang] Adapt mlir based error status handling in `tco` tool

Sourabh Singh Tomar via flang-commits flang-commits at lists.llvm.org
Thu Feb 4 21:37:42 PST 2021


Author: Sourabh Singh Tomar
Date: 2021-02-05T11:07:10+05:30
New Revision: bca0619a1bcad0d2be9f03ae5f768a64f48b1b8a

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

LOG: [flang] Adapt mlir based error status handling in `tco` tool

Earlier scheme was using negative integers for communicating error status,
switch to canonical MLIR style.

f18 commit authored by @schweitz:
https://github.com/flang-compiler/f18-llvm-project/commit/c1af08d6e70b66c08ee2fbf2e63c764ec2e006e5

Reviewed By: mehdi_amini, clementval, svedanayagam

Differential Revision: https://reviews.llvm.org/D96068

Added: 
    

Modified: 
    flang/tools/tco/tco.cpp

Removed: 
    


################################################################################
diff  --git a/flang/tools/tco/tco.cpp b/flang/tools/tco/tco.cpp
index 46e64b0cb4eb..5931d7b39206 100644
--- a/flang/tools/tco/tco.cpp
+++ b/flang/tools/tco/tco.cpp
@@ -47,14 +47,15 @@ static void printModuleBody(mlir::ModuleOp mod, raw_ostream &output) {
 }
 
 // compile a .fir file
-static int compileFIR() {
+static mlir::LogicalResult
+compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
   // check that there is a file to load
   ErrorOr<std::unique_ptr<MemoryBuffer>> fileOrErr =
       MemoryBuffer::getFileOrSTDIN(inputFilename);
 
   if (std::error_code EC = fileOrErr.getError()) {
     errs() << "Could not open file: " << EC.message() << '\n';
-    return 1;
+    return mlir::failure();
   }
 
   // load the file into a module
@@ -66,11 +67,11 @@ static int compileFIR() {
 
   if (!owningRef) {
     errs() << "Error can't load file " << inputFilename << '\n';
-    return 2;
+    return mlir::failure();
   }
   if (mlir::failed(owningRef->verify())) {
     errs() << "Error verifying FIR module\n";
-    return 4;
+    return mlir::failure();
   }
 
   std::error_code ec;
@@ -94,13 +95,13 @@ static int compileFIR() {
     if (emitFir)
       printModuleBody(*owningRef, out.os());
     out.keep();
-    return 0;
+    return mlir::success();
   }
 
   // pass manager failed
   printModuleBody(*owningRef, errs());
   errs() << "\n\nFAILED: " << inputFilename << '\n';
-  return 8;
+  return mlir::failure();
 }
 
 int main(int argc, char **argv) {
@@ -109,5 +110,5 @@ int main(int argc, char **argv) {
   mlir::registerPassManagerCLOptions();
   mlir::PassPipelineCLParser passPipe("", "Compiler passes to run");
   cl::ParseCommandLineOptions(argc, argv, "Tilikum Crossing Optimizer\n");
-  return compileFIR();
+  return mlir::failed(compileFIR(passPipe));
 }


        


More information about the flang-commits mailing list