Skip to content

Commit

Permalink
back.rtlil: match shape of Array elements to ArrayProxy shape.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Dec 31, 2018
1 parent cdc40ea commit ae3c583
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions nmigen/back/rtlil.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,10 @@ def on_ArrayProxy(self, value):
index = self.s.expand(value.index)
if isinstance(index, ast.Const):
if index.value < len(value.elems):
return self(value.elems[index.value])
elem = value.elems[index.value]
else:
return self(value.elems[-1])
elem = value.elems[-1]
return self.match_shape(elem, *value.shape())
else:
raise LegalizeValue(value.index, range(len(value.elems)))

Expand Down Expand Up @@ -503,6 +504,10 @@ def on_Const(self, value):
def on_Operator(self, value):
raise TypeError # :nocov:

def match_shape(self, value, new_bits, new_sign):
assert value.shape() == (new_bits, new_sign)
return self(value)

def on_Signal(self, value):
wire_curr, wire_next = self.s.resolve(value)
if wire_next is None:
Expand Down

0 comments on commit ae3c583

Please sign in to comment.