@@ -35,14 +35,15 @@ def __init__(self, fragment, *, engine="pysim"):
35
35
self ._engine = engine (self ._design )
36
36
self ._clocked = set ()
37
37
38
- def _check_process (self , process ):
39
- if not (inspect .isgeneratorfunction (process ) or inspect .iscoroutinefunction (process )):
40
- raise TypeError ("Cannot add a process {!r} because it is not a generator function"
41
- .format (process ))
42
- return process
38
+ def _check_function (self , function , * , kind ):
39
+ if not (inspect .isgeneratorfunction (function ) or inspect .iscoroutinefunction (function )):
40
+ raise TypeError (
41
+ f"Cannot add a { kind } { function !r} because it is not an async function or "
42
+ f"generator function" )
43
+ return function
43
44
44
45
def add_process (self , process ):
45
- process = self ._check_process (process )
46
+ process = self ._check_function (process , kind = "process" )
46
47
if inspect .iscoroutinefunction (process ):
47
48
self ._engine .add_async_process (self , process )
48
49
else :
@@ -54,16 +55,17 @@ def wrapper():
54
55
wrap_process = coro_wrapper (wrapper , testbench = False )
55
56
self ._engine .add_async_process (self , wrap_process )
56
57
57
- def add_testbench (self , process , * , background = False ):
58
- if inspect .iscoroutinefunction (process ):
59
- self ._engine .add_async_testbench (self , process , background = background )
58
+ def add_testbench (self , testbench , * , background = False ):
59
+ testbench = self ._check_function (testbench , kind = "testbench" )
60
+ if inspect .iscoroutinefunction (testbench ):
61
+ self ._engine .add_async_testbench (self , testbench , background = background )
60
62
else :
61
- process = coro_wrapper (process , testbench = True )
62
- self ._engine .add_async_testbench (self , process , background = background )
63
+ testbench = coro_wrapper (testbench , testbench = True )
64
+ self ._engine .add_async_testbench (self , testbench , background = background )
63
65
64
66
@deprecated ("The `add_sync_process` method is deprecated per RFC 27. Use `add_process` or `add_testbench` instead." )
65
67
def add_sync_process (self , process , * , domain = "sync" ):
66
- process = self ._check_process (process )
68
+ process = self ._check_function (process , kind = "process" )
67
69
def wrapper ():
68
70
# Only start a sync process after the first clock edge (or reset edge, if the domain
69
71
# uses an asynchronous reset). This matches the behavior of synchronous FFs.
0 commit comments