Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 32 additions and 17 deletions.
  1. +32 −17 migen/fhdl/tools.py
View
49 migen/fhdl/tools.py
@@ -152,6 +152,8 @@ def value_bits_sign(v):
elif v.op == "<" or v.op == "<=" or v.op == "==" or v.op == "!=" \
or v.op == ">" or v.op == ">=":
return 1, False
+ elif v.op == "~":
+ return obs[0]
else:
raise TypeError
elif isinstance(v, _Slice):
@@ -169,30 +171,43 @@ def value_bits_sign(v):
class _ArrayLowerer(NodeTransformer):
def __init__(self):
self.comb = []
-
+ self.target_context = False
+ self.extra_stmts = []
+
def visit_Assign(self, node):
- if isinstance(node.l, _ArrayProxy):
- k = self.visit(node.l.key)
- cases = {}
- for n, choice in enumerate(node.l.choices):
- assign = self.visit_Assign(_Assign(choice, node.r))
- cases[n] = [assign]
- return Case(k, cases).makedefault()
- else:
- return NodeTransformer.visit_Assign(self, node)
+ old_target_context, old_extra_stmts = self.target_context, self.extra_stmts
+ self.extra_stmts = []
+
+ self.target_context = True
+ lhs = self.visit(node.l)
+ self.target_context = False
+ rhs = self.visit(node.r)
+ r = _Assign(lhs, rhs)
+ if self.extra_stmts:
+ r = [r] + self.extra_stmts
+
+ self.target_context, self.extra_stmts = old_target_context, old_extra_stmts
+ return r
def visit_ArrayProxy(self, node):
- array_muxed = Signal(value_bits_sign(node))
- cases = dict((n, _Assign(array_muxed, self.visit(choice)))
- for n, choice in enumerate(node.choices))
- self.comb.append(Case(self.visit(node.key), cases).makedefault())
+ array_muxed = Signal(value_bits_sign(node), variable=True)
+ if self.target_context:
+ k = self.visit(node.key)
+ cases = {}
+ for n, choice in enumerate(node.choices):
+ cases[n] = [self.visit_Assign(_Assign(choice, array_muxed))]
+ self.extra_stmts.append(Case(k, cases).makedefault())
+ else:
+ cases = dict((n, _Assign(array_muxed, self.visit(choice)))
+ for n, choice in enumerate(node.choices))
+ self.comb.append(Case(self.visit(node.key), cases).makedefault())
return array_muxed
def lower_arrays(f):
al = _ArrayLowerer()
- f2 = al.visit(f)
- f2.comb += al.comb
- return f2
+ tf = al.visit(f)
+ tf.comb += al.comb
+ return tf
def bitreverse(s):
length, signed = value_bits_sign(s)

No commit comments for this range

Something went wrong with that request. Please try again.