back.pysim: extract simulator commands to sim._cmds. NFC.
[nmigen.git] / nmigen / sim / _cmds.py
1 from ..hdl.cd import *
2
3
4 __all__ = ["Settle", "Delay", "Tick", "Passive", "Active"]
5
6
7 class Command:
8 pass
9
10
11 class Settle(Command):
12 def __repr__(self):
13 return "(settle)"
14
15
16 class Delay(Command):
17 def __init__(self, interval=None):
18 self.interval = None if interval is None else float(interval)
19
20 def __repr__(self):
21 if self.interval is None:
22 return "(delay ε)"
23 else:
24 return "(delay {:.3}us)".format(self.interval * 1e6)
25
26
27 class Tick(Command):
28 def __init__(self, domain="sync"):
29 if not isinstance(domain, (str, ClockDomain)):
30 raise TypeError("Domain must be a string or a ClockDomain instance, not {!r}"
31 .format(domain))
32 assert domain != "comb"
33 self.domain = domain
34
35 def __repr__(self):
36 return "(tick {})".format(self.domain)
37
38
39 class Passive(Command):
40 def __repr__(self):
41 return "(passive)"
42
43
44 class Active(Command):
45 def __repr__(self):
46 return "(active)"