[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
GitOrigin-RevId: bca0619a1bcad0d2be9f03ae5f768a64f48b1b8a
diff --git a/tools/tco/tco.cpp b/tools/tco/tco.cpp
index 46e64b0..5931d7b 100644
--- a/tools/tco/tco.cpp
+++ b/tools/tco/tco.cpp
@@ -47,14 +47,15 @@
}
// 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 @@
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 @@
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 @@
mlir::registerPassManagerCLOptions();
mlir::PassPipelineCLParser passPipe("", "Compiler passes to run");
cl::ParseCommandLineOptions(argc, argv, "Tilikum Crossing Optimizer\n");
- return compileFIR();
+ return mlir::failed(compileFIR(passPipe));
}