diff --git a/amaranth/sim/_pycoro.py b/amaranth/sim/_pycoro.py index 63df6ec..503984d 100644 --- a/amaranth/sim/_pycoro.py +++ b/amaranth/sim/_pycoro.py @@ -1,13 +1,61 @@ import inspect +from .._utils import deprecated from ..hdl import * from ..hdl._ast import Statement, Assign, SignalSet, ValueCastable -from .core import Tick, Settle, Delay, Passive, Active from ._base import BaseProcess, BaseMemoryState from ._pyeval import eval_value, eval_assign -__all__ = ["PyCoroProcess"] +__all__ = ["Command", "Settle", "Delay", "Tick", "Passive", "Active", "PyCoroProcess"] + + +class Command: + pass + + +class Settle(Command): + @deprecated("The `Settle` command is deprecated per RFC 27. Use `add_testbench` to write " + "testbenches; in them, an equivalent of `yield Settle()` is performed " + "automatically.") + def __init__(self): + pass + + def __repr__(self): + return "(settle)" + + +class Delay(Command): + def __init__(self, interval=None): + self.interval = None if interval is None else float(interval) + + def __repr__(self): + if self.interval is None: + return "(delay ε)" + else: + return f"(delay {self.interval * 1e6:.3}us)" + + +class Tick(Command): + def __init__(self, domain="sync"): + if not isinstance(domain, (str, ClockDomain)): + raise TypeError("Domain must be a string or a ClockDomain instance, not {!r}" + .format(domain)) + assert domain != "comb" + self.domain = domain + + def __repr__(self): + return f"(tick {self.domain})" + + +class Passive(Command): + def __repr__(self): + return "(passive)" + + +class Active(Command): + def __repr__(self): + return "(active)" class PyCoroProcess(BaseProcess): diff --git a/amaranth/sim/core.py b/amaranth/sim/core.py index 936cd5f..f6e05af 100644 --- a/amaranth/sim/core.py +++ b/amaranth/sim/core.py @@ -7,59 +7,12 @@ from ..hdl._ir import * from ..hdl._ast import Value, ValueLike from ..hdl._mem import MemoryData from ._base import BaseEngine +from ._pycoro import Tick, Settle, Delay, Passive, Active __all__ = ["Settle", "Delay", "Tick", "Passive", "Active", "Simulator"] -class Command: - pass - - -class Settle(Command): - @deprecated("The `Settle` command is deprecated per RFC 27. Use `add_testbench` to write " - "testbenches; in them, an equivalent of `yield Settle()` is performed " - "automatically.") - def __init__(self): - pass - - def __repr__(self): - return "(settle)" - - -class Delay(Command): - def __init__(self, interval=None): - self.interval = None if interval is None else float(interval) - - def __repr__(self): - if self.interval is None: - return "(delay ε)" - else: - return f"(delay {self.interval * 1e6:.3}us)" - - -class Tick(Command): - def __init__(self, domain="sync"): - if not isinstance(domain, (str, ClockDomain)): - raise TypeError("Domain must be a string or a ClockDomain instance, not {!r}" - .format(domain)) - assert domain != "comb" - self.domain = domain - - def __repr__(self): - return f"(tick {self.domain})" - - -class Passive(Command): - def __repr__(self): - return "(passive)" - - -class Active(Command): - def __repr__(self): - return "(active)" - - class Simulator: def __init__(self, fragment, *, engine="pysim"): if isinstance(engine, type) and issubclass(engine, BaseEngine):