Skip to content

Commit

Permalink
Merge pull request #2161 from VOGL-electronic/expression_slice
Browse files Browse the repository at this point in the history
gen: fhdl: expression: resolve slice completly
  • Loading branch information
enjoy-digital authored Jan 15, 2025
2 parents a9265ef + 29fc471 commit fefe317
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 11 additions & 6 deletions litex/gen/fhdl/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,20 @@ def to_signed(r):
# Print Slice --------------------------------------------------------------------------------------

def _generate_slice(ns, node):
assert (node.stop - node.start) >= 1
if hasattr(node.value, "__len__") and len(node.value) == 1:
length = len(node)
assert length >= 1
start = 0
while isinstance(node, _Slice):
start += node.start
node = node.value
if len(node) == 1:
sr = "" # Avoid slicing 1-bit Signals.
else:
if (node.stop - node.start) > 1:
sr = f"[{node.stop-1}:{node.start}]"
if length > 1:
sr = f"[{start+length-1}:{start}]"
else:
sr = f"[{node.start}]"
r, s = _generate_expression(ns, node.value)
sr = f"[{start}]"
r, s = _generate_expression(ns, node)
return r + sr, s

# Print Cat ----------------------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions litex/gen/fhdl/verilog.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,6 @@ def convert(f, ios=set(), name="top", platform=None,
msg += f"- {f.name}\n"
raise Exception(msg)

# Lower complex slices.
f = lower_complex_slices(f)

# Insert resets.
insert_resets(f)

Expand Down

0 comments on commit fefe317

Please sign in to comment.