xref: /llvm-project/llvm/include/llvm-c/Error.h (revision 45ef0d492f7b61613d0833fbf7eafdd41e137139)
100fb14daSLang Hames /*===------- llvm-c/Error.h - llvm::Error class C Interface -------*- C -*-===*\
200fb14daSLang Hames |*                                                                            *|
32946cd70SChandler Carruth |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
42946cd70SChandler Carruth |* Exceptions.                                                                *|
52946cd70SChandler Carruth |* See https://llvm.org/LICENSE.txt for license information.                  *|
62946cd70SChandler Carruth |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
700fb14daSLang Hames |*                                                                            *|
800fb14daSLang Hames |*===----------------------------------------------------------------------===*|
900fb14daSLang Hames |*                                                                            *|
1000fb14daSLang Hames |* This file defines the C interface to LLVM's Error class.                   *|
1100fb14daSLang Hames |*                                                                            *|
1200fb14daSLang Hames \*===----------------------------------------------------------------------===*/
1300fb14daSLang Hames 
1400fb14daSLang Hames #ifndef LLVM_C_ERROR_H
1500fb14daSLang Hames #define LLVM_C_ERROR_H
1600fb14daSLang Hames 
178c484050SDuncan P. N. Exon Smith #include "llvm-c/ExternC.h"
188c484050SDuncan P. N. Exon Smith 
198c484050SDuncan P. N. Exon Smith LLVM_C_EXTERN_C_BEGIN
2000fb14daSLang Hames 
21ad523cc3SMats Larsen /**
22ad523cc3SMats Larsen  * @defgroup LLVMCError Error Handling
23ad523cc3SMats Larsen  * @ingroup LLVMC
24ad523cc3SMats Larsen  *
25ad523cc3SMats Larsen  * @{
26ad523cc3SMats Larsen  */
27ad523cc3SMats Larsen 
2872d195ecSLang Hames #define LLVMErrorSuccess 0
2972d195ecSLang Hames 
3000fb14daSLang Hames /**
3100fb14daSLang Hames  * Opaque reference to an error instance. Null serves as the 'success' value.
3200fb14daSLang Hames  */
3300fb14daSLang Hames typedef struct LLVMOpaqueError *LLVMErrorRef;
3400fb14daSLang Hames 
3500fb14daSLang Hames /**
3600fb14daSLang Hames  * Error type identifier.
3700fb14daSLang Hames  */
3800fb14daSLang Hames typedef const void *LLVMErrorTypeId;
3900fb14daSLang Hames 
4000fb14daSLang Hames /**
4100fb14daSLang Hames  * Returns the type id for the given error instance, which must be a failure
4200fb14daSLang Hames  * value (i.e. non-null).
4300fb14daSLang Hames  */
4400fb14daSLang Hames LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err);
4500fb14daSLang Hames 
4600fb14daSLang Hames /**
4700fb14daSLang Hames  * Dispose of the given error without handling it. This operation consumes the
4800fb14daSLang Hames  * error, and the given LLVMErrorRef value is not usable once this call returns.
4900fb14daSLang Hames  * Note: This method *only* needs to be called if the error is not being passed
5000fb14daSLang Hames  * to some other consuming operation, e.g. LLVMGetErrorMessage.
5100fb14daSLang Hames  */
5200fb14daSLang Hames void LLVMConsumeError(LLVMErrorRef Err);
5300fb14daSLang Hames 
5400fb14daSLang Hames /**
55*45ef0d49SDavid Blaikie  * Report a fatal error if Err is a failure value.
56*45ef0d49SDavid Blaikie  *
57*45ef0d49SDavid Blaikie  * This function can be used to wrap calls to fallible functions ONLY when it is
58*45ef0d49SDavid Blaikie  * known that the Error will always be a success value.
59*45ef0d49SDavid Blaikie  */
60*45ef0d49SDavid Blaikie void LLVMCantFail(LLVMErrorRef Err);
61*45ef0d49SDavid Blaikie 
62*45ef0d49SDavid Blaikie /**
6300fb14daSLang Hames  * Returns the given string's error message. This operation consumes the error,
6400fb14daSLang Hames  * and the given LLVMErrorRef value is not usable once this call returns.
65d18d69f2SLang Hames  * The caller is responsible for disposing of the string by calling
66d18d69f2SLang Hames  * LLVMDisposeErrorMessage.
6700fb14daSLang Hames  */
6800fb14daSLang Hames char *LLVMGetErrorMessage(LLVMErrorRef Err);
6900fb14daSLang Hames 
7000fb14daSLang Hames /**
7100fb14daSLang Hames  * Dispose of the given error message.
7200fb14daSLang Hames  */
7300fb14daSLang Hames void LLVMDisposeErrorMessage(char *ErrMsg);
7400fb14daSLang Hames 
7500fb14daSLang Hames /**
7600fb14daSLang Hames  * Returns the type id for llvm StringError.
7700fb14daSLang Hames  */
784732d3abSAnders Waldenborg LLVMErrorTypeId LLVMGetStringErrorTypeId(void);
7900fb14daSLang Hames 
8019402ce7SLang Hames /**
8119402ce7SLang Hames  * Create a StringError.
8219402ce7SLang Hames  */
8319402ce7SLang Hames LLVMErrorRef LLVMCreateStringError(const char *ErrMsg);
8419402ce7SLang Hames 
85ad523cc3SMats Larsen /**
86ad523cc3SMats Larsen  * @}
87ad523cc3SMats Larsen  */
88ad523cc3SMats Larsen 
898c484050SDuncan P. N. Exon Smith LLVM_C_EXTERN_C_END
9000fb14daSLang Hames 
9100fb14daSLang Hames #endif
92