Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 37 additions and 19 deletions.
  1. +1 −1  migen/flow/network.py
  2. +36 −18 migen/genlib/record.py
View
2  migen/flow/network.py
@@ -247,4 +247,4 @@ def __init__(self, dfg):
for u, v, d in dfg.edges_iter(data=True):
ep_src = getattr(u, d["source"])
ep_dst = getattr(v, d["sink"])
- self.comb += ep_src.connect(ep_dst, match_by_position=True)
+ self.comb += ep_src.connect_flat(ep_dst)
View
54 migen/genlib/record.py
@@ -80,27 +80,27 @@ def __init__(self, layout, name=None):
def eq(self, other):
return [getattr(self, f[0]).eq(getattr(other, f[0]))
for f in self.layout if hasattr(other, f[0])]
-
- def flatten(self):
- r = []
- for f in self.layout:
+
+ def iter_flat(self):
+ for f in self.layout:
e = getattr(self, f[0])
if isinstance(e, Signal):
- r.append(e)
+ if len(f) == 3:
+ yield e, f[2]
+ else:
+ yield e, DIR_NONE
elif isinstance(e, Record):
- r += e.flatten()
+ yield from e.iter_flat()
else:
raise TypeError
- return r
+
+ def flatten(self):
+ return [signal for signal, direction in self.iter_flat()]
def raw_bits(self):
return Cat(*self.flatten())
- def connect(self, *slaves, match_by_position=False):
- if match_by_position:
- iters = [iter(slave.layout) for slave in slaves]
- else:
- iters = [iter(self.layout) for slave in slaves]
+ def connect(self, *slaves):
r = []
for f in self.layout:
field = f[0]
@@ -108,16 +108,34 @@ def connect(self, *slaves, match_by_position=False):
if isinstance(self_e, Signal):
direction = f[2]
if direction == DIR_M_TO_S:
- r += [getattr(slave, next(it)[0]).eq(self_e) for slave, it in zip(slaves, iters)]
+ 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, next(it)[0])
- for slave, it in zip(slaves, iters)])))
+ r.append(self_e.eq(optree("|", [getattr(slave, field) for slave in slaves])))
else:
raise TypeError
else:
- for slave, it in zip(slaves, iters):
- r += self_e.connect(getattr(slave, next(it)[0]),
- match_by_position=match_by_position)
+ for slave in slaves:
+ r += self_e.connect(getattr(slave, field))
+ return r
+
+ def connect_flat(self, *slaves):
+ r = []
+ iter_slaves = [slave.iter_flat() for slave in slaves]
+ for m_signal, m_direction in self.iter_flat():
+ if m_direction == DIR_M_TO_S:
+ for iter_slave in iter_slaves:
+ s_signal, s_direction = next(iter_slave)
+ assert(s_direction == DIR_M_TO_S)
+ r.append(s_signal.eq(m_signal))
+ elif m_direction == DIR_S_TO_M:
+ s_signals = []
+ for iter_slave in iter_slaves:
+ s_signal, s_direction = next(iter_slave)
+ assert(s_direction == DIR_S_TO_M)
+ s_signals.append(s_signal)
+ r.append(m_signal.eq(optree("|", s_signals)))
+ else:
+ raise TypeError
return r
def __len__(self):

No commit comments for this range

Something went wrong with that request. Please try again.