From: Sebastien Bourdeauducq Date: Thu, 25 Apr 2013 12:56:26 +0000 (+0200) Subject: fhdl/verilog: recursive Special lowering X-Git-Tag: 24jan2021_ls180~2099^2~600 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b862b070d6283525424a57a1a714beb05e242b71;p=litex.git fhdl/verilog: recursive Special lowering --- diff --git a/migen/fhdl/verilog.py b/migen/fhdl/verilog.py index 748db5b2..6708bdff 100644 --- a/migen/fhdl/verilog.py +++ b/migen/fhdl/verilog.py @@ -230,7 +230,7 @@ def _call_special_classmethod(overrides, obj, method, *args, **kwargs): else: return None -def _lower_specials(overrides, specials): +def _lower_specials_step(overrides, specials): f = Fragment() lowered_specials = set() for special in sorted(specials, key=lambda x: x.huid): @@ -240,6 +240,24 @@ def _lower_specials(overrides, specials): lowered_specials.add(special) 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, specials): + f, lowered_specials = _lower_specials_step(overrides, specials) + while _can_lower(overrides, f.specials): + f2, lowered_specials2 = _lower_specials_step(overrides, f.specials) + f += f2 + lowered_specials |= lowered_specials2 + f.specials -= lowered_specials2 + return f, lowered_specials + def _printspecials(overrides, specials, ns): r = "" for special in sorted(specials, key=lambda x: x.huid):