From 1cabcb3c3fce5c7bd0baa2c6b9075c1b35124892 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 17 Nov 2012 19:59:22 +0100 Subject: [PATCH] uio: support generator trampolining in simulation --- migen/uio/ioo.py | 3 ++- migen/uio/trampoline.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 migen/uio/trampoline.py diff --git a/migen/uio/ioo.py b/migen/uio/ioo.py index 72dbb391..c95c60ce 100644 --- a/migen/uio/ioo.py +++ b/migen/uio/ioo.py @@ -1,6 +1,7 @@ from migen.fhdl.structure import * from migen.flow.actor import * from migen.bus import wishbone +from migen.uio.trampoline import Trampoline class UnifiedIOObject(Actor): def __init__(self, dataflow=None, buses={}): @@ -12,7 +13,7 @@ class UnifiedIOObject(Actor): class UnifiedIOSimulation(UnifiedIOObject): def __init__(self, generator, dataflow=None, buses={}): - self.generator = generator + self.generator = Trampoline(generator) super().__init__(dataflow, buses) self.callers = [] diff --git a/migen/uio/trampoline.py b/migen/uio/trampoline.py new file mode 100644 index 00000000..912427de --- /dev/null +++ b/migen/uio/trampoline.py @@ -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 -- 2.30.2