migen/genlib/record: add leave_out parameter to connect

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.
This commit is contained in:
Florent Kermarrec 2015-05-23 00:22:13 +02:00
parent 5390540d3c
commit 9cabcf14e9
1 changed files with 15 additions and 12 deletions

View File

@ -128,22 +128,25 @@ class Record:
def raw_bits(self): def raw_bits(self):
return Cat(*self.flatten()) 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 = [] r = []
for f in self.layout: for f in self.layout:
field = f[0] field = f[0]
self_e = getattr(self, field) if field not in leave_out:
if isinstance(self_e, Signal): self_e = getattr(self, field)
direction = f[2] if isinstance(self_e, Signal):
if direction == DIR_M_TO_S: direction = f[2]
r += [getattr(slave, field).eq(self_e) for slave in slaves] if direction == DIR_M_TO_S:
elif direction == DIR_S_TO_M: r += [getattr(slave, field).eq(self_e) for slave in slaves]
r.append(self_e.eq(optree("|", [getattr(slave, field) 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: else:
raise TypeError for slave in slaves:
else: r += self_e.connect(getattr(slave, field), leave_out=leave_out)
for slave in slaves:
r += self_e.connect(getattr(slave, field))
return r return r
def connect_flat(self, *slaves): def connect_flat(self, *slaves):