Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 1 contributor

Showing 1 changed file with 32 additions and 17 deletions. Show diff stats Hide diff stats

  1. 49  migen/fhdl/tools.py
49  migen/fhdl/tools.py
@@ -152,6 +152,8 @@ def value_bits_sign(v):
152 152
 		elif v.op == "<" or v.op == "<=" or v.op == "==" or v.op == "!=" \
153 153
 		  or v.op == ">" or v.op == ">=":
154 154
 			  return 1, False
  155
+		elif v.op == "~":
  156
+			return obs[0]
155 157
 		else:
156 158
 			raise TypeError
157 159
 	elif isinstance(v, _Slice):
@@ -169,30 +171,43 @@ def value_bits_sign(v):
169 171
 class _ArrayLowerer(NodeTransformer):
170 172
 	def __init__(self):
171 173
 		self.comb = []
172  
-	
  174
+		self.target_context = False
  175
+		self.extra_stmts = []
  176
+
173 177
 	def visit_Assign(self, node):
174  
-		if isinstance(node.l, _ArrayProxy):
175  
-			k = self.visit(node.l.key)
176  
-			cases = {}
177  
-			for n, choice in enumerate(node.l.choices):
178  
-				assign = self.visit_Assign(_Assign(choice, node.r))
179  
-				cases[n] = [assign]
180  
-			return Case(k, cases).makedefault()
181  
-		else:
182  
-			return NodeTransformer.visit_Assign(self, node)
  178
+		old_target_context, old_extra_stmts = self.target_context, self.extra_stmts
  179
+		self.extra_stmts = []
  180
+
  181
+		self.target_context = True
  182
+		lhs = self.visit(node.l)
  183
+		self.target_context = False
  184
+		rhs = self.visit(node.r)
  185
+		r = _Assign(lhs, rhs)
  186
+		if self.extra_stmts:
  187
+			r = [r] + self.extra_stmts
  188
+		
  189
+		self.target_context, self.extra_stmts = old_target_context, old_extra_stmts
  190
+		return r
183 191
 	
184 192
 	def visit_ArrayProxy(self, node):
185  
-		array_muxed = Signal(value_bits_sign(node))
186  
-		cases = dict((n, _Assign(array_muxed, self.visit(choice)))
187  
-			for n, choice in enumerate(node.choices))
188  
-		self.comb.append(Case(self.visit(node.key), cases).makedefault())
  193
+		array_muxed = Signal(value_bits_sign(node), variable=True)
  194
+		if self.target_context:
  195
+			k = self.visit(node.key)
  196
+			cases = {}
  197
+			for n, choice in enumerate(node.choices):
  198
+				cases[n] = [self.visit_Assign(_Assign(choice, array_muxed))]
  199
+			self.extra_stmts.append(Case(k, cases).makedefault())
  200
+		else:
  201
+			cases = dict((n, _Assign(array_muxed, self.visit(choice)))
  202
+				for n, choice in enumerate(node.choices))
  203
+			self.comb.append(Case(self.visit(node.key), cases).makedefault())
189 204
 		return array_muxed
190 205
 
191 206
 def lower_arrays(f):
192 207
 	al = _ArrayLowerer()
193  
-	f2 = al.visit(f)
194  
-	f2.comb += al.comb
195  
-	return f2
  208
+	tf = al.visit(f)
  209
+	tf.comb += al.comb
  210
+	return tf
196 211
 
197 212
 def bitreverse(s):
198 213
 	length, signed = value_bits_sign(s)

No commit comments for this range

Something went wrong with that request. Please try again.