Loom C API
Public Loom compiler C API
Loading...
Searching...
No Matches
source.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_SOURCE_H_
8#define LOOMC_SOURCE_H_
9
10#include <stdio.h>
11
12#include "loomc/status.h"
13
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
82
94
106
117 void* user_data, loomc_byte_span_t contents);
118
153
179
201 loomc_allocator_t allocator, loomc_source_t** out_source);
202
224 FILE* file, const loomc_source_load_options_t* options,
225 loomc_allocator_t allocator, loomc_source_t** out_source);
226
247 loomc_allocator_t allocator, loomc_source_t** out_source);
248
256
265
272
282
293
294#ifdef __cplusplus
295} // extern "C"
296#endif
297
298#endif // LOOMC_SOURCE_H_
#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
loomc_structure_type_t
Structure type values used by extensible public descriptors.
Definition base.h:181
#define LOOMC_API_PTR
Marks a public callback function pointer type.
Definition base.h:38
struct iree_status_handle_t * loomc_status_t
Opaque status handle.
Definition base.h:55
loomc_status_t loomc_source_create_from_file(FILE *file, const loomc_source_load_options_t *options, loomc_allocator_t allocator, loomc_source_t **out_source)
Creates an immutable source by reading an open file.
loomc_source_storage_t
Storage policy for source bytes.
Definition source.h:96
@ LOOMC_SOURCE_STORAGE_COPY
Source bytes are copied into storage owned by the source.
Definition source.h:101
@ LOOMC_SOURCE_STORAGE_BORROWED
Source bytes are borrowed from the caller for the lifetime of the source.
Definition source.h:98
@ LOOMC_SOURCE_STORAGE_EXTERNAL
Source bytes are owned externally and released by a caller callback.
Definition source.h:104
loomc_string_view_t loomc_source_identifier(const loomc_source_t *source)
Returns the source identifier.
void loomc_source_release(loomc_source_t *source)
Releases source from one owner.
void(* loomc_source_release_fn_t)(void *user_data, loomc_byte_span_t contents)
Callback used to release externally owned source bytes.
Definition source.h:116
struct loomc_source_t loomc_source_t
Immutable source handle.
Definition source.h:81
loomc_source_format_t loomc_source_format(const loomc_source_t *source)
Returns the source format.
loomc_byte_span_t loomc_source_contents(const loomc_source_t *source)
Returns the source contents.
void loomc_source_retain(loomc_source_t *source)
Retains source for another owner.
loomc_status_t loomc_source_create_from_path(loomc_string_view_t path, const loomc_source_load_options_t *options, loomc_allocator_t allocator, loomc_source_t **out_source)
Creates an immutable source by reading a filesystem path.
loomc_source_format_t
Source byte format.
Definition source.h:84
@ LOOMC_SOURCE_FORMAT_UNKNOWN
Source format is unknown and must be inferred by the consumer.
Definition source.h:86
@ LOOMC_SOURCE_FORMAT_TEXT
Textual .loom source.
Definition source.h:89
@ LOOMC_SOURCE_FORMAT_BYTECODE
Binary .loombc source.
Definition source.h:92
loomc_status_t loomc_source_create(const loomc_source_options_t *options, loomc_allocator_t allocator, loomc_source_t **out_source)
Creates an immutable source handle.
Status codes and rich infrastructure error reporting.
Host allocator used for persistent Loom object storage.
Definition base.h:390
Non-owning view over immutable bytes.
Definition base.h:128
Source load options for host file and path constructors.
Definition source.h:159
loomc_source_format_t format
Loaded source format.
Definition source.h:171
loomc_string_view_t identifier
Stable identifier used in diagnostics and provider labels.
Definition source.h:177
loomc_host_size_t structure_size
Size of this structure in bytes.
Definition source.h:165
const void * next
Reserved extension chain. Must be NULL.
Definition source.h:168
loomc_structure_type_t type
Structure type.
Definition source.h:162
Source creation options.
Definition source.h:124
loomc_source_format_t format
Input source format.
Definition source.h:136
loomc_source_storage_t storage
Storage policy for contents.
Definition source.h:145
loomc_structure_type_t type
Structure type.
Definition source.h:127
const void * next
Extension chain for future source options.
Definition source.h:133
loomc_string_view_t identifier
Stable identifier used in diagnostics and provider labels.
Definition source.h:139
void * release_user_data
User data passed to release.
Definition source.h:151
loomc_source_release_fn_t release
Callback used when storage is LOOMC_SOURCE_STORAGE_EXTERNAL.
Definition source.h:148
loomc_host_size_t structure_size
Size of this structure in bytes.
Definition source.h:130
loomc_byte_span_t contents
Input bytes.
Definition source.h:142
Non-owning string view over bytes that need not be NUL-terminated.
Definition base.h:63