2012-01-06 18:33:28 -05:00
|
|
|
import networkx as nx
|
|
|
|
|
2012-01-09 08:21:45 -05:00
|
|
|
from migen.fhdl.structure import *
|
2012-01-06 18:33:28 -05:00
|
|
|
from migen.flow.actor import *
|
2012-01-09 08:21:45 -05:00
|
|
|
from migen.corelogic.misc import optree
|
2012-01-06 18:33:28 -05:00
|
|
|
|
|
|
|
class CompositeActor(Actor):
|
2012-01-15 09:09:44 -05:00
|
|
|
def __init__(self, dfg): # TODO: endpoints
|
2012-01-06 18:33:28 -05:00
|
|
|
self.dfg = dfg
|
|
|
|
Actor.__init__(self,
|
2012-01-15 09:09:44 -05:00
|
|
|
SchedulingModel(SchedulingModel.DYNAMIC))
|
2012-01-06 18:33:28 -05:00
|
|
|
|
2012-01-10 09:54:51 -05:00
|
|
|
def get_fragment(self):
|
2012-01-15 09:09:44 -05:00
|
|
|
this_fragments = [get_conn_fragment(x[0].endpoints[x[2]["source"]], x[1].endpoints[x[2]["sink"]])
|
|
|
|
for x in self.dfg.edges(data=True)]
|
|
|
|
this = sum(this_fragments, Fragment())
|
2012-01-10 09:54:51 -05:00
|
|
|
others = sum([node.get_fragment() for node in self.dfg], Fragment())
|
2012-02-14 07:12:43 -05:00
|
|
|
busy = Fragment([self.busy.eq(optree("|", [node.busy for node in self.dfg]))])
|
2012-01-09 08:21:45 -05:00
|
|
|
return this + others + busy
|
2012-01-06 18:33:28 -05:00
|
|
|
|
|
|
|
def add_connection(dfg, source_node, sink_node, source_ep=None, sink_ep=None):
|
|
|
|
if source_ep is None:
|
|
|
|
source_eps = source_node.sources()
|
|
|
|
assert(len(source_eps) == 1)
|
|
|
|
source_ep = source_eps[0]
|
|
|
|
if sink_ep is None:
|
|
|
|
sink_eps = sink_node.sinks()
|
|
|
|
assert(len(sink_eps) == 1)
|
|
|
|
sink_ep = sink_eps[0]
|
|
|
|
dfg.add_edge(source_node, sink_node, source=source_ep, sink=sink_ep)
|