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.
This commit is contained in:
whitequark 2019-08-08 07:45:34 +00:00
parent 1b379a513c
commit 5c626e33bf

View file

@ -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