Skip to content

features

Classes:

Functions:

ExternalSymbolSpec dataclass

ExternalSymbolSpec(
    name: str, declare: RuntimeSymbolFactory
)

NativeArtifact dataclass

NativeArtifact(
    kind: NativeArtifactKind,
    path: Path,
    include_dirs: tuple[Path, ...] = (),
    compile_flags: tuple[str, ...] = (),
    link_flags: tuple[str, ...] = (),
)

RuntimeFeature dataclass

RuntimeFeature(
    name: str,
    symbols: Mapping[str, ExternalSymbolSpec] = dict(),
    artifacts: tuple[NativeArtifact, ...] = (),
    linker_flags: tuple[str, ...] = (),
    metadata: Mapping[str, object] = dict(),
)

declare_external_function

declare_external_function(
    module: Module, name: str, fn_type: FunctionType
) -> Function
Source code in src/irx/runtime/features.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def declare_external_function(
    module: ir.Module, name: str, fn_type: ir.FunctionType
) -> ir.Function:
    """
    title: Declare or reuse an external function in an LLVM module.
    parameters:
      module:
        type: ir.Module
      name:
        type: str
      fn_type:
        type: ir.FunctionType
    returns:
      type: ir.Function
    """
    existing = module.globals.get(name)
    if existing is not None:
        if not isinstance(existing, ir.Function):
            raise TypeError(f"Global '{name}' is not a function")
        if existing.function_type != fn_type:
            raise TypeError(
                f"Function '{name}' already exists with a mismatch"
            )
        return cast(ir.Function, existing)

    fn = ir.Function(module, fn_type, name=name)
    fn.linkage = "external"
    return fn