From 279b758584a64a3cdea7da5cfa543f1355292548 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 14 Jan 2025 17:57:04 +0100 Subject: [PATCH] litex/gen/fhdl/expression: Improve _generate_slice to avoid slicing all 1-bit Signals and cleanup. --- litex/gen/fhdl/expression.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/litex/gen/fhdl/expression.py b/litex/gen/fhdl/expression.py index f5325f0275..3a8d537af9 100644 --- a/litex/gen/fhdl/expression.py +++ b/litex/gen/fhdl/expression.py @@ -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