-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastien Bourdeauducq
committed
Jan 6, 2012
1 parent
3c1dada
commit 0b195a2
Showing
5 changed files
with
146 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import networkx as nx | ||
|
||
from migen.fhdl import verilog | ||
from migen.flow.ala import * | ||
from migen.flow.plumbing import * | ||
from migen.flow.network import * | ||
|
||
def get_actor_fragments(*actors): | ||
return sum([a.get_control_fragment() + a.get_process_fragment() for a in actors], Fragment()) | ||
|
||
act = Adder(32) | ||
comb = Combinator(act.operands, ["a"], ["b"]) | ||
comb = Combinator(act.operands.template(), ["a"], ["b"]) | ||
outbuf = Buffer(act.result.template()) | ||
frag = get_actor_fragments(act, comb, outbuf) | ||
|
||
stb_a = comb.sinks[0].stb | ||
ack_a = comb.sinks[0].ack | ||
stb_b = comb.sinks[1].stb | ||
ack_b = comb.sinks[1].ack | ||
stb_a.name = "stb_a_i" | ||
ack_a.name = "ack_a_o" | ||
stb_b.name = "stb_b_i" | ||
ack_b.name = "stb_b_o" | ||
a = comb.ins[0].a | ||
b = comb.ins[1].b | ||
a.name = "a" | ||
b.name = "b" | ||
print(verilog.convert(frag, ios={stb_a, ack_a, stb_b, ack_b, a, b})) | ||
g = nx.MultiDiGraph() | ||
g.add_nodes_from([act, comb, outbuf]) | ||
add_connection(g, comb, act) | ||
add_connection(g, act, outbuf) | ||
c = CompositeActor(g) | ||
|
||
frag = c.get_control_fragment() + c.get_process_fragment() | ||
|
||
print(verilog.convert(frag)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import networkx as nx | ||
|
||
from migen.flow.actor import * | ||
|
||
class CompositeActor(Actor): | ||
def __init__(self, dfg): | ||
self.dfg = dfg | ||
# Internal unconnected endpoints become our endpoints. Determine them. | ||
our_endpoints = [] | ||
for node in self.dfg: | ||
endpoints = set(node.endpoints) | ||
for u, v, d in self.dfg.in_edges([node], data=True): | ||
endpoints.remove(d['sink']) | ||
for u, v, d in self.dfg.out_edges([node], data=True): | ||
endpoints.remove(d['source']) | ||
our_endpoints += list(endpoints) | ||
Actor.__init__(self, | ||
SchedulingModel(SchedulingModel.DYNAMIC), | ||
endpoints=our_endpoints) | ||
|
||
def get_control_fragment(self): | ||
this = sum([get_conn_control_fragment(x[2]['source'], x[2]['sink']) | ||
for x in self.dfg.edges(data=True)], Fragment()) | ||
others = sum([node.get_control_fragment() for node in self.dfg], Fragment()) | ||
return this + others | ||
|
||
def get_process_fragment(self): | ||
this = sum([get_conn_process_fragment(x[2]['source'], x[2]['sink']) | ||
for x in self.dfg.edges(data=True)], Fragment()) | ||
others = sum([node.get_process_fragment() for node in self.dfg], Fragment()) | ||
return this + others | ||
|
||
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] | ||
assert(isinstance(source_ep, Source)) | ||
assert(isinstance(sink_ep, Sink)) | ||
assert(source_ep in source_node.endpoints) | ||
assert(sink_ep in sink_node.endpoints) | ||
dfg.add_edge(source_node, sink_node, source=source_ep, sink=sink_ep) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters