Skip to content

Commit bfbdc2c

Browse files
committed
Implement RFC 27 amendment: deprecate add_sync_process, not add_process.
1 parent ace7aea commit bfbdc2c

File tree

7 files changed

+120
-139
lines changed

7 files changed

+120
-139
lines changed

amaranth/sim/core.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def _check_process(self, process):
8080
.format(process))
8181
return process
8282

83-
@deprecated("The `add_process` method is deprecated per RFC 27. Use `add_testbench` instead.")
8483
def add_process(self, process):
8584
process = self._check_process(process)
8685
def wrapper():
@@ -89,6 +88,7 @@ def wrapper():
8988
yield from process()
9089
self._engine.add_coroutine_process(wrapper, default_cmd=None)
9190

91+
@deprecated("The `add_sync_process` method is deprecated per RFC 47. Use `add_process` or `add_testbench` instead.")
9292
def add_sync_process(self, process, *, domain="sync"):
9393
process = self._check_process(process)
9494
def wrapper():
@@ -107,25 +107,6 @@ def wrapper():
107107
except StopIteration:
108108
break
109109
try:
110-
if isinstance(command, (Settle, Delay, Tick)):
111-
frame = generator.gi_frame
112-
module_globals = frame.f_globals
113-
if '__name__' in module_globals:
114-
module = module_globals['__name__']
115-
else:
116-
module = "<string>"
117-
# If the warning action is "error", this call will throw the warning, and
118-
# the try block will redirect it into the generator.
119-
warnings.warn_explicit(
120-
f"Using `{command.__class__.__name__}` is deprecated within "
121-
f"`add_sync_process` per RFC 27; use `add_testbench` instead.",
122-
DeprecationWarning,
123-
filename=frame.f_code.co_filename,
124-
lineno=frame.f_lineno,
125-
module=module,
126-
registry=module_globals.setdefault("__warningregistry__", {}),
127-
module_globals=module_globals,
128-
)
129110
result = yield command
130111
exception = None
131112
except Exception as e:

docs/changes.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ Apply the following changes to code written against Amaranth 0.4 to migrate it t
2929
* Replace uses of ``Value.matches()`` with no patterns with ``Const(1)``
3030
* Update uses of ``amaranth.utils.log2_int(need_pow2=False)`` to :func:`amaranth.utils.ceil_log2`
3131
* Update uses of ``amaranth.utils.log2_int(need_pow2=True)`` to :func:`amaranth.utils.exact_log2`
32-
* Update uses of ``Simulator.add_process`` to ``Simulator.add_testbench``
3332
* Convert uses of ``Simulator.add_sync_process`` used as testbenches to ``Simulator.add_testbench``
34-
* Convert uses of ``yield Tick()`` within remaining ``Simulator.add_sync_process`` to plain ``yield``
33+
* Convert other uses of ``Simulator.add_sync_process`` to ``Simulator.add_process``
3534

3635

3736
Implemented RFCs
@@ -81,7 +80,7 @@ Toolchain changes
8180

8281
* Added: ``Simulator.add_testbench``. (`RFC 27`_)
8382
* Deprecated: ``Settle`` simulation command. (`RFC 27`_)
84-
* Deprecated: ``Simulator.add_process``. (`RFC 27`_)
83+
* Deprecated: ``Simulator.add_sync_process``. (`RFC 27`_)
8584
* Removed: (deprecated in 0.4) use of mixed-case toolchain environment variable names, such as ``NMIGEN_ENV_Diamond`` or ``AMARANTH_ENV_Diamond``; use upper-case environment variable names, such as ``AMARANTH_ENV_DIAMOND``.
8685

8786

examples/basic/ctr_en.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def elaborate(self, platform):
2323
sim = Simulator(ctr)
2424
sim.add_clock(1e-6)
2525
def ce_proc():
26-
yield; yield; yield
26+
yield Tick(); yield Tick(); yield Tick()
2727
yield ctr.en.eq(1)
28-
yield; yield; yield
28+
yield Tick(); yield Tick(); yield Tick()
2929
yield ctr.en.eq(0)
30-
yield; yield; yield
30+
yield Tick(); yield Tick(); yield Tick()
3131
yield ctr.en.eq(1)
32-
sim.add_sync_process(ce_proc)
32+
sim.add_testbench(ce_proc)
3333
with sim.write_vcd("ctrl.vcd", "ctrl.gtkw", traces=[ctr.en, ctr.v, ctr.o]):
3434
sim.run_until(100e-6, run_passive=True)

tests/test_lib_cdc.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def test_basic(self):
2626
def process():
2727
self.assertEqual((yield o), 0)
2828
yield i.eq(1)
29-
yield
29+
yield Tick()
3030
self.assertEqual((yield o), 0)
31-
yield
31+
yield Tick()
3232
self.assertEqual((yield o), 0)
33-
yield
33+
yield Tick()
3434
self.assertEqual((yield o), 1)
35-
sim.add_sync_process(process)
35+
sim.add_process(process)
3636
sim.run()
3737

3838
def test_reset_value(self):
@@ -45,13 +45,13 @@ def test_reset_value(self):
4545
def process():
4646
self.assertEqual((yield o), 1)
4747
yield i.eq(0)
48-
yield
48+
yield Tick()
4949
self.assertEqual((yield o), 1)
50-
yield
50+
yield Tick()
5151
self.assertEqual((yield o), 1)
52-
yield
52+
yield Tick()
5353
self.assertEqual((yield o), 0)
54-
sim.add_sync_process(process)
54+
sim.add_process(process)
5555
sim.run()
5656

5757

@@ -221,17 +221,17 @@ def process():
221221
yield ps.i.eq(0)
222222
# TODO: think about reset
223223
for n in range(5):
224-
yield
224+
yield Tick()
225225
# Make sure no pulses are generated in quiescent state
226226
for n in range(3):
227-
yield
227+
yield Tick()
228228
self.assertEqual((yield ps.o), 0)
229229
# Check conservation of pulses
230230
accum = 0
231231
for n in range(10):
232232
yield ps.i.eq(1 if n < 4 else 0)
233-
yield
233+
yield Tick()
234234
accum += yield ps.o
235235
self.assertEqual(accum, 4)
236-
sim.add_sync_process(process)
236+
sim.add_process(process)
237237
sim.run()

tests/test_lib_crc.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ def process():
243243
yield crc.start.eq(word == b"1")
244244
yield crc.data.eq(word)
245245
yield crc.valid.eq(1)
246-
yield
246+
yield Tick()
247247
yield crc.valid.eq(0)
248-
yield
248+
yield Tick()
249249
self.assertEqual((yield crc.crc), check)
250250

251251
sim = Simulator(crc)
252-
sim.add_sync_process(process)
252+
sim.add_testbench(process)
253253
sim.add_clock(1e-6)
254254
sim.run()
255255

@@ -283,18 +283,18 @@ def test_crc_words(self):
283283

284284
def process():
285285
yield crc.start.eq(1)
286-
yield
286+
yield Tick()
287287
yield crc.start.eq(0)
288288
for word in words:
289289
yield crc.data.eq(word)
290290
yield crc.valid.eq(1)
291-
yield
291+
yield Tick()
292292
yield crc.valid.eq(0)
293-
yield
293+
yield Tick()
294294
self.assertEqual((yield crc.crc), check)
295295

296296
sim = Simulator(crc)
297-
sim.add_sync_process(process)
297+
sim.add_testbench(process)
298298
sim.add_clock(1e-6)
299299
sim.run()
300300

@@ -334,17 +334,17 @@ def test_crc_match(self):
334334

335335
def process():
336336
yield crc.start.eq(1)
337-
yield
337+
yield Tick()
338338
yield crc.start.eq(0)
339339
for word in words:
340340
yield crc.data.eq(word)
341341
yield crc.valid.eq(1)
342-
yield
342+
yield Tick()
343343
yield crc.valid.eq(0)
344-
yield
344+
yield Tick()
345345
self.assertTrue((yield crc.match_detected))
346346

347347
sim = Simulator(crc)
348-
sim.add_sync_process(process)
348+
sim.add_testbench(process)
349349
sim.add_clock(1e-6)
350350
sim.run()

tests/test_lib_fifo.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def testbench():
296296
for i in range(10):
297297
yield fifo.w_data.eq(i)
298298
yield fifo.w_en.eq(1)
299-
yield
299+
yield Tick()
300300

301301
if (i - ff_syncronizer_latency) > 0:
302302
self.assertEqual((yield fifo.r_level), i - ff_syncronizer_latency)
@@ -305,7 +305,7 @@ def testbench():
305305

306306
simulator = Simulator(fifo)
307307
simulator.add_clock(100e-6)
308-
simulator.add_sync_process(testbench)
308+
simulator.add_process(testbench)
309309
simulator.run()
310310

311311
def check_async_fifo_level(self, fifo, fill_in, expected_level, read=False):
@@ -315,25 +315,24 @@ def write_process():
315315
for i in range(fill_in):
316316
yield fifo.w_data.eq(i)
317317
yield fifo.w_en.eq(1)
318-
yield
318+
yield Tick("write")
319319
yield fifo.w_en.eq(0)
320-
yield
321-
yield
320+
yield Tick ("write")
322321
self.assertEqual((yield fifo.w_level), expected_level)
323322
yield write_done.eq(1)
324323

325324
def read_process():
326325
if read:
327326
yield fifo.r_en.eq(1)
328327
while not (yield write_done):
329-
yield
328+
yield Tick("read")
330329
self.assertEqual((yield fifo.r_level), expected_level)
331330

332331
simulator = Simulator(fifo)
333332
simulator.add_clock(100e-6, domain="write")
334-
simulator.add_sync_process(write_process, domain="write")
333+
simulator.add_testbench(write_process)
335334
simulator.add_clock(50e-6, domain="read")
336-
simulator.add_sync_process(read_process, domain="read")
335+
simulator.add_testbench(read_process)
337336
with simulator.write_vcd("test.vcd"):
338337
simulator.run()
339338

0 commit comments

Comments
 (0)