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

Reusable Loom API context. More...

Go to the source code of this file.

Data Structures

struct  loomc_context_options_t
 Context creation options. More...

Typedefs

typedef struct loomc_context_t loomc_context_t
 Immutable Loom API context.

Enumerations

enum  loomc_source_retention_t { LOOMC_SOURCE_RETENTION_EXACT = 0 , LOOMC_SOURCE_RETENTION_METADATA_ONLY = 1 }
 Retention policy for source contents used to enrich diagnostics. More...

Functions

loomc_status_t loomc_context_create (const loomc_context_options_t *options, loomc_allocator_t allocator, loomc_context_t **out_context)
 Creates a reusable Loom API context.
void loomc_context_retain (loomc_context_t *context)
 Retains context for another owner.
void loomc_context_release (loomc_context_t *context)
 Releases context from one owner.

Detailed Description

Reusable Loom API context.

A context owns process-local Loom language registration state used by parsing, bytecode indexing, linking, and compilation. Embedders normally create one context for a process or toolchain instance and share it with prepared linkers, compilers, and link-index builders.

Example
Create a context once, then reuse it while building persistent indexes:
loomc_context_t* context = NULL;
if (!loomc_status_is_ok(status)) {
return status;
}
// Use context to create link-index builders, linkers, and compilers.
loomc_allocator_t loomc_allocator_system(void)
Returns a process-global system allocator.
struct iree_status_handle_t * loomc_status_t
Opaque status handle.
Definition base.h:55
struct loomc_context_t loomc_context_t
Immutable Loom API context.
Definition context.h:63
loomc_status_t loomc_context_create(const loomc_context_options_t *options, loomc_allocator_t allocator, loomc_context_t **out_context)
Creates a reusable Loom API context.
void loomc_context_release(loomc_context_t *context)
Releases context from one owner.
Metadata-only source retention
Long-lived compilers that report structured diagnostics without rendering source excerpts can omit authored source bytes from retained modules and results:
.structure_size = sizeof(loomc_context_options_t),
};
loomc_context_t* context = NULL;
&options, loomc_allocator_system(), &context);
@ LOOMC_STRUCTURE_TYPE_CONTEXT_OPTIONS
loomc_context_options_t.
Definition base.h:192
@ LOOMC_SOURCE_RETENTION_METADATA_ONLY
Retain source identifiers and available coordinates without source contents.
Definition context.h:74
Context creation options.
Definition context.h:82

Typedef Documentation

◆ loomc_context_t

Immutable Loom API context.

Thread safety
Contexts are immutable after creation and may be shared across threads. Operations that need mutable source-location tables serialize that mutation through their owning builder or invocation object rather than exposing it on the context API.

Enumeration Type Documentation

◆ loomc_source_retention_t

Retention policy for source contents used to enrich diagnostics.

Enumerator
LOOMC_SOURCE_RETENTION_EXACT 

Retain exact source contents referenced by admitted IR.

This is the default and allows later compiler diagnostics to render source excerpts.

LOOMC_SOURCE_RETENTION_METADATA_ONLY 

Retain source identifiers and available coordinates without source contents.

Structured diagnostics remain available without keeping authored files live with modules, results, or text link indexes.

Function Documentation

◆ loomc_context_create()

loomc_status_t loomc_context_create ( const loomc_context_options_t * options,
loomc_allocator_t allocator,
loomc_context_t ** out_context )

Creates a reusable Loom API context.

Parameters
optionsContext options, or NULL for defaults.
allocatorHost allocator used for context-owned storage.
out_contextReceives one retained context on success.
Returns
OK when the context was created.
Ownership
The caller owns the returned reference and releases it with loomc_context_release.
Thread safety
The returned context is immutable and may be shared across prepared tools and worker threads.

◆ loomc_context_release()

void loomc_context_release ( loomc_context_t * context)

Releases context from one owner.

Parameters
contextContext to release. Passing NULL is allowed.
Thread safety
Retain/release operations are safe to perform from multiple threads. The context is destroyed when the final reference is released.

◆ loomc_context_retain()

void loomc_context_retain ( loomc_context_t * context)

Retains context for another owner.

Parameters
contextContext to retain.
Thread safety
Retain/release operations are safe to perform from multiple threads.