Skip to content

Commit

Permalink
fhdl: fix mismatch between _can_lower() and _lower_specials_step().
Browse files Browse the repository at this point in the history
The conditions in them were different: _can_lower() checked for
presence of the lower() override method, and _lower_specials_step()
would only lower the special if lower() is present and returns
something other than None.

Remove _can_lower() and instead lower specials until no more can
be lowered. This is also both simpler and faster.
  • Loading branch information
whitequark committed Dec 1, 2018
1 parent f5005b5 commit 01d9055
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions migen/fhdl/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,14 @@ def _lower_specials_step(overrides, specials):
return f, lowered_specials


def _can_lower(overrides, specials):
for special in specials:
cl = special.__class__
if cl in overrides:
cl = overrides[cl]
if hasattr(cl, "lower"):
return True
return False


def lower_specials(overrides, f):
lowered_specials = set()
while _can_lower(overrides, f.specials):
while True:
fs, lowered_specials_step = _lower_specials_step(overrides, f.specials)
f += fs
lowered_specials |= lowered_specials_step
f.specials -= lowered_specials_step
if lowered_specials_step:
lowered_specials |= lowered_specials_step
f.specials -= lowered_specials_step
else:
break
return f, lowered_specials

0 comments on commit 01d9055

Please sign in to comment.