Skip to content

Commit

Permalink
fhdl/structure: add check for equality for _Slice
Browse files Browse the repository at this point in the history
add check for equality for _Slice.

Signed-off-by: Fin Maaß <[email protected]>
  • Loading branch information
maass-hamburg committed Nov 5, 2024
1 parent 832a724 commit 7845b72
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions migen/fhdl/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7845b72

Please sign in to comment.