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: b6fe3ace058b
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: dc552893239d
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Mar 18, 2013

  1. fhdl/tools/value_bits_sign: support not

    Sebastien Bourdeauducq committed Mar 18, 2013
    Copy the full SHA
    e95d2f4 View commit details
  2. fhdl/tools/_ArrayLowerer: complete support for arrays as targets

    Sebastien Bourdeauducq committed Mar 18, 2013
    Copy the full SHA
    dc55289 View commit details
Showing with 32 additions and 17 deletions.
  1. +32 −17 migen/fhdl/tools.py
49 changes: 32 additions & 17 deletions migen/fhdl/tools.py
Original file line number Diff line number Diff line change
@@ -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)