chipflow.sim.cxxrtl

CXXRTL C API bindings via ctypes.

This module provides Python bindings for the CXXRTL simulation engine, allowing fast compiled simulation of HDL designs with Python testbenches.

Classes

CxxrtlObject

CXXRTL object descriptor - matches struct cxxrtl_object in cxxrtl_capi.h

CxxrtlSimulator

Python wrapper for CXXRTL simulation.

Module Contents

class chipflow.sim.cxxrtl.CxxrtlObject

Bases: ctypes.Structure

CXXRTL object descriptor - matches struct cxxrtl_object in cxxrtl_capi.h

class chipflow.sim.cxxrtl.CxxrtlSimulator(library_path, top_module)

Python wrapper for CXXRTL simulation.

This class provides a Pythonic interface to CXXRTL compiled simulations, supporting signal access, stepping, and VCD tracing.

Example:

sim = CxxrtlSimulator("build/design.so", "design")
sim.reset()

# Clock cycle
sim.set("clk", 0)
sim.step()
sim.set("clk", 1)
sim.step()

# Read output
value = sim.get("data_out")
Parameters:
reset()

Reset the simulation to initial state.

Return type:

None

eval()

Evaluate combinatorial logic.

Returns:

True if the design converged immediately

Return type:

bool

commit()

Commit sequential state.

Returns:

True if any state changed

Return type:

bool

step()

Simulate to a fixed point (eval + commit until stable).

Returns:

Number of delta cycles

Return type:

int

get(name)

Get the current value of a signal.

Parameters:

name (str) – Signal name (e.g., “i_clk” or “o_data”)

Returns:

Current value as an integer

Return type:

int

set(name, value)

Set the next value of a signal.

Parameters:
  • name (str) – Hierarchical signal name

  • value (int) – Value to set

Return type:

None

signals()

Iterate over all signals in the design.

Yields:

Tuples of (name, object) for each signal

Return type:

Iterator[Tuple[str, CxxrtlObject]]

inputs()

Iterate over input signals.

Return type:

Iterator[Tuple[str, CxxrtlObject]]

outputs()

Iterate over output signals.

Return type:

Iterator[Tuple[str, CxxrtlObject]]

close()

Release simulation resources.

Return type:

None