Skip to content

Commit f637530

Browse files
committed
sim: move Command from core to _pycoro.
Simulator commands are deprecated and will be removed once RFC 36 is implemented and released. They are an artifact of the old API.
1 parent 78a289e commit f637530

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

amaranth/sim/_pycoro.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,61 @@
11
import inspect
22

3+
from .._utils import deprecated
34
from ..hdl import *
45
from ..hdl._ast import Statement, Assign, SignalSet, ValueCastable
5-
from .core import Tick, Settle, Delay, Passive, Active
66
from ._base import BaseProcess, BaseMemoryState
77
from ._pyeval import eval_value, eval_assign
88

99

10-
__all__ = ["PyCoroProcess"]
10+
__all__ = ["Command", "Settle", "Delay", "Tick", "Passive", "Active", "PyCoroProcess"]
11+
12+
13+
class Command:
14+
pass
15+
16+
17+
class Settle(Command):
18+
@deprecated("The `Settle` command is deprecated per RFC 27. Use `add_testbench` to write "
19+
"testbenches; in them, an equivalent of `yield Settle()` is performed "
20+
"automatically.")
21+
def __init__(self):
22+
pass
23+
24+
def __repr__(self):
25+
return "(settle)"
26+
27+
28+
class Delay(Command):
29+
def __init__(self, interval=None):
30+
self.interval = None if interval is None else float(interval)
31+
32+
def __repr__(self):
33+
if self.interval is None:
34+
return "(delay ε)"
35+
else:
36+
return f"(delay {self.interval * 1e6:.3}us)"
37+
38+
39+
class Tick(Command):
40+
def __init__(self, domain="sync"):
41+
if not isinstance(domain, (str, ClockDomain)):
42+
raise TypeError("Domain must be a string or a ClockDomain instance, not {!r}"
43+
.format(domain))
44+
assert domain != "comb"
45+
self.domain = domain
46+
47+
def __repr__(self):
48+
return f"(tick {self.domain})"
49+
50+
51+
class Passive(Command):
52+
def __repr__(self):
53+
return "(passive)"
54+
55+
56+
class Active(Command):
57+
def __repr__(self):
58+
return "(active)"
1159

1260

1361
class PyCoroProcess(BaseProcess):

amaranth/sim/core.py

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,12 @@
77
from ..hdl._ast import Value, ValueLike
88
from ..hdl._mem import MemoryData
99
from ._base import BaseEngine
10+
from ._pycoro import Tick, Settle, Delay, Passive, Active
1011

1112

1213
__all__ = ["Settle", "Delay", "Tick", "Passive", "Active", "Simulator"]
1314

1415

15-
class Command:
16-
pass
17-
18-
19-
class Settle(Command):
20-
@deprecated("The `Settle` command is deprecated per RFC 27. Use `add_testbench` to write "
21-
"testbenches; in them, an equivalent of `yield Settle()` is performed "
22-
"automatically.")
23-
def __init__(self):
24-
pass
25-
26-
def __repr__(self):
27-
return "(settle)"
28-
29-
30-
class Delay(Command):
31-
def __init__(self, interval=None):
32-
self.interval = None if interval is None else float(interval)
33-
34-
def __repr__(self):
35-
if self.interval is None:
36-
return "(delay ε)"
37-
else:
38-
return f"(delay {self.interval * 1e6:.3}us)"
39-
40-
41-
class Tick(Command):
42-
def __init__(self, domain="sync"):
43-
if not isinstance(domain, (str, ClockDomain)):
44-
raise TypeError("Domain must be a string or a ClockDomain instance, not {!r}"
45-
.format(domain))
46-
assert domain != "comb"
47-
self.domain = domain
48-
49-
def __repr__(self):
50-
return f"(tick {self.domain})"
51-
52-
53-
class Passive(Command):
54-
def __repr__(self):
55-
return "(passive)"
56-
57-
58-
class Active(Command):
59-
def __repr__(self):
60-
return "(active)"
61-
62-
6316
class Simulator:
6417
def __init__(self, fragment, *, engine="pysim"):
6518
if isinstance(engine, type) and issubclass(engine, BaseEngine):

0 commit comments

Comments
 (0)