Loom C API
Public Loom compiler C API
Loading...
Searching...
No Matches
artifact.h File Reference

In-memory output artifacts produced by compiler operations. More...

Go to the source code of this file.

Data Structures

struct  loomc_artifact_t
 Borrowed artifact view owned by a result object. More...

Macros

#define LOOMC_ARTIFACT_FORMAT_LOOM_TEXT   "loom-text"
 Textual Loom module artifact format.
#define LOOMC_ARTIFACT_FORMAT_LOOM_BYTECODE   "loombc"
 Binary Loom bytecode module artifact format.
#define LOOMC_ARTIFACT_FORMAT_JSON   "json"
 JSON report artifact format.

Typedefs

typedef void(* loomc_artifact_release_fn_t) (void *user_data, loomc_byte_span_t contents)
 Callback used to release artifact contents transferred to a consumer.

Enumerations

enum  loomc_artifact_kind_t {
  LOOMC_ARTIFACT_KIND_EXECUTABLE = 0 , LOOMC_ARTIFACT_KIND_TEXT = 1 , LOOMC_ARTIFACT_KIND_REPORT = 2 , LOOMC_ARTIFACT_KIND_MODULE = 3 ,
  LOOMC_ARTIFACT_KIND_LAUNCH_CONFIG = 4
}
 Artifact category. More...

Functions

loomc_status_t loomc_artifact_create_source (const loomc_artifact_t *artifact, loomc_source_format_t format, loomc_allocator_t allocator, loomc_source_t **out_source)
 Creates an immutable source handle from an artifact.
loomc_status_t loomc_artifact_write_to_file (const loomc_artifact_t *artifact, FILE *file)
 Writes artifact bytes to an open C FILE*.
loomc_status_t loomc_artifact_write_to_path (const loomc_artifact_t *artifact, loomc_string_view_t path, loomc_allocator_t allocator)
 Writes artifact bytes to a filesystem path.

Detailed Description

In-memory output artifacts produced by compiler operations.

Artifacts are structured objects, not filesystem side effects. They carry format, identity, and bytes so language bindings can expose native byte arrays or typed artifact objects.

Filesystem persistence is explicit and composable. JIT integrations can keep artifact bytes in memory for loading or cache lookup, while tools and release builds can write the same artifact object to a FILE* or path.

Example
Save the first executable artifact from a result:
++i) {
const loomc_artifact_t* artifact = loomc_result_artifact_at(result, i);
if (artifact->kind != LOOMC_ARTIFACT_KIND_EXECUTABLE) continue;
artifact, loomc_make_cstring_view("kernel.vmfb"),
}
@ LOOMC_ARTIFACT_KIND_EXECUTABLE
Executable or loadable binary artifact.
Definition artifact.h:55
loomc_status_t loomc_artifact_write_to_path(const loomc_artifact_t *artifact, loomc_string_view_t path, loomc_allocator_t allocator)
Writes artifact bytes to a filesystem path.
loomc_allocator_t loomc_allocator_system(void)
Returns a process-global system allocator.
size_t loomc_host_size_t
Host allocation and container size type.
Definition base.h:45
const loomc_artifact_t * loomc_result_artifact_at(const loomc_result_t *result, loomc_host_size_t index)
Returns an artifact by index.
loomc_host_size_t loomc_result_artifact_count(const loomc_result_t *result)
Returns the number of artifacts attached to result.
Borrowed artifact view owned by a result object.
Definition artifact.h:75
loomc_artifact_kind_t kind
Artifact kind.
Definition artifact.h:77

Typedef Documentation

◆ loomc_artifact_release_fn_t

typedef void(* loomc_artifact_release_fn_t) (void *user_data, loomc_byte_span_t contents)

Callback used to release artifact contents transferred to a consumer.

Parameters
user_dataCaller-provided value passed to the consuming operation.
contentsOriginal artifact contents transferred to the consumer.

The consuming operation documents when the callback runs. The callback is invoked exactly once after that operation accepts ownership of the bytes.

Enumeration Type Documentation

◆ loomc_artifact_kind_t

Artifact category.

Enumerator
LOOMC_ARTIFACT_KIND_EXECUTABLE 

Executable or loadable binary artifact.

LOOMC_ARTIFACT_KIND_TEXT 

Human-readable textual artifact.

LOOMC_ARTIFACT_KIND_REPORT 

Machine-readable report artifact.

LOOMC_ARTIFACT_KIND_MODULE 

Loom module artifact. The format indicates text or bytecode.

LOOMC_ARTIFACT_KIND_LAUNCH_CONFIG 

Compiled kernel launch-configuration program.

Function Documentation

◆ loomc_artifact_create_source()

loomc_status_t loomc_artifact_create_source ( const loomc_artifact_t * artifact,
loomc_source_format_t format,
loomc_allocator_t allocator,
loomc_source_t ** out_source )

Creates an immutable source handle from an artifact.

Parameters
artifactArtifact whose bytes should become source contents.
formatSource format for the returned handle. Unknown infers Loom text and bytecode from well-known Loom artifact format strings and leaves other artifact formats unknown.
allocatorHost allocator used for source-owned storage.
out_sourceReceives one retained source on success.
Returns
OK when the source was created.
Ownership
The returned source owns a copy of the artifact bytes and identifier. The caller releases it with loomc_source_release.

◆ loomc_artifact_write_to_file()

loomc_status_t loomc_artifact_write_to_file ( const loomc_artifact_t * artifact,
FILE * file )

Writes artifact bytes to an open C FILE*.

Parameters
artifactArtifact to write.
fileOpen writable file handle, such as stdout.
Returns
OK when all artifact bytes were written.
Ownership
The caller retains ownership of file; this function does not close it.

◆ loomc_artifact_write_to_path()

loomc_status_t loomc_artifact_write_to_path ( const loomc_artifact_t * artifact,
loomc_string_view_t path,
loomc_allocator_t allocator )

Writes artifact bytes to a filesystem path.

Parameters
artifactArtifact to write.
pathOutput file path. The path is a borrowed byte view and does not need to be NUL-terminated.
allocatorHost allocator used for transient file path/stream storage.
Returns
OK when all artifact bytes were written.