flow: adapt to new Record API
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Mon, 1 Apr 2013 20:15:23 +0000 (22:15 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Mon, 1 Apr 2013 20:15:23 +0000 (22:15 +0200)
migen/actorlib/spi.py
migen/actorlib/structuring.py
migen/flow/actor.py
migen/flow/network.py
migen/flow/plumbing.py

index b831c3baa446fb6c7446421e1510b942213a0fc6..7b94fe45b13502755509ee6e3085fd83dcb77670 100644 (file)
@@ -108,7 +108,7 @@ class Collector(Actor, AutoCSR):
                        self._r_wc.dat_w.eq(self._r_wc.storage - 1),
                        
                        wp.adr.eq(self._r_wa.storage),
-                       wp.dat_w.eq(Cat(*self.token("sink").flatten())),
+                       wp.dat_w.eq(self.token("sink").raw_bits()),
                        
                        rp.adr.eq(self._r_ra.storage),
                        self._r_rd.status.eq(rp.dat_r)
index dbe2204ab17a77d60db60baa89341edf4b21908c..0041806d07f5b847ac2e6a1570ddfd6043f5c2d0 100644 (file)
@@ -29,7 +29,7 @@ class Cast(CombinatorialActor):
                ])
 
 def pack_layout(l, n):
-       return [("chunk{0}".format(i), l) for i in range(n)]
+       return [("chunk"+str(i), l) for i in range(n)]
 
 class Unpack(Actor):
        def __init__(self, n, layout_to):
@@ -57,7 +57,7 @@ class Unpack(Actor):
                ]
                cases = {}
                for i in range(self.n):
-                       cases[i] = [Cat(*self.token("source").flatten()).eq(Cat(*self.token("sink").subrecord("chunk{0}".format(i)).flatten()))]
+                       cases[i] = [self.token("source").raw_bits().eq(getattr(self.token("sink"), "chunk"+str(i)).raw_bits())]
                comb.append(Case(mux, cases).makedefault())
                return Fragment(comb, sync)
 
@@ -75,7 +75,7 @@ class Pack(Actor):
                strobe_all = Signal()
                cases = {}
                for i in range(self.n):
-                       cases[i] = [Cat(*self.token("source").subrecord("chunk{0}".format(i)).flatten()).eq(*self.token("sink").flatten())]
+                       cases[i] = [getattr(self.token("source"), "chunk"+str(i)).raw_bits().eq(self.token("sink").raw_bits())]
                comb = [
                        self.busy.eq(strobe_all),
                        self.endpoints["sink"].ack.eq(~strobe_all | self.endpoints["source"].ack),
index 0b286342d451a4bb43b51b15c91b45ef0c6c2c37..867a5009666bb8f5f3547bbac3f7efcbee361edb 100644 (file)
@@ -163,7 +163,6 @@ class PipelinedActor(BinaryActor):
 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 = [
index ee6962946dd37cde2253ba9bc24a00577f353cf1..4f222143a2ea89aa4f837fff681fe5b64c9120f4 100644 (file)
@@ -170,7 +170,7 @@ class DataFlowGraph(MultiDiGraph):
                                                other_ep = other.single_sink()
                                else:
                                        raise AssertionError
-                               layout = other.token(other_ep).layout()
+                               layout = other.token(other_ep).layout
                                a.parameters["layout"] = layout
                                self.instantiate(a)
        
index 04fc5d128c69a282b23b04d7b641b61163c4e7f2..d19abc077eddb975a1e02a0fcf7d5bc8b8300e1e 100644 (file)
@@ -1,4 +1,5 @@
 from migen.fhdl.structure import *
+from migen.fhdl.module import Module
 from migen.flow.actor import *
 from migen.genlib.record import *
 from migen.genlib.misc import optree
@@ -14,57 +15,45 @@ class Buffer(PipelinedActor):
                sync = [If(self.pipe_ce, Cat(*sigs_q).eq(Cat(*sigs_d)))]
                return Fragment(sync=sync)
 
-class Combinator(Actor):
+class Combinator(Module, Actor):
        def __init__(self, layout, subrecords):
-               source = Record(layout)
-               subrecords = [source.subrecord(*subr) for subr in subrecords]
-               eps = [("sink{0}".format(n), Sink, r)
+               eps = [("source", Source, layout)]
+               eps += [("sink"+str(n), Sink, layout_partial(layout, r))
                        for n, r in enumerate(subrecords)]
-               ep_source = ("source", Source, source)
-               eps.append(ep_source)
                Actor.__init__(self, *eps)
 
-       def get_fragment(self):
+               ###
+       
                source = self.endpoints["source"]
-               sinks = [self.endpoints["sink{0}".format(n)]
+               sinks = [self.endpoints["sink"+str(n)]
                        for n in range(len(self.endpoints)-1)]
-               comb = [source.stb.eq(optree("&", [sink.stb for sink in sinks]))]
-               comb += [sink.ack.eq(source.ack & source.stb) for sink in sinks]
-               return Fragment(comb)
+               self.comb += [source.stb.eq(optree("&", [sink.stb for sink in sinks]))]
+               self.comb += [sink.ack.eq(source.ack & source.stb) for sink in sinks]
+               self.comb += [source.token.eq(sink.token) for sink in sinks]
 
-class Splitter(Actor):
+class Splitter(Module, Actor):
        def __init__(self, layout, subrecords):
-               sink = Record(layout)
-               subr = []
-               for s in subrecords:
-                       if s is None:
-                               subr.append(sink)
-                       else:
-                               subr.append(sink.subrecord(*s))
-               eps = [("source{0}".format(n), Source, r)
-                       for n, r in enumerate(subr)]
-               ep_sink = ("sink", Sink, sink)
-               eps.append(ep_sink)
+               eps = [("sink", Sink, layout)]
+               eps += [("source"+str(n), Source, layout_partial(layout, *r))
+                       for n, r in enumerate(subrecords)]
                Actor.__init__(self, *eps)
                
-       def get_fragment(self):
+               ###
+
                sources = [self.endpoints[e] for e in self.sources()]
                sink = self.endpoints[self.sinks()[0]]
+
+               self.comb += [source.token.eq(sink.token) for source in sources]
                
                already_acked = Signal(len(sources))
-               sync = [
-                       If(sink.stb,
+               self.sync += If(sink.stb,
                                already_acked.eq(already_acked | Cat(*[s.ack for s in sources])),
                                If(sink.ack, already_acked.eq(0))
                        )
-               ]
-               comb = [
-                       sink.ack.eq(optree("&",
+               self.comb += sink.ack.eq(optree("&",
                                [s.ack | already_acked[n] for n, s in enumerate(sources)]))
-               ]
                for n, s in enumerate(sources):
-                       comb.append(s.stb.eq(sink.stb & ~already_acked[n]))
-               return Fragment(comb, sync)
+                       self.comb += s.stb.eq(sink.stb & ~already_acked[n])
 
 # Actors whose layout should be inferred from what their single sink is connected to.
 layout_sink = {Buffer, Splitter}