uio: support generator trampolining in simulation
This commit is contained in:
parent
be68ecfc72
commit
1cabcb3c3f
|
@ -1,6 +1,7 @@
|
||||||
from migen.fhdl.structure import *
|
from migen.fhdl.structure import *
|
||||||
from migen.flow.actor import *
|
from migen.flow.actor import *
|
||||||
from migen.bus import wishbone
|
from migen.bus import wishbone
|
||||||
|
from migen.uio.trampoline import Trampoline
|
||||||
|
|
||||||
class UnifiedIOObject(Actor):
|
class UnifiedIOObject(Actor):
|
||||||
def __init__(self, dataflow=None, buses={}):
|
def __init__(self, dataflow=None, buses={}):
|
||||||
|
@ -12,7 +13,7 @@ class UnifiedIOObject(Actor):
|
||||||
|
|
||||||
class UnifiedIOSimulation(UnifiedIOObject):
|
class UnifiedIOSimulation(UnifiedIOObject):
|
||||||
def __init__(self, generator, dataflow=None, buses={}):
|
def __init__(self, generator, dataflow=None, buses={}):
|
||||||
self.generator = generator
|
self.generator = Trampoline(generator)
|
||||||
super().__init__(dataflow, buses)
|
super().__init__(dataflow, buses)
|
||||||
|
|
||||||
self.callers = []
|
self.callers = []
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
import types
|
||||||
|
|
||||||
|
class Trampoline:
|
||||||
|
def __init__(self, g):
|
||||||
|
self.stack = [g]
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
while True:
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
r = next(self.stack[-1])
|
||||||
|
break
|
||||||
|
except StopIteration:
|
||||||
|
self.stack.pop()
|
||||||
|
if not self.stack:
|
||||||
|
raise
|
||||||
|
if isinstance(r, types.GeneratorType):
|
||||||
|
self.stack.append(r)
|
||||||
|
else:
|
||||||
|
return r
|
Loading…
Reference in New Issue