xref: /freebsd-src/contrib/llvm-project/llvm/include/llvm-c/Error.h (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
10b57cec5SDimitry Andric /*===------- llvm-c/Error.h - llvm::Error class C Interface -------*- C -*-===*\
20b57cec5SDimitry Andric |*                                                                            *|
30b57cec5SDimitry Andric |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
40b57cec5SDimitry Andric |* Exceptions.                                                                *|
50b57cec5SDimitry Andric |* See https://llvm.org/LICENSE.txt for license information.                  *|
60b57cec5SDimitry Andric |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
70b57cec5SDimitry Andric |*                                                                            *|
80b57cec5SDimitry Andric |*===----------------------------------------------------------------------===*|
90b57cec5SDimitry Andric |*                                                                            *|
100b57cec5SDimitry Andric |* This file defines the C interface to LLVM's Error class.                   *|
110b57cec5SDimitry Andric |*                                                                            *|
120b57cec5SDimitry Andric \*===----------------------------------------------------------------------===*/
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #ifndef LLVM_C_ERROR_H
150b57cec5SDimitry Andric #define LLVM_C_ERROR_H
160b57cec5SDimitry Andric 
17480093f4SDimitry Andric #include "llvm-c/ExternC.h"
18480093f4SDimitry Andric 
19480093f4SDimitry Andric LLVM_C_EXTERN_C_BEGIN
200b57cec5SDimitry Andric 
21*349cc55cSDimitry Andric /**
22*349cc55cSDimitry Andric  * @defgroup LLVMCError Error Handling
23*349cc55cSDimitry Andric  * @ingroup LLVMC
24*349cc55cSDimitry Andric  *
25*349cc55cSDimitry Andric  * @{
26*349cc55cSDimitry Andric  */
27*349cc55cSDimitry Andric 
280b57cec5SDimitry Andric #define LLVMErrorSuccess 0
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric /**
310b57cec5SDimitry Andric  * Opaque reference to an error instance. Null serves as the 'success' value.
320b57cec5SDimitry Andric  */
330b57cec5SDimitry Andric typedef struct LLVMOpaqueError *LLVMErrorRef;
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric /**
360b57cec5SDimitry Andric  * Error type identifier.
370b57cec5SDimitry Andric  */
380b57cec5SDimitry Andric typedef const void *LLVMErrorTypeId;
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric /**
410b57cec5SDimitry Andric  * Returns the type id for the given error instance, which must be a failure
420b57cec5SDimitry Andric  * value (i.e. non-null).
430b57cec5SDimitry Andric  */
440b57cec5SDimitry Andric LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err);
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric /**
470b57cec5SDimitry Andric  * Dispose of the given error without handling it. This operation consumes the
480b57cec5SDimitry Andric  * error, and the given LLVMErrorRef value is not usable once this call returns.
490b57cec5SDimitry Andric  * Note: This method *only* needs to be called if the error is not being passed
500b57cec5SDimitry Andric  * to some other consuming operation, e.g. LLVMGetErrorMessage.
510b57cec5SDimitry Andric  */
520b57cec5SDimitry Andric void LLVMConsumeError(LLVMErrorRef Err);
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric /**
550b57cec5SDimitry Andric  * Returns the given string's error message. This operation consumes the error,
560b57cec5SDimitry Andric  * and the given LLVMErrorRef value is not usable once this call returns.
570b57cec5SDimitry Andric  * The caller is responsible for disposing of the string by calling
580b57cec5SDimitry Andric  * LLVMDisposeErrorMessage.
590b57cec5SDimitry Andric  */
600b57cec5SDimitry Andric char *LLVMGetErrorMessage(LLVMErrorRef Err);
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric /**
630b57cec5SDimitry Andric  * Dispose of the given error message.
640b57cec5SDimitry Andric  */
650b57cec5SDimitry Andric void LLVMDisposeErrorMessage(char *ErrMsg);
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric /**
680b57cec5SDimitry Andric  * Returns the type id for llvm StringError.
690b57cec5SDimitry Andric  */
700b57cec5SDimitry Andric LLVMErrorTypeId LLVMGetStringErrorTypeId(void);
710b57cec5SDimitry Andric 
72e8d8bef9SDimitry Andric /**
73e8d8bef9SDimitry Andric  * Create a StringError.
74e8d8bef9SDimitry Andric  */
75e8d8bef9SDimitry Andric LLVMErrorRef LLVMCreateStringError(const char *ErrMsg);
76e8d8bef9SDimitry Andric 
77*349cc55cSDimitry Andric /**
78*349cc55cSDimitry Andric  * @}
79*349cc55cSDimitry Andric  */
80*349cc55cSDimitry Andric 
81480093f4SDimitry Andric LLVM_C_EXTERN_C_END
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric #endif
84