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ß <f.maass@vogl-electronic.com>
  • Loading branch information
maass-hamburg committed Dec 5, 2024
1 parent 832a724 commit a950eb8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion migen/fhdl/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,26 @@ class _Value(DUID):
represent the integer.
"""
def __bool__(self):
# Special case: Constants and Signals are part of a set or used as
# Special case: Constants, Signals and Slices are part of a set or used as
# dictionary keys, and Python needs to check for equality.
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) or isinstance(b, _Slice):
a_start = 0
b_start = 0
if len(a) != len(b):
return False
while isinstance(a, _Slice):
a_start += a.start
a = a.value
while isinstance(b, _Slice):
b_start += b.start
b = b.value
return (bool(a == b) and (a_start == b_start))
if (isinstance(a, Constant) and isinstance(b, Signal)
or isinstance(a, Signal) and isinstance(b, Constant)):
return False
Expand Down

0 comments on commit a950eb8

Please sign in to comment.