Loom C API
Public Loom compiler C API
Loading...
Searching...
No Matches
status.h
Go to the documentation of this file.
1// Copyright 2026 The IREE Authors
2//
3// Licensed 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#ifndef LOOMC_STATUS_H_
8#define LOOMC_STATUS_H_
9
10#include "loomc/base.h"
11
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
45#define LOOMC_STATUS_FEATURE_SOURCE_LOCATION (1 << 0)
46
48#define LOOMC_STATUS_FEATURE_ANNOTATIONS (1 << 1)
49
51#define LOOMC_STATUS_FEATURE_STACK_TRACE (1 << 2)
52
59#if !defined(LOOMC_STATUS_MODE)
60#if defined(IREE_STATUS_MODE)
61#define LOOMC_STATUS_MODE IREE_STATUS_MODE
62#elif defined(NDEBUG)
63#define LOOMC_STATUS_MODE 2
64#else
65#define LOOMC_STATUS_MODE 3
66#endif
67#endif
68
70#if !defined(LOOMC_STATUS_FEATURES)
71#if defined(LOOMC_STATUS_MODE) && LOOMC_STATUS_MODE == 1
72#define LOOMC_STATUS_FEATURES (LOOMC_STATUS_FEATURE_SOURCE_LOCATION)
73#elif defined(LOOMC_STATUS_MODE) && LOOMC_STATUS_MODE == 2
74#define LOOMC_STATUS_FEATURES \
75 (LOOMC_STATUS_FEATURE_SOURCE_LOCATION | LOOMC_STATUS_FEATURE_ANNOTATIONS)
76#elif defined(LOOMC_STATUS_MODE) && LOOMC_STATUS_MODE == 3
77#define LOOMC_STATUS_FEATURES \
78 (LOOMC_STATUS_FEATURE_SOURCE_LOCATION | LOOMC_STATUS_FEATURE_ANNOTATIONS | \
79 LOOMC_STATUS_FEATURE_STACK_TRACE)
80#else
81#define LOOMC_STATUS_FEATURES 0
82#endif
83#endif
84
151
160
169static inline loomc_status_t loomc_status_from_code(loomc_status_code_t code) {
170 return (loomc_status_t)((uintptr_t)code & LOOMC_STATUS_CODE_MASK);
171}
172
176static inline loomc_status_t loomc_ok_status(void) {
177 return loomc_status_from_code(LOOMC_STATUS_OK);
178}
179
184static inline loomc_status_code_t loomc_status_code(loomc_status_t status) {
185 return (loomc_status_code_t)((uintptr_t)status & LOOMC_STATUS_CODE_MASK);
186}
187
192static inline bool loomc_status_is_ok(loomc_status_t status) {
193 return (uintptr_t)status == LOOMC_STATUS_OK;
194}
195
210loomc_status_allocate(loomc_status_code_t code, const char* file, uint32_t line,
211 loomc_string_view_t message);
212
218#define loomc_make_status(code, message) \
219 loomc_status_allocate((code), __FILE__, __LINE__, \
220 loomc_make_cstring_view(message))
221
226
233
244 loomc_status_t new_status);
245
251
262
272
285 loomc_host_size_t buffer_capacity,
286 char* buffer,
287 loomc_host_size_t* out_length);
288
292#define LOOMC_RETURN_IF_ERROR(expr) \
293 do { \
294 loomc_status_t status__ = (expr); \
295 if (!loomc_status_is_ok(status__)) { \
296 return status__; \
297 } \
298 } while (0)
299
300#ifdef __cplusplus
301} // extern "C"
302#endif
303
304#endif // LOOMC_STATUS_H_
Base types, descriptors, spans, and host allocation helpers.
#define LOOMC_API_EXPORT
Exports a public Loom C API symbol from a shared library build.
Definition base.h:34
size_t loomc_host_size_t
Host allocation and container size type.
Definition base.h:45
struct iree_status_handle_t * loomc_status_t
Opaque status handle.
Definition base.h:55
loomc_status_code_t
Stable status codes shared by all Loom status modes.
Definition status.h:90
@ LOOMC_STATUS_PERMISSION_DENIED
The caller does not have permission for the requested operation.
Definition status.h:113
@ LOOMC_STATUS_INVALID_ARGUMENT
The caller provided an invalid argument.
Definition status.h:101
@ LOOMC_STATUS_INCOMPATIBLE
The program or environment is incompatible with the request.
Definition status.h:146
@ LOOMC_STATUS_CODE_MASK
Mask covering all status code bits in a loomc_status_t value.
Definition status.h:149
@ LOOMC_STATUS_UNKNOWN
Unknown error or unmapped failure.
Definition status.h:98
@ LOOMC_STATUS_UNAUTHENTICATED
The requested operation does not have proper authentication.
Definition status.h:140
@ LOOMC_STATUS_OK
Successful operation.
Definition status.h:92
@ LOOMC_STATUS_NOT_FOUND
A referenced resource could not be found.
Definition status.h:107
@ LOOMC_STATUS_DEADLINE_EXCEEDED
A deadline was exceeded before the call completed.
Definition status.h:104
@ LOOMC_STATUS_INTERNAL
An internal invariant was violated.
Definition status.h:131
@ LOOMC_STATUS_FAILED_PRECONDITION
The system is not in a required state for the operation.
Definition status.h:119
@ LOOMC_STATUS_DEFERRED
The operation has been deferred and must be resumed later.
Definition status.h:143
@ LOOMC_STATUS_RESOURCE_EXHAUSTED
A required resource was exhausted.
Definition status.h:116
@ LOOMC_STATUS_DATA_LOSS
Unrecoverable data loss or corruption occurred.
Definition status.h:137
@ LOOMC_STATUS_CANCELLED
Operation was cancelled by the caller.
Definition status.h:95
@ LOOMC_STATUS_ABORTED
The operation was aborted by the system.
Definition status.h:122
@ LOOMC_STATUS_ALREADY_EXISTS
The resource the caller attempted to create already exists.
Definition status.h:110
@ LOOMC_STATUS_UNIMPLEMENTED
The operation has not been implemented or is not supported.
Definition status.h:128
@ LOOMC_STATUS_OUT_OF_RANGE
The operation was attempted outside a valid range.
Definition status.h:125
@ LOOMC_STATUS_UNAVAILABLE
The underlying system is currently unavailable.
Definition status.h:134
loomc_status_code_t loomc_status_consume_code(loomc_status_t status)
Frees status storage and returns its code.
bool loomc_status_format(loomc_status_t status, loomc_host_size_t buffer_capacity, char *buffer, loomc_host_size_t *out_length)
Formats status into buffer using the two-pass pattern.
loomc_status_t loomc_status_allocate(loomc_status_code_t code, const char *file, uint32_t line, loomc_string_view_t message)
Allocates a rich status when enabled by LOOMC_STATUS_MODE.
const char * loomc_status_code_string(loomc_status_code_t code)
Returns a stable C string naming code.
loomc_status_t loomc_status_join(loomc_status_t base_status, loomc_status_t new_status)
Joins two statuses without discarding cleanup failures.
loomc_status_source_location_t loomc_status_source_location(loomc_status_t status)
Returns the source location captured by status, when available.
loomc_string_view_t loomc_status_message(loomc_status_t status)
Returns the primary message stored in status.
void loomc_status_free(loomc_status_t status)
Frees status storage, if any.
Source location captured when rich status mode supports it.
Definition status.h:153
loomc_string_view_t file
Source file path, or empty when unavailable.
Definition status.h:155
uint32_t line
One-based source line, or zero when unavailable.
Definition status.h:158
Non-owning string view over bytes that need not be NUL-terminated.
Definition base.h:63