migen/genlib/record: add leave_out parameter to connect
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 22 May 2015 22:22:13 +0000 (00:22 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Sat, 23 May 2015 11:59:09 +0000 (13:59 +0200)
Modules doing dataflow adaptation often need to connect most of the signals between endpoints except the one concerned by the adaptation.
This new parameter ease that by avoid manual connection of all signals.

migen/genlib/record.py

index d2e93cd90aadfc24f26ec2bbdcbc00ee30a07124..05151bc678cb92c4ccc677aae4c4f03ceecc356c 100644 (file)
@@ -128,22 +128,25 @@ class Record:
     def raw_bits(self):
         return Cat(*self.flatten())
 
-    def connect(self, *slaves):
+    def connect(self, *slaves, leave_out=set()):
+        if isinstance(leave_out, str):
+            leave_out = {leave_out}
         r = []
         for f in self.layout:
             field = f[0]
-            self_e = getattr(self, field)
-            if isinstance(self_e, Signal):
-                direction = f[2]
-                if direction == DIR_M_TO_S:
-                    r += [getattr(slave, field).eq(self_e) for slave in slaves]
-                elif direction == DIR_S_TO_M:
-                    r.append(self_e.eq(optree("|", [getattr(slave, field) for slave in slaves])))
+            if field not in leave_out:
+                self_e = getattr(self, field)
+                if isinstance(self_e, Signal):
+                    direction = f[2]
+                    if direction == DIR_M_TO_S:
+                        r += [getattr(slave, field).eq(self_e) for slave in slaves]
+                    elif direction == DIR_S_TO_M:
+                        r.append(self_e.eq(optree("|", [getattr(slave, field) for slave in slaves])))
+                    else:
+                        raise TypeError
                 else:
-                    raise TypeError
-            else:
-                for slave in slaves:
-                    r += self_e.connect(getattr(slave, field))
+                    for slave in slaves:
+                        r += self_e.connect(getattr(slave, field), leave_out=leave_out)
         return r
 
     def connect_flat(self, *slaves):