Skip to content

gds_software.component.compile

Compiler: ComponentModel -> GDSSpec / SystemIR.

Public Functions

Compile a ComponentModel into a GDSSpec.

Source code in packages/gds-software/gds_software/component/compile.py
def compile_component(model: ComponentModel) -> GDSSpec:
    """Compile a ComponentModel into a GDSSpec."""
    spec = GDSSpec(name=model.name, description=model.description)

    # 1. Register types
    spec.collect(ComponentDataType, ComponentStateType)

    # 2. Register spaces
    spec.collect(ComponentDataSpace, ComponentStateSpace)

    # 3. Register entities for stateful components
    for comp in model.components:
        if comp.stateful:
            spec.register_entity(_build_component_entity(comp))

    # 4. Register blocks
    for comp in model.components:
        spec.register_block(_build_component_block(comp, model))

    # 5. Register spec wirings
    all_block_names = [b.name for b in spec.blocks.values()]
    wires: list[Wire] = []

    for conn in model.connectors:
        wires.append(
            Wire(
                source=conn.source,
                target=conn.target,
                space="CP DataSpace",
            )
        )

    spec.register_wiring(
        SpecWiring(
            name=f"{model.name} Wiring",
            block_names=all_block_names,
            wires=wires,
            description=f"Auto-generated wiring for component diagram {model.name!r}",
        )
    )

    return spec

Compile a ComponentModel directly to SystemIR.

Source code in packages/gds-software/gds_software/component/compile.py
def compile_component_to_system(model: ComponentModel) -> SystemIR:
    """Compile a ComponentModel directly to SystemIR."""
    root = _build_composition_tree(model)
    return compile_system(model.name, root)