back.pysim: allow coroutines as processes.
authorwhitequark <cz@m-labs.hk>
Wed, 21 Aug 2019 03:28:48 +0000 (03:28 +0000)
committerwhitequark <cz@m-labs.hk>
Wed, 21 Aug 2019 03:30:37 +0000 (03:30 +0000)
commit19e91faad053f9fa24090ca9fde3923553d1c0fb
tree9032f66cc936e3c9ee35f2cbe3f48a7ca3b07027
parent352d5fc6e81c63ceedbe8a22cdd4ed952cc63190
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.
nmigen/back/pysim.py