From dac0d11e5268066c496856b8dec453a24c5e9df7 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 24 Nov 2012 00:00:07 +0100 Subject: [PATCH] actorlib/sim: Dumper --- examples/dataflow/arithmetic.py | 12 +----------- examples/dataflow/fibonacci.py | 12 +----------- examples/pytholite/basic.py | 12 +----------- examples/pytholite/uio.py | 12 +----------- migen/actorlib/sim.py | 14 ++++++++++++++ 5 files changed, 18 insertions(+), 44 deletions(-) diff --git a/examples/dataflow/arithmetic.py b/examples/dataflow/arithmetic.py index bd3e037b..89efa0b1 100644 --- a/examples/dataflow/arithmetic.py +++ b/examples/dataflow/arithmetic.py @@ -18,16 +18,6 @@ class NumberGen(SimActor): super().__init__(number_gen(), ("result", Source, [("r", self.bv_r)])) -class Dumper(SimActor): - def __init__(self): - def dumper_gen(): - while True: - t = Token("result") - yield t - print(t.value["r"]) - super().__init__(dumper_gen(), - ("result", Sink, [("r", BV(32))])) - def draw(g): if len(sys.argv) > 1 and sys.argv[1] == "draw": nx.draw_spectral(g) @@ -42,7 +32,7 @@ def main(): ps = gen1 + gen2 result = ps*gen1 + ps*gen2 - g.add_connection(result, ActorNode(Dumper())) + g.add_connection(result, ActorNode(Dumper([("r", BV(32))]))) gen1.actor.name = "gen1" gen2.actor.name = "gen2" diff --git a/examples/dataflow/fibonacci.py b/examples/dataflow/fibonacci.py index e67728bb..8e1276ee 100644 --- a/examples/dataflow/fibonacci.py +++ b/examples/dataflow/fibonacci.py @@ -31,16 +31,6 @@ class Init(Actor): ] return Fragment(comb, sync) -class Dumper(SimActor): - def __init__(self, nbits): - def dumper_gen(): - while True: - t = Token("result") - yield t - print(t.value["r"]) - super().__init__(dumper_gen(), - ("result", Sink, [("r", BV(nbits))])) - def main(): nbits = 32 @@ -63,7 +53,7 @@ def main(): g.add_connection(init2, buf2) g.add_connection(buf2, adder, sink_subr="b") - g.add_connection(bufadd, ActorNode(Dumper(nbits))) + g.add_connection(bufadd, ActorNode(Dumper([("r", BV(nbits))]))) c = CompositeActor(g) fragment = c.get_fragment() diff --git a/examples/pytholite/basic.py b/examples/pytholite/basic.py index 91688dc0..40c8e962 100644 --- a/examples/pytholite/basic.py +++ b/examples/pytholite/basic.py @@ -11,19 +11,9 @@ def number_gen(): for i in range(10): yield Token("result", {"r": i}) -class Dumper(SimActor): - def __init__(self): - def dumper_gen(): - while True: - t = Token("result") - yield t - print(t.value["r"]) - super().__init__(dumper_gen(), - ("result", Sink, layout)) - def run_sim(ng): g = DataFlowGraph() - d = Dumper() + d = Dumper(layout) g.add_connection(ActorNode(ng), ActorNode(d)) c = CompositeActor(g) diff --git a/examples/pytholite/uio.py b/examples/pytholite/uio.py index a0c5ca3c..0cf5b6eb 100644 --- a/examples/pytholite/uio.py +++ b/examples/pytholite/uio.py @@ -24,23 +24,13 @@ def gen(): ds.store = r.data yield Token("result", {"r": ds}) -class Dumper(SimActor): - def __init__(self): - def dumper_gen(): - while True: - t = Token("result") - yield t - print(t.value["r"]) - super().__init__(dumper_gen(), - ("result", Sink, layout)) - class SlaveModel(wishbone.TargetModel): def read(self, address): return address + 4 def run_sim(ng): g = DataFlowGraph() - d = Dumper() + d = Dumper(layout) g.add_connection(ActorNode(ng), ActorNode(d)) slave = wishbone.Target(SlaveModel()) diff --git a/migen/actorlib/sim.py b/migen/actorlib/sim.py index f63e15b4..00848e3f 100644 --- a/migen/actorlib/sim.py +++ b/migen/actorlib/sim.py @@ -75,3 +75,17 @@ class SimActor(Actor): def get_fragment(self): return self.token_exchanger.get_fragment() + +class Dumper(SimActor): + def __init__(self, layout, prefix=""): + def dumper_gen(): + while True: + t = Token("result") + yield t + if len(t.value) > 1: + s = str(t.value) + else: + s = str(list(t.value.values())[0]) + print(prefix + s) + super().__init__(dumper_gen(), + ("result", Sink, layout)) -- 2.30.2