bus: add interconnect statements function
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 17 Feb 2012 22:51:32 +0000 (23:51 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 17 Feb 2012 22:51:32 +0000 (23:51 +0100)
migen/bus/dfi.py
migen/bus/simple.py

index 5fb2a044e1181bf703456416da7e35b5617a0e93..b2137cb399513ec259fac64f6d636d6d6f8d9f5d 100644 (file)
@@ -42,14 +42,16 @@ class Interface:
                                        r.append(("dfi_" + signal[1] + suffix, getattr(phase, signal[1])))
                return r
 
+def interconnect_stmts(master, slave):
+       r = []
+       for pm, ps in zip(master.phases, slave.phases):
+               r += simple_interconnect_stmts(master.pdesc, pm, [ps])
+       return r
+
 class Interconnect:
        def __init__(self, master, slave):
                self.master = master
                self.slave = slave
        
        def get_fragment(self):
-               f = Fragment()
-               for pm, ps in zip(self.master.phases, self.slave.phases):
-                       ic = SimpleInterconnect(pm, [ps])
-                       f += ic.get_fragment()
-               return f
+               return Fragment(interconnect_stmts(self.master, self.slave))
index f0f1049034b8e96e2d21362d978d4eb2404fe28c..348e510ce76cc131f54d886491b7a680ad763770 100644 (file)
@@ -27,19 +27,21 @@ class SimpleInterface:
                        signame = signal[1]
                        setattr(self, signame, Signal(BV(signal[2]), busname + "_" + signame))
 
+def simple_interconnect_stmts(desc, master, slaves):
+       s2m = desc.get_names(S_TO_M)
+       m2s = desc.get_names(M_TO_S)
+       sl = [getattr(slave, name).eq(getattr(master, name))
+               for name in m2s for slave in slaves]
+       sl += [getattr(master, name).eq(
+                       optree("|", [getattr(slave, name) for slave in slaves])
+               )
+               for name in s2m]
+       return sl
+
 class SimpleInterconnect:
        def __init__(self, master, slaves):
                self.master = master
                self.slaves = slaves
        
        def get_fragment(self):
-               desc = self.master.desc 
-               s2m = desc.get_names(S_TO_M)
-               m2s = desc.get_names(M_TO_S)
-               comb = [getattr(slave, name).eq(getattr(self.master, name))
-                       for name in m2s for slave in self.slaves]
-               comb += [getattr(self.master, name).eq(
-                               optree("|", [getattr(slave, name) for slave in self.slaves])
-                       )
-                       for name in s2m]
-               return Fragment(comb)
+               return Fragment(simple_interconnect_stmts(self.master.desc, self.master, self.slaves))