Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fhdl/structure: add check for equality for _Slice #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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