Loom C API
Public Loom compiler C API
Loading...
Searching...
No Matches
iree.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_IREE_H_
8#define LOOMC_IREE_H_
9
10#include <stddef.h>
11
12#include "iree/base/api.h"
13#include "iree/base/byte_sequence.h"
14#include "loomc/byte_sequence.h"
15#include "loomc/status.h"
16
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
53#if defined(__cplusplus)
54#define LOOMC_IREE_STATIC_ASSERT static_assert
55#else
56#define LOOMC_IREE_STATIC_ASSERT _Static_assert
57#endif
58
59LOOMC_IREE_STATIC_ASSERT(sizeof(loomc_string_view_t) ==
60 sizeof(iree_string_view_t),
61 "loomc_string_view_t must match iree_string_view_t");
62LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_string_view_t, data) ==
63 offsetof(iree_string_view_t, data),
64 "string view data fields must match");
65LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_string_view_t, size) ==
66 offsetof(iree_string_view_t, size),
67 "string view size fields must match");
68LOOMC_IREE_STATIC_ASSERT(sizeof(loomc_byte_span_t) ==
69 sizeof(iree_const_byte_span_t),
70 "loomc_byte_span_t must match iree_const_byte_span_t");
71LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_byte_span_t, data) ==
72 offsetof(iree_const_byte_span_t, data),
73 "byte span data fields must match");
74LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_byte_span_t, data_length) ==
75 offsetof(iree_const_byte_span_t, data_length),
76 "byte span length fields must match");
77IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_OK, IREE_STATUS_OK,
78 "status code values must match");
79IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_CANCELLED, IREE_STATUS_CANCELLED,
80 "status code values must match");
81IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_UNKNOWN, IREE_STATUS_UNKNOWN,
82 "status code values must match");
83IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_INVALID_ARGUMENT,
84 IREE_STATUS_INVALID_ARGUMENT,
85 "status code values must match");
86IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_DEADLINE_EXCEEDED,
87 IREE_STATUS_DEADLINE_EXCEEDED,
88 "status code values must match");
89IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_NOT_FOUND, IREE_STATUS_NOT_FOUND,
90 "status code values must match");
91IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_ALREADY_EXISTS,
92 IREE_STATUS_ALREADY_EXISTS,
93 "status code values must match");
94IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_PERMISSION_DENIED,
95 IREE_STATUS_PERMISSION_DENIED,
96 "status code values must match");
97IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_RESOURCE_EXHAUSTED,
98 IREE_STATUS_RESOURCE_EXHAUSTED,
99 "status code values must match");
100IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_FAILED_PRECONDITION,
101 IREE_STATUS_FAILED_PRECONDITION,
102 "status code values must match");
103IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_ABORTED, IREE_STATUS_ABORTED,
104 "status code values must match");
105IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_OUT_OF_RANGE, IREE_STATUS_OUT_OF_RANGE,
106 "status code values must match");
107IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_UNIMPLEMENTED,
108 IREE_STATUS_UNIMPLEMENTED,
109 "status code values must match");
110IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_INTERNAL, IREE_STATUS_INTERNAL,
111 "status code values must match");
112IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_UNAVAILABLE, IREE_STATUS_UNAVAILABLE,
113 "status code values must match");
114IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_DATA_LOSS, IREE_STATUS_DATA_LOSS,
115 "status code values must match");
116IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_UNAUTHENTICATED,
117 IREE_STATUS_UNAUTHENTICATED,
118 "status code values must match");
119IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_DEFERRED, IREE_STATUS_DEFERRED,
120 "status code values must match");
121IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_INCOMPATIBLE, IREE_STATUS_INCOMPATIBLE,
122 "status code values must match");
123IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_CODE_MASK, IREE_STATUS_CODE_MASK,
124 "status code masks must match");
125LOOMC_IREE_STATIC_ASSERT(LOOMC_STATUS_FEATURES == IREE_STATUS_FEATURES,
126 "status feature modes must match");
127IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_ALLOCATOR_COMMAND_MALLOC,
128 IREE_ALLOCATOR_COMMAND_MALLOC,
129 "allocator malloc commands must match");
130IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_ALLOCATOR_COMMAND_CALLOC,
131 IREE_ALLOCATOR_COMMAND_CALLOC,
132 "allocator calloc commands must match");
133IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_ALLOCATOR_COMMAND_REALLOC,
134 IREE_ALLOCATOR_COMMAND_REALLOC,
135 "allocator realloc commands must match");
136IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_ALLOCATOR_COMMAND_FREE,
137 IREE_ALLOCATOR_COMMAND_FREE,
138 "allocator free commands must match");
139LOOMC_IREE_STATIC_ASSERT(sizeof(loomc_allocator_alloc_params_t) ==
140 sizeof(iree_allocator_alloc_params_t),
141 "allocator parameter structures must match");
142LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_allocator_alloc_params_t,
143 byte_length) ==
144 offsetof(iree_allocator_alloc_params_t,
145 byte_length),
146 "allocator parameter byte lengths must match");
148
158static inline loomc_status_t loomc_status_from_iree(iree_status_t status) {
159 return status;
160}
161
170static inline iree_status_t iree_status_from_loomc(loomc_status_t status) {
171 return status;
172}
173
181static inline loomc_string_view_t loomc_string_view_from_iree(
182 iree_string_view_t value) {
183 return loomc_make_string_view(value.data, value.size);
184}
185
193static inline iree_string_view_t iree_string_view_from_loomc(
194 loomc_string_view_t value) {
195 return iree_make_string_view(value.data, value.size);
196}
197
205static inline loomc_byte_span_t loomc_byte_span_from_iree(
206 iree_const_byte_span_t value) {
207 return loomc_make_byte_span(value.data, value.data_length);
208}
209
217static inline iree_const_byte_span_t iree_const_byte_span_from_loomc(
218 loomc_byte_span_t value) {
219 return iree_make_const_byte_span(value.data, value.data_length);
220}
221
225static inline loomc_byte_sequence_t* loomc_byte_sequence_from_iree(
226 iree_byte_sequence_t* sequence) {
227 return (loomc_byte_sequence_t*)sequence;
228}
229
233static inline iree_byte_sequence_t* iree_byte_sequence_from_loomc(
234 loomc_byte_sequence_t* sequence) {
235 return (iree_byte_sequence_t*)sequence;
236}
237
246static inline loomc_allocator_t loomc_allocator_from_iree(
247 iree_allocator_t allocator) {
248 loomc_allocator_t value = {
249 allocator.self,
250 allocator.ctl,
251 };
252 return value;
253}
254
263static inline iree_allocator_t iree_allocator_from_loomc(
264 loomc_allocator_t allocator) {
265 IREE_ASSERT_ARGUMENT(loomc_allocator_is_valid(allocator));
266 iree_allocator_t value = {
267 allocator.self,
268 allocator.ctl,
269 };
270 return value;
271}
272
273#undef LOOMC_IREE_STATIC_ASSERT
274
275#ifdef __cplusplus
276} // extern "C"
277#endif
278
279#endif // LOOMC_IREE_H_
@ LOOMC_ALLOCATOR_COMMAND_REALLOC
Resizes an existing allocation.
Definition base.h:375
@ LOOMC_ALLOCATOR_COMMAND_MALLOC
Allocates memory without requiring zero initialization.
Definition base.h:369
@ LOOMC_ALLOCATOR_COMMAND_CALLOC
Allocates memory and zeros it before returning.
Definition base.h:372
@ LOOMC_ALLOCATOR_COMMAND_FREE
Frees an existing allocation.
Definition base.h:378
struct iree_status_handle_t * loomc_status_t
Opaque status handle.
Definition base.h:55
Immutable ref-counted byte sequences.
struct loomc_byte_sequence_t loomc_byte_sequence_t
Immutable logical sequence of bytes stored in one or more segments.
Definition byte_sequence.h:28
Status codes and rich infrastructure error reporting.
@ 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
#define LOOMC_STATUS_FEATURES
Feature bit mask derived from LOOMC_STATUS_MODE.
Definition status.h:81
Allocation parameters passed to loomc_allocator_ctl_fn_t callbacks.
Definition base.h:385
Host allocator used for persistent Loom object storage.
Definition base.h:414
loomc_allocator_ctl_fn_t ctl
Callback implementing allocation commands.
Definition base.h:419
void * self
Callback-owned state pointer.
Definition base.h:416
Non-owning view over immutable bytes.
Definition base.h:128
loomc_host_size_t data_length
Number of bytes in data.
Definition base.h:133
const uint8_t * data
First byte of the span, or NULL when the span is empty.
Definition base.h:130
Non-owning string view over bytes that need not be NUL-terminated.
Definition base.h:63
const char * data
First byte of the string, or NULL when the view is empty.
Definition base.h:65
loomc_host_size_t size
Number of bytes in data.
Definition base.h:68