Skip to content

Commit

Permalink
gen: fhdl: expression: resolve slice completly
Browse files Browse the repository at this point in the history
resolve slice completly, to reduce complexity
in the verilog files.

Signed-off-by: Fin Maaß <[email protected]>
  • Loading branch information
maass-hamburg committed Jan 20, 2025
1 parent 666c9b4 commit 6c9fe62
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 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:
sr = "" # Avoid slicing 1-bit Signals.
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

0 comments on commit 6c9fe62

Please sign in to comment.