dan-fritchman / Hdl21

Hardware Description Library
BSD 3-Clause "New" or "Revised" License
69 stars 16 forks source link

Unelaborated `GeneratorCall` as testbench #191

Closed dan-fritchman closed 1 year ago

dan-fritchman commented 1 year ago

This here:

https://github.com/dan-fritchman/Hdl21/blob/edc6bb0a52cd779038ce2511cadcab116ab4c20f/hdl21/sim/data.py#L42


def is_tb(i: Instantiable) -> bool:
    """Boolean indication of whether Instantiable `m` meets the test-bench interface."""
    if isinstance(i, (Module, ExternalModuleCall)):
        m = i
    elif isinstance(i, GeneratorCall):
        m = i.result
    else:
        raise TypeError(f"Invalid un-instantiable argument {i} to `is_tb`")

    if len(m.ports) != 1:
        return False

    # There's exactly one port. Retrieve it from the `ports` dict,
    # first requiring getting its name from the `keys`.
    port = m.ports[list(m.ports.keys())[0]]

    # While that port is *conventionally* called "VSS", it *can* be called anything.
    # The testbench interface is met so long as we have a single, scalar port.
    return port.width == 1

Fails if the argument is a GeneratorCall, but has not yet been run. I.e. i.result is None.

dan-fritchman commented 1 year ago

This would go away if #194 / #196 sticks.

dan-fritchman commented 1 year ago

Closed via #196