Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
2  migen/flow/network.py
@@ -247,4 +247,4 @@ def __init__(self, dfg):
247 247
 		for u, v, d in dfg.edges_iter(data=True):
248 248
 			ep_src = getattr(u, d["source"])
249 249
 			ep_dst = getattr(v, d["sink"])
250  
-			self.comb += ep_src.connect(ep_dst, match_by_position=True)
  250
+			self.comb += ep_src.connect_flat(ep_dst)
54  migen/genlib/record.py
@@ -80,27 +80,27 @@ def __init__(self, layout, name=None):
80 80
 	def eq(self, other):
81 81
 		return [getattr(self, f[0]).eq(getattr(other, f[0]))
82 82
 		  for f in self.layout if hasattr(other, f[0])]
83  
-	
84  
-	def flatten(self):
85  
-		r = []
86  
-		for f in self.layout:			
  83
+
  84
+	def iter_flat(self):
  85
+		for f in self.layout:
87 86
 			e = getattr(self, f[0])
88 87
 			if isinstance(e, Signal):
89  
-				r.append(e)
  88
+				if len(f) == 3:
  89
+					yield e, f[2]
  90
+				else:
  91
+					yield e, DIR_NONE
90 92
 			elif isinstance(e, Record):
91  
-				r += e.flatten()
  93
+				yield from e.iter_flat()
92 94
 			else:
93 95
 				raise TypeError
94  
-		return r
  96
+	
  97
+	def flatten(self):
  98
+		return [signal for signal, direction in self.iter_flat()]
95 99
 
96 100
 	def raw_bits(self):
97 101
 		return Cat(*self.flatten())
98 102
 	
99  
-	def connect(self, *slaves, match_by_position=False):
100  
-		if match_by_position:
101  
-			iters = [iter(slave.layout) for slave in slaves]
102  
-		else:
103  
-			iters = [iter(self.layout) for slave in slaves]
  103
+	def connect(self, *slaves):
104 104
 		r = []
105 105
 		for f in self.layout:
106 106
 			field = f[0]
@@ -108,16 +108,34 @@ def connect(self, *slaves, match_by_position=False):
108 108
 			if isinstance(self_e, Signal):
109 109
 				direction = f[2]
110 110
 				if direction == DIR_M_TO_S:
111  
-					r += [getattr(slave, next(it)[0]).eq(self_e) for slave, it in zip(slaves, iters)]
  111
+					r += [getattr(slave, field).eq(self_e) for slave in slaves]
112 112
 				elif direction == DIR_S_TO_M:
113  
-					r.append(self_e.eq(optree("|", [getattr(slave, next(it)[0])
114  
-					  for slave, it in zip(slaves, iters)])))
  113
+					r.append(self_e.eq(optree("|", [getattr(slave, field) for slave in slaves])))
115 114
 				else:
116 115
 					raise TypeError
117 116
 			else:
118  
-				for slave, it in zip(slaves, iters):
119  
-					r += self_e.connect(getattr(slave, next(it)[0]),
120  
-					  match_by_position=match_by_position)
  117
+				for slave in slaves:
  118
+					r += self_e.connect(getattr(slave, field))
  119
+		return r
  120
+
  121
+	def connect_flat(self, *slaves):
  122
+		r = []
  123
+		iter_slaves = [slave.iter_flat() for slave in slaves]
  124
+		for m_signal, m_direction in self.iter_flat():
  125
+			if m_direction == DIR_M_TO_S:
  126
+				for iter_slave in iter_slaves:
  127
+					s_signal, s_direction = next(iter_slave)
  128
+					assert(s_direction == DIR_M_TO_S)
  129
+					r.append(s_signal.eq(m_signal))
  130
+			elif m_direction == DIR_S_TO_M:
  131
+				s_signals = []
  132
+				for iter_slave in iter_slaves:
  133
+					s_signal, s_direction = next(iter_slave)
  134
+					assert(s_direction == DIR_S_TO_M)
  135
+					s_signals.append(s_signal)
  136
+				r.append(m_signal.eq(optree("|", s_signals)))
  137
+			else:
  138
+				raise TypeError
121 139
 		return r
122 140
 
123 141
 	def __len__(self):

No commit comments for this range

Something went wrong with that request. Please try again.