From: whitequark Date: Thu, 8 Aug 2019 07:45:34 +0000 (+0000) Subject: compat.fhdl.module: fix finalization of transformed compat submodules. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dc0461d40fd61da2bdb1bcdf8153a4ba830ca6a0;p=nmigen.git compat.fhdl.module: fix finalization of transformed compat submodules. Before this commit, the TransformedElaboratable of a CompatModule would be ignored, and .get_fragment() would be used to retrieve the CompatModule within. After this commit, the finalization process is reworked to match oMigen's finalization closely, and all submodules, native and compat, are added in the same way that preserves applied transforms. --- diff --git a/nmigen/compat/fhdl/module.py b/nmigen/compat/fhdl/module.py index f4622b0..4431b84 100644 --- a/nmigen/compat/fhdl/module.py +++ b/nmigen/compat/fhdl/module.py @@ -105,7 +105,9 @@ class CompatModule(ir.Elaboratable): return self._module def elaborate(self, platform): - return self.get_fragment() + if not self.get_fragment_called: + self.get_fragment() + return self._module def __getattr__(self, name): if name == "comb": @@ -137,22 +139,22 @@ class CompatModule(ir.Elaboratable): raise AttributeError("'{}' object has no attribute '{}'" .format(type(self).__name__, name)) - def _finalize_submodules(self, finalize_native): - for name, submodule in self._submodules: - if hasattr(submodule, "get_fragment_called"): - # Compat submodule - if not submodule.get_fragment_called: - self._module._add_submodule(submodule.get_fragment(), name) - elif finalize_native: - # Native submodule - self._module._add_submodule(submodule, name) - def finalize(self, *args, **kwargs): + def finalize_submodules(): + for name, submodule in self._submodules: + if not hasattr(submodule, "finalize"): + continue + if submodule.finalized: + continue + submodule.finalize(*args, **kwargs) + if not self.finalized: self.finalized = True - self._finalize_submodules(finalize_native=False) + finalize_submodules() self.do_finalize(*args, **kwargs) - self._finalize_submodules(finalize_native=True) + finalize_submodules() + for name, submodule in self._submodules: + self._module._add_submodule(submodule, name) def do_finalize(self): pass