Add a helper function to convert LogicalResult to int for return from main
authorThomas Köppe <tkoeppe@google.com>
Tue, 18 May 2021 23:44:25 +0000 (23:44 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Wed, 19 May 2021 00:12:39 +0000 (00:12 +0000)
commit58369fce30af484889356f225d89cb0b32009206
treef7c4d235e4a0ac95058fd77e739459f9c509f574
parent861d69a5259653f60d59795597493a7939b794fe
Add a helper function to convert LogicalResult to int for return from main

At present, a lot of code contains main function bodies like "return failed(mlir::MlirOptMain(...);". This is unfortunate for two reasons: a) it uses ADL, which is maybe not what the free "failed" function was designed for; and b) it is a bit awkward to read, requring the reader to both understand the boolean nature of the value and the semantics of main's return value. (And it's also not portable, since 1 is not a portable success value.)

The replacement code, `return mlir::AsMainReturnCode(mlir::MlirOptMain(...))` is a bit more self-explanatory.

The change applies the new function to a few internal uses of MlirOptMain, too.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D102641
mlir/examples/standalone/standalone-opt/standalone-opt.cpp
mlir/include/mlir/Support/MlirOptMain.h
mlir/tools/mlir-opt/mlir-opt.cpp