From 7845b72841429156f3def8ee4cf4f3e305dda704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fin=20Maa=C3=9F?= Date: Thu, 12 Sep 2024 09:36:17 +0200 Subject: [PATCH] fhdl/structure: add check for equality for _Slice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add check for equality for _Slice. Signed-off-by: Fin Maaß --- migen/fhdl/structure.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/migen/fhdl/structure.py b/migen/fhdl/structure.py index 0865e76fa..c339710a7 100644 --- a/migen/fhdl/structure.py +++ b/migen/fhdl/structure.py @@ -29,12 +29,16 @@ class _Value(DUID): def __bool__(self): # Special case: Constants and Signals are part of a set or used as # dictionary keys, and Python needs to check for equality. + # The part for the Slice has been added to do the same for Slices of + # Signals, Constants, and Slices. if isinstance(self, _Operator) and self.op == "==": a, b = self.operands if isinstance(a, Constant) and isinstance(b, Constant): return a.value == b.value if isinstance(a, Signal) and isinstance(b, Signal): return a is b + if isinstance(a, _Slice) and isinstance(b, _Slice): + return (bool(a.value == b.value) and (a.start == b.start) and (a.stop == b.stop)) if (isinstance(a, Constant) and isinstance(b, Signal) or isinstance(a, Signal) and isinstance(b, Constant)): return False