Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c934fc66e90a
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1fc63a62c04a
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Aug 21, 2019

  1. back.pysim: allow coroutines as processes.

    This is a somewhat obscure use case, but it is possible to use async
    functions with pysim by carefully using @asyncio.coroutine. That is,
    async functions can call back into pysim if they are declared in
    a specific way:
    
      @asyncio.coroutine
      def do_something(self, value):
        yield self.reg.eq(value)
    
    which may then be called from elsewhere with:
    
      async def test_case(self):
        await do_something(0x1234)
    
    This approach is unfortunately limited in that async functions
    cannot yield directly. It should likely be improved by using async
    generators, but supporting coroutines in pysim is unobtrustive and
    allows existing code that made use of this feature in oMigen to work.
    whitequark committed Aug 21, 2019
    Copy the full SHA
    1fc63a6 View commit details
Showing with 5 additions and 2 deletions.
  1. +5 −2 nmigen/back/pysim.py
7 changes: 5 additions & 2 deletions nmigen/back/pysim.py
Original file line number Diff line number Diff line change
@@ -402,7 +402,7 @@ def __init__(self, fragment, vcd_file=None, gtkw_file=None, traces=()):
def _check_process(process):
if inspect.isgeneratorfunction(process):
process = process()
if not inspect.isgenerator(process):
if not (inspect.isgenerator(process) or inspect.iscoroutine(process)):
raise TypeError("Cannot add a process '{!r}' because it is not a generator or "
"a generator function"
.format(process))
@@ -412,7 +412,10 @@ def _name_process(self, process):
if process in self._process_loc:
return self._process_loc[process]
else:
frame = process.gi_frame
if inspect.isgenerator(process):
frame = process.gi_frame
if inspect.iscoroutine(process):
frame = process.cr_frame
return "{}:{}".format(inspect.getfile(frame), inspect.getlineno(frame))

def add_process(self, process):