From c03e0e6a22bcc68f0cdeb6969cb42b463ef25b5c Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 8 Jul 2020 05:42:33 +0000 Subject: [PATCH] back.pysim: extract simulator commands to sim._cmds. NFC. --- nmigen/back/pysim.py | 42 ++------------------------------------ nmigen/sim/__init__.py | 0 nmigen/sim/_cmds.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 nmigen/sim/__init__.py create mode 100644 nmigen/sim/_cmds.py diff --git a/nmigen/back/pysim.py b/nmigen/back/pysim.py index a9c6c16..f3c1fec 100644 --- a/nmigen/back/pysim.py +++ b/nmigen/back/pysim.py @@ -12,48 +12,10 @@ from ..hdl.ast import * from ..hdl.cd import * from ..hdl.ir import * from ..hdl.xfrm import ValueVisitor, StatementVisitor, LHSGroupFilter +from ..sim._cmds import * -class Command: - pass - - -class Settle(Command): - 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 "(delay {:.3}us)".format(self.interval * 1e6) - - -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 "(tick {})".format(self.domain) - - -class Passive(Command): - def __repr__(self): - return "(passive)" - - -class Active(Command): - def __repr__(self): - return "(active)" +__all__ = ["Settle", "Delay", "Tick", "Passive", "Active", "Simulator"] class _WaveformWriter: diff --git a/nmigen/sim/__init__.py b/nmigen/sim/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nmigen/sim/_cmds.py b/nmigen/sim/_cmds.py new file mode 100644 index 0000000..a1cea3e --- /dev/null +++ b/nmigen/sim/_cmds.py @@ -0,0 +1,46 @@ +from ..hdl.cd import * + + +__all__ = ["Settle", "Delay", "Tick", "Passive", "Active"] + + +class Command: + pass + + +class Settle(Command): + 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 "(delay {:.3}us)".format(self.interval * 1e6) + + +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 "(tick {})".format(self.domain) + + +class Passive(Command): + def __repr__(self): + return "(passive)" + + +class Active(Command): + def __repr__(self): + return "(active)" -- 2.30.2