Skip to content

Commit

Permalink
litex/gen/fhdl/expression: Improve _generate_slice to avoid slicing a…
Browse files Browse the repository at this point in the history
…ll 1-bit Signals and cleanup.
  • Loading branch information
enjoy-digital committed Jan 14, 2025
1 parent e71e404 commit 279b758
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions litex/gen/fhdl/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ def to_signed(r):

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

Expand Down

0 comments on commit 279b758

Please sign in to comment.