gen/genlib/record: rename leave_out by omit and add keep parameter to Record.connect

This commit is contained in:
Florent Kermarrec 2016-04-21 08:08:47 +02:00
parent ee378b2557
commit c330e7be49
1 changed files with 18 additions and 9 deletions

View File

@ -131,15 +131,24 @@ class Record:
def raw_bits(self): def raw_bits(self):
return Cat(*self.flatten()) return Cat(*self.flatten())
def connect(self, *slaves, leave_out=set()): def connect(self, *slaves, keep=None, omit=None):
if isinstance(leave_out, str): if keep is None:
leave_out = {leave_out} keep = set([f[0] for f in self.layout])
if isinstance(keep, list):
keep = set(keep)
if omit is None:
omit = set()
if isinstance(omit, list):
omit = set(omit)
keep = keep - omit
r = [] r = []
for f in self.layout: for f in self.layout:
field = f[0] field = f[0]
if field not in leave_out: self_e = getattr(self, field)
self_e = getattr(self, field) if isinstance(self_e, Signal):
if isinstance(self_e, Signal): if field in keep:
direction = f[2] direction = f[2]
if direction == DIR_M_TO_S: if direction == DIR_M_TO_S:
r += [getattr(slave, field).eq(self_e) for slave in slaves] r += [getattr(slave, field).eq(self_e) for slave in slaves]
@ -147,9 +156,9 @@ class Record:
r.append(self_e.eq(reduce(or_, [getattr(slave, field) for slave in slaves]))) r.append(self_e.eq(reduce(or_, [getattr(slave, field) for slave in slaves])))
else: else:
raise TypeError raise TypeError
else: else:
for slave in slaves: for slave in slaves:
r += self_e.connect(getattr(slave, field), leave_out=leave_out) r += self_e.connect(getattr(slave, field), keep=keep, omit=omit)
return r return r
def connect_flat(self, *slaves): def connect_flat(self, *slaves):