Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/migen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c82b53f1cd81
Choose a base ref
...
head repository: m-labs/migen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0ec6a7eb4e0e
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on May 10, 2013

  1. Revert "genlib/record/connect: add match_by_position"

    This reverts commit df1ed32.
    Sebastien Bourdeauducq committed May 10, 2013
    Copy the full SHA
    955a973 View commit details

Commits on May 11, 2013

  1. genlib/record: match_by_position -> connect_flat

    Sebastien Bourdeauducq committed May 11, 2013
    Copy the full SHA
    0ec6a7e View commit details
Showing with 37 additions and 19 deletions.
  1. +1 −1 migen/flow/network.py
  2. +36 −18 migen/genlib/record.py
2 changes: 1 addition & 1 deletion migen/flow/network.py
Original file line number Diff line number Diff line change
@@ -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)
54 changes: 36 additions & 18 deletions migen/genlib/record.py
Original file line number Diff line number Diff line change
@@ -80,44 +80,62 @@ 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]
self_e = getattr(self, field)
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):