chipflow.utils

Core utility functions for ChipFlow

This module provides core utilities used throughout the chipflow library.

Exceptions

ChipFlowError

Base exception for ChipFlow errors

Functions

get_cls_by_reference(reference, context)

Dynamically import and return a class by its module:class reference string.

ensure_chipflow_root()

Ensure CHIPFLOW_ROOT environment variable is set and return its path.

get_src_loc([src_loc_at])

Get the source location (filename, line number) of the caller.

compute_invert_mask(invert_list)

Compute a bit mask for signal inversion from a list of boolean invert flags.

top_components(config)

Return the top level components for the design, as configured in chipflow.toml.

get_software_builds(m, component)

Extract software build information from a component's interfaces.

Module Contents

exception chipflow.utils.ChipFlowError

Bases: Exception

Base exception for ChipFlow errors

chipflow.utils.get_cls_by_reference(reference, context)

Dynamically import and return a class by its module:class reference string.

Parameters:
  • reference (str) – String in format “module.path:ClassName”

  • context (str) – Description of where this reference came from (for error messages)

Returns:

The class object

Raises:

ChipFlowError – If module or class cannot be found

chipflow.utils.ensure_chipflow_root()

Ensure CHIPFLOW_ROOT environment variable is set and return its path.

If CHIPFLOW_ROOT is not set, sets it to the current working directory. Also ensures the root is in sys.path.

Returns:

Path to the chipflow root directory

Return type:

pathlib.Path

chipflow.utils.get_src_loc(src_loc_at=0)

Get the source location (filename, line number) of the caller.

Parameters:

src_loc_at (int) – Number of frames to go back (0 = immediate caller)

Returns:

Tuple of (filename, line_number)

chipflow.utils.compute_invert_mask(invert_list)

Compute a bit mask for signal inversion from a list of boolean invert flags.

Parameters:

invert_list – List of booleans indicating which bits should be inverted

Returns:

Integer mask where set bits indicate positions to invert

chipflow.utils.top_components(config)

Return the top level components for the design, as configured in chipflow.toml.

Parameters:

config (chipflow.config.models.Config) – The parsed chipflow configuration

Returns:

Dictionary mapping component names to instantiated Component objects

Raises:

ChipFlowError – If component references are invalid or instantiation fails

Return type:

Dict[str, amaranth.lib.wiring.Component]

chipflow.utils.get_software_builds(m, component)

Extract software build information from a component’s interfaces.

Parameters:
  • m – Module containing the component

  • component (str) – Name of the component

Returns:

Dictionary of interface names to SoftwareBuild objects