blob: c3baaf65186aac65ec84d97cde1aa41b165d2df9 [file] [log] [blame]
Lang Hames00fb14d2018-08-15 18:42:11 +00001/*===------- llvm-c/Error.h - llvm::Error class C Interface -------*- C -*-===*\
2|* *|
Chandler Carruth2946cd72019-01-19 08:50:56 +00003|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4|* Exceptions. *|
5|* See https://llvm.org/LICENSE.txt for license information. *|
6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
Lang Hames00fb14d2018-08-15 18:42:11 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This file defines the C interface to LLVM's Error class. *|
11|* *|
12\*===----------------------------------------------------------------------===*/
13
14#ifndef LLVM_C_ERROR_H
15#define LLVM_C_ERROR_H
16
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080017#include "llvm-c/ExternC.h"
18
19LLVM_C_EXTERN_C_BEGIN
Lang Hames00fb14d2018-08-15 18:42:11 +000020
Mats Larsenad523cc2021-11-07 12:23:17 +010021/**
22 * @defgroup LLVMCError Error Handling
23 * @ingroup LLVMC
24 *
25 * @{
26 */
27
Lang Hames72d195e2018-09-23 02:09:18 +000028#define LLVMErrorSuccess 0
29
Lang Hames00fb14d2018-08-15 18:42:11 +000030/**
31 * Opaque reference to an error instance. Null serves as the 'success' value.
32 */
33typedef struct LLVMOpaqueError *LLVMErrorRef;
34
35/**
36 * Error type identifier.
37 */
38typedef const void *LLVMErrorTypeId;
39
40/**
41 * Returns the type id for the given error instance, which must be a failure
42 * value (i.e. non-null).
43 */
44LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err);
45
46/**
47 * Dispose of the given error without handling it. This operation consumes the
48 * error, and the given LLVMErrorRef value is not usable once this call returns.
49 * Note: This method *only* needs to be called if the error is not being passed
50 * to some other consuming operation, e.g. LLVMGetErrorMessage.
51 */
52void LLVMConsumeError(LLVMErrorRef Err);
53
54/**
55 * Returns the given string's error message. This operation consumes the error,
56 * and the given LLVMErrorRef value is not usable once this call returns.
Lang Hamesd18d69f2018-09-29 23:49:54 +000057 * The caller is responsible for disposing of the string by calling
58 * LLVMDisposeErrorMessage.
Lang Hames00fb14d2018-08-15 18:42:11 +000059 */
60char *LLVMGetErrorMessage(LLVMErrorRef Err);
61
62/**
63 * Dispose of the given error message.
64 */
65void LLVMDisposeErrorMessage(char *ErrMsg);
66
67/**
68 * Returns the type id for llvm StringError.
69 */
Anders Waldenborg4732d3a2019-05-06 06:42:06 +000070LLVMErrorTypeId LLVMGetStringErrorTypeId(void);
Lang Hames00fb14d2018-08-15 18:42:11 +000071
Lang Hames19402ce2020-10-15 17:31:14 -070072/**
73 * Create a StringError.
74 */
75LLVMErrorRef LLVMCreateStringError(const char *ErrMsg);
76
Mats Larsenad523cc2021-11-07 12:23:17 +010077/**
78 * @}
79 */
80
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080081LLVM_C_EXTERN_C_END
Lang Hames00fb14d2018-08-15 18:42:11 +000082
83#endif