From: Sebastien Bourdeauducq Date: Tue, 10 Jan 2012 14:54:51 +0000 (+0100) Subject: flow: simplify actor fragment interface X-Git-Tag: 24jan2021_ls180~2099^2~1084 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a6e5f3e76680f619b89aa47aaef77209ccb63aaa;p=litex.git flow: simplify actor fragment interface --- diff --git a/examples/dataflow.py b/examples/dataflow.py index 8e43f8c5..aab603f9 100644 --- a/examples/dataflow.py +++ b/examples/dataflow.py @@ -1,7 +1,7 @@ import sys import networkx as nx -from migen.fhdl import verilog +from migen.fhdl import verilog from migen.flow.ala import * from migen.flow.network import * from migen.flow.composer import * @@ -13,7 +13,7 @@ a3 = make_composable(g, Add(BV(16))) c3 = (a1 + a2)*a3 c = CompositeActor(g) -frag = c.get_control_fragment() + c.get_process_fragment() +frag = c.get_fragment() print(verilog.convert(frag)) diff --git a/migen/flow/actor.py b/migen/flow/actor.py index 25279bd8..346cc06e 100644 --- a/migen/flow/actor.py +++ b/migen/flow/actor.py @@ -146,28 +146,26 @@ class Actor: elif self.scheduling_model.model == SchedulingModel.PIPELINE: return _control_fragment_pipe(self.scheduling_model.latency, stb_i, ack_o, stb_o, ack_i, self.busy, self.pipe_ce) elif self.scheduling_model.model == SchedulingModel.DYNAMIC: - raise NotImplementedError("Actor classes with dynamic scheduling must overload get_control_fragment") + raise NotImplementedError("Actor classes with dynamic scheduling must overload get_control_fragment or get_fragment") def get_process_fragment(self): raise NotImplementedError("Actor classes must overload get_process_fragment") + def get_fragment(self): + return self.get_control_fragment() + self.get_process_fragment() + def __repr__(self): 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) - assert isinstance(sink, Sink) - comb = [ - source.ack.eq(sink.ack), - sink.stb.eq(source.stb) - ] - return Fragment(comb) - -def get_conn_process_fragment(source, sink): +def get_conn_fragment(source, sink): assert isinstance(source, Source) assert isinstance(sink, Sink) assert sink.token.compatible(source.token) sigs_source = source.token.flatten() sigs_sink = sink.token.flatten() - comb = [Cat(*sigs_sink).eq(Cat(*sigs_source))] + comb = [ + source.ack.eq(sink.ack), + sink.stb.eq(source.stb), + Cat(*sigs_sink).eq(Cat(*sigs_source)) + ] return Fragment(comb) diff --git a/migen/flow/network.py b/migen/flow/network.py index 409e32c2..d0333a3d 100644 --- a/migen/flow/network.py +++ b/migen/flow/network.py @@ -20,18 +20,12 @@ class CompositeActor(Actor): SchedulingModel(SchedulingModel.DYNAMIC), endpoints=our_endpoints) - def get_control_fragment(self): - this = sum([get_conn_control_fragment(x[2]['source'], x[2]['sink']) + def get_fragment(self): + this = sum([get_conn_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()) + others = sum([node.get_fragment() for node in self.dfg], Fragment()) busy = Fragment([self.busy.eq(optree('|', [node.busy for node in self.dfg]))]) return this + others + busy - - 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: diff --git a/migen/flow/plumbing.py b/migen/flow/plumbing.py index e7f06efc..6f9c8b44 100644 --- a/migen/flow/plumbing.py +++ b/migen/flow/plumbing.py @@ -25,10 +25,7 @@ class Combinator(Actor): SchedulingModel(SchedulingModel.COMBINATORIAL), self.ins, self.destination) - def get_process_fragment(self): - return Fragment() # nothing to do - - def get_control_fragment(self): + def get_fragment(self): source = self.sources()[0] sinks = self.sinks() comb = [source.stb.eq(optree('&', [sink.stb for sink in sinks]))] @@ -43,7 +40,4 @@ class Splitter(Actor): SchedulingModel(SchedulingModel.COMBINATORIAL), self.source, self.outs) - def get_process_fragment(self): - return Fragment() # nothing to do - - # TODO def get_control_fragment(self): + # TODO def get_fragment(self):