From: whitequark Date: Sat, 22 Dec 2018 19:04:35 +0000 (+0000) Subject: hdl.ir: factor out _merge_subfragment. NFC. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1e596630c4ce6a75c46111bab96bcbcd4a134b3d;p=nmigen.git hdl.ir: factor out _merge_subfragment. NFC. --- diff --git a/nmigen/hdl/ir.py b/nmigen/hdl/ir.py index f9a4774..3105253 100644 --- a/nmigen/hdl/ir.py +++ b/nmigen/hdl/ir.py @@ -86,6 +86,25 @@ class Fragment: def get_fragment(self, platform): return self + def _merge_subfragment(self, subfragment): + # Merge subfragment's everything except clock domains into this fragment. + # Flattening is done after clock domain propagation, so we can assume the domains + # are already the same in every involved fragment in the first place. + self.ports.update(subfragment.ports) + for domain, signal in subfragment.iter_drivers(): + self.add_driver(signal, domain) + self.statements += subfragment.statements + self.subfragments += subfragment.subfragments + + # Remove the merged subfragment. + found = False + for i, (check_subfrag, check_name) in enumerate(self.subfragments): # :nobr: + if subfragment == check_subfrag: + del self.subfragments[i] + found = True + break + assert found + def _resolve_driver_conflicts(self, hierarchy=("top",), mode="warn"): assert mode in ("silent", "warn", "error") @@ -132,21 +151,9 @@ class Fragment: message += "; hierarchy will be flattened" warnings.warn_explicit(message, DriverConflict, *signal.src_loc) + # Flatten hierarchy. for subfrag, subfrag_hierarchy in sorted(flatten_subfrags, key=lambda x: x[1]): - # Merge subfragment's everything except clock domains into this fragment. - # Flattening is done after clock domain propagation, so we can assume the domains - # are already the same in every involved fragment in the first place. - self.ports.update(subfrag.ports) - for domain, signal in subfrag.iter_drivers(): - self.add_driver(signal, domain) - self.statements += subfrag.statements - self.subfragments += subfrag.subfragments - - # Remove the merged subfragment. - for i, (check_subfrag, check_name) in enumerate(self.subfragments): # :nobr: - if subfrag == check_subfrag: - del self.subfragments[i] - break + self._merge_subfragment(subfrag) # If we flattened anything, we might be in a situation where we have a driver conflict # again, e.g. if we had a tree of fragments like A --- B --- C where only fragments