From b862b070d6283525424a57a1a714beb05e242b71 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 25 Apr 2013 14:56:26 +0200 Subject: [PATCH] fhdl/verilog: recursive Special lowering --- migen/fhdl/verilog.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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): -- 2.30.2