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/loomc.h"
15
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
50#if defined(__cplusplus)
51#define LOOMC_IREE_STATIC_ASSERT static_assert
52#else
53#define LOOMC_IREE_STATIC_ASSERT _Static_assert
54#endif
55
56LOOMC_IREE_STATIC_ASSERT(sizeof(loomc_string_view_t) ==
57 sizeof(iree_string_view_t),
58 "loomc_string_view_t must match iree_string_view_t");
59LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_string_view_t, data) ==
60 offsetof(iree_string_view_t, data),
61 "string view data fields must match");
62LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_string_view_t, size) ==
63 offsetof(iree_string_view_t, size),
64 "string view size fields must match");
65LOOMC_IREE_STATIC_ASSERT(sizeof(loomc_byte_span_t) ==
66 sizeof(iree_const_byte_span_t),
67 "loomc_byte_span_t must match iree_const_byte_span_t");
68LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_byte_span_t, data) ==
69 offsetof(iree_const_byte_span_t, data),
70 "byte span data fields must match");
71LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_byte_span_t, data_length) ==
72 offsetof(iree_const_byte_span_t, data_length),
73 "byte span length fields must match");
74IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_OK, IREE_STATUS_OK,
75 "status code values must match");
76IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_CANCELLED, IREE_STATUS_CANCELLED,
77 "status code values must match");
78IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_UNKNOWN, IREE_STATUS_UNKNOWN,
79 "status code values must match");
80IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_INVALID_ARGUMENT,
81 IREE_STATUS_INVALID_ARGUMENT,
82 "status code values must match");
83IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_DEADLINE_EXCEEDED,
84 IREE_STATUS_DEADLINE_EXCEEDED,
85 "status code values must match");
86IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_NOT_FOUND, IREE_STATUS_NOT_FOUND,
87 "status code values must match");
88IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_ALREADY_EXISTS,
89 IREE_STATUS_ALREADY_EXISTS,
90 "status code values must match");
91IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_PERMISSION_DENIED,
92 IREE_STATUS_PERMISSION_DENIED,
93 "status code values must match");
94IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_RESOURCE_EXHAUSTED,
95 IREE_STATUS_RESOURCE_EXHAUSTED,
96 "status code values must match");
97IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_FAILED_PRECONDITION,
98 IREE_STATUS_FAILED_PRECONDITION,
99 "status code values must match");
100IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_ABORTED, IREE_STATUS_ABORTED,
101 "status code values must match");
102IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_OUT_OF_RANGE, IREE_STATUS_OUT_OF_RANGE,
103 "status code values must match");
104IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_UNIMPLEMENTED,
105 IREE_STATUS_UNIMPLEMENTED,
106 "status code values must match");
107IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_INTERNAL, IREE_STATUS_INTERNAL,
108 "status code values must match");
109IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_UNAVAILABLE, IREE_STATUS_UNAVAILABLE,
110 "status code values must match");
111IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_DATA_LOSS, IREE_STATUS_DATA_LOSS,
112 "status code values must match");
113IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_UNAUTHENTICATED,
114 IREE_STATUS_UNAUTHENTICATED,
115 "status code values must match");
116IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_DEFERRED, IREE_STATUS_DEFERRED,
117 "status code values must match");
118IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_INCOMPATIBLE, IREE_STATUS_INCOMPATIBLE,
119 "status code values must match");
120IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_STATUS_CODE_MASK, IREE_STATUS_CODE_MASK,
121 "status code masks must match");
122LOOMC_IREE_STATIC_ASSERT(LOOMC_STATUS_FEATURES == IREE_STATUS_FEATURES,
123 "status feature modes must match");
124IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_ALLOCATOR_COMMAND_MALLOC,
125 IREE_ALLOCATOR_COMMAND_MALLOC,
126 "allocator malloc commands must match");
127IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_ALLOCATOR_COMMAND_CALLOC,
128 IREE_ALLOCATOR_COMMAND_CALLOC,
129 "allocator calloc commands must match");
130IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_ALLOCATOR_COMMAND_REALLOC,
131 IREE_ALLOCATOR_COMMAND_REALLOC,
132 "allocator realloc commands must match");
133IREE_STATIC_ASSERT_ENUM_EQ(LOOMC_ALLOCATOR_COMMAND_FREE,
134 IREE_ALLOCATOR_COMMAND_FREE,
135 "allocator free commands must match");
136LOOMC_IREE_STATIC_ASSERT(sizeof(loomc_allocator_alloc_params_t) ==
137 sizeof(iree_allocator_alloc_params_t),
138 "allocator parameter structures must match");
139LOOMC_IREE_STATIC_ASSERT(offsetof(loomc_allocator_alloc_params_t,
140 byte_length) ==
141 offsetof(iree_allocator_alloc_params_t,
142 byte_length),
143 "allocator parameter byte lengths must match");
145
155static inline loomc_status_t loomc_status_from_iree(iree_status_t status) {
156 return status;
157}
158
167static inline iree_status_t iree_status_from_loomc(loomc_status_t status) {
168 return status;
169}
170
178static inline loomc_string_view_t loomc_string_view_from_iree(
179 iree_string_view_t value) {
180 return loomc_make_string_view(value.data, value.size);
181}
182
190static inline iree_string_view_t iree_string_view_from_loomc(
191 loomc_string_view_t value) {
192 return iree_make_string_view(value.data, value.size);
193}
194
202static inline loomc_byte_span_t loomc_byte_span_from_iree(
203 iree_const_byte_span_t value) {
204 return loomc_make_byte_span(value.data, value.data_length);
205}
206
214static inline iree_const_byte_span_t iree_const_byte_span_from_loomc(
215 loomc_byte_span_t value) {
216 return iree_make_const_byte_span(value.data, value.data_length);
217}
218
222static inline loomc_byte_sequence_t* loomc_byte_sequence_from_iree(
223 iree_byte_sequence_t* sequence) {
224 return (loomc_byte_sequence_t*)sequence;
225}
226
230static inline iree_byte_sequence_t* iree_byte_sequence_from_loomc(
231 loomc_byte_sequence_t* sequence) {
232 return (iree_byte_sequence_t*)sequence;
233}
234
243static inline loomc_allocator_t loomc_allocator_from_iree(
244 iree_allocator_t allocator) {
245 loomc_allocator_t value = {
246 allocator.self,
247 allocator.ctl,
248 };
249 return value;
250}
251
260static inline iree_allocator_t iree_allocator_from_loomc(
261 loomc_allocator_t allocator) {
262 IREE_ASSERT_ARGUMENT(loomc_allocator_is_valid(allocator));
263 iree_allocator_t value = {
264 allocator.self,
265 allocator.ctl,
266 };
267 return value;
268}
269
270#undef LOOMC_IREE_STATIC_ASSERT
271
272#ifdef __cplusplus
273} // extern "C"
274#endif
275
276#endif // LOOMC_IREE_H_
@ LOOMC_ALLOCATOR_COMMAND_REALLOC
Resizes an existing allocation.
Definition base.h:351
@ LOOMC_ALLOCATOR_COMMAND_MALLOC
Allocates memory without requiring zero initialization.
Definition base.h:345
@ LOOMC_ALLOCATOR_COMMAND_CALLOC
Allocates memory and zeros it before returning.
Definition base.h:348
@ LOOMC_ALLOCATOR_COMMAND_FREE
Frees an existing allocation.
Definition base.h:354
struct iree_status_handle_t * loomc_status_t
Opaque status handle.
Definition base.h:55
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
Umbrella include for the public Loom C API.
@ 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:361
Host allocator used for persistent Loom object storage.
Definition base.h:390
loomc_allocator_ctl_fn_t ctl
Callback implementing allocation commands.
Definition base.h:395
void * self
Callback-owned state pointer.
Definition base.h:392
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