flow: draw network graph
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Mon, 9 Jan 2012 13:21:54 +0000 (14:21 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Mon, 9 Jan 2012 13:21:54 +0000 (14:21 +0100)
examples/dataflow.py
migen/flow/actor.py

index 7707b3a2dc64aa312ff92ed11854aef4f21bc3ce..8e43f8c5d0186a1de6d2d40e19ffc765d97af14d 100644 (file)
@@ -1,3 +1,4 @@
+import sys
 import networkx as nx
 
 from migen.fhdl import verilog 
@@ -10,9 +11,13 @@ a1 = make_composable(g, Add(BV(16)))
 a2 = make_composable(g, Add(BV(16)))
 a3 = make_composable(g, Add(BV(16)))
 c3 = (a1 + a2)*a3
-print(c3)
 c = CompositeActor(g)
 
 frag = c.get_control_fragment() + c.get_process_fragment()
 
 print(verilog.convert(frag))
+
+if len(sys.argv) > 1 and sys.argv[1] == "draw":
+       import matplotlib.pyplot as plt
+       nx.draw(g)
+       plt.show()
index a1f57e4fae0a46b8d147b6bd8daa65ded71b883c..25279bd842bef1092d3cbb9c451faaeeb3d36ab6 100644 (file)
@@ -152,7 +152,7 @@ class Actor:
                raise NotImplementedError("Actor classes must overload get_process_fragment")
        
        def __repr__(self):
-               return "<Actor " + repr(self.scheduling_model) + " " + repr(self.sinks()) + " " + repr(self.sources()) + ">"
+               return "<" + self.__class__.__name__ + " " + repr(self.scheduling_model) + " " + repr(self.sinks()) + " " + repr(self.sources()) + ">"
 
 def get_conn_control_fragment(source, sink):
        assert isinstance(source, Source)