actorlib/sim: Dumper
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 23 Nov 2012 23:00:07 +0000 (00:00 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 23 Nov 2012 23:00:07 +0000 (00:00 +0100)
examples/dataflow/arithmetic.py
examples/dataflow/fibonacci.py
examples/pytholite/basic.py
examples/pytholite/uio.py
migen/actorlib/sim.py

index bd3e037b434bf4d34a89962baf11e02f69bf7064..89efa0b1eef52276d612635d26d4169cf628d716 100644 (file)
@@ -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"
index e67728bba3770ffd204a96ea9bb6463914c30936..8e1276eeb714cca9e011163ae4e6ef331e70a4eb 100644 (file)
@@ -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()
index 91688dc028c200e9b84a73dcae729643dd1a4805..40c8e96223c3480ebd49a6f3e3a5e319a641b54c 100644 (file)
@@ -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)
index a0c5ca3cdb1aae47e114174d11cf9419b15e7f94..0cf5b6eb51bd0e598eee820ddbf5091ee1be22ca 100644 (file)
@@ -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())
index f63e15b4915e691714d06a1b992242e4a49842fc..00848e3f609c5c97c9c0fdb945839fa5c6e84857 100644 (file)
@@ -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))