/home/arjun/llvm-project/mlir/include/mlir/Support/LogicalResult.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- LogicalResult.h - Utilities for handling success/failure -*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #ifndef MLIR_SUPPORT_LOGICAL_RESULT_H |
10 | | #define MLIR_SUPPORT_LOGICAL_RESULT_H |
11 | | |
12 | | #include "mlir/Support/LLVM.h" |
13 | | |
14 | | namespace mlir { |
15 | | |
16 | | // Values that can be used to signal success/failure. This should be used in |
17 | | // conjunction with the utility functions below. |
18 | | struct LogicalResult { |
19 | | enum ResultEnum { Success, Failure } value; |
20 | 415 | LogicalResult(ResultEnum v) : value(v) {} |
21 | | }; |
22 | | |
23 | | /// Utility function to generate a LogicalResult. If isSuccess is true a |
24 | | /// `success` result is generated, otherwise a 'failure' result is generated. |
25 | 356 | inline LogicalResult success(bool isSuccess = true) { |
26 | 356 | return LogicalResult{isSuccess ? LogicalResult::Success |
27 | 356 | : LogicalResult::Failure}; |
28 | 356 | } |
29 | | |
30 | | /// Utility function to generate a LogicalResult. If isFailure is true a |
31 | | /// `failure` result is generated, otherwise a 'success' result is generated. |
32 | 0 | inline LogicalResult failure(bool isFailure = true) { |
33 | 0 | return LogicalResult{isFailure ? LogicalResult::Failure |
34 | 0 | : LogicalResult::Success}; |
35 | 0 | } |
36 | | |
37 | | /// Utility function that returns true if the provided LogicalResult corresponds |
38 | | /// to a success value. |
39 | 0 | inline bool succeeded(LogicalResult result) { |
40 | 0 | return result.value == LogicalResult::Success; |
41 | 0 | } |
42 | | |
43 | | /// Utility function that returns true if the provided LogicalResult corresponds |
44 | | /// to a failure value. |
45 | 415 | inline bool failed(LogicalResult result) { |
46 | 415 | return result.value == LogicalResult::Failure; |
47 | 415 | } |
48 | | |
49 | | } // namespace mlir |
50 | | |
51 | | #endif // MLIR_SUPPORT_LOGICAL_RESULT_H |