raise AttributeError("Attempted to assign sync property - use += instead")
-class _CompatModuleForwardAttr:
+class _CompatModuleSpecials(_CompatModuleProxy):
@deprecated("TODO")
def __setattr__(self, name, value):
self.__iadd__(value)
setattr(self._cm, name, value)
-
-class _CompatModuleSpecials(_CompatModuleProxy, _CompatModuleForwardAttr):
@deprecated("TODO")
def __iadd__(self, other):
self._cm._fragment.specials |= set(_flat_list(other))
class _CompatModuleSubmodules(_CompatModuleProxy):
- @deprecated("TODO")
+ @deprecated("instead of `self.submodules.<mod> =`, use `m.submodules.<mod> =`")
def __setattr__(self, name, value):
self._cm._submodules += [(name, e) for e in _flat_list(value)]
setattr(self._cm, name, value)
- @deprecated("TODO")
+ @deprecated("instead of `self.submodules +=`, use `m.submodules +=`")
def __iadd__(self, other):
self._cm._submodules += [(None, e) for e in _flat_list(other)]
return self
-class _CompatModuleClockDomains(_CompatModuleProxy, _CompatModuleForwardAttr):
+class _CompatModuleClockDomains(_CompatModuleProxy):
+ @deprecated("TODO")
+ def __setattr__(self, name, value):
+ self.__iadd__(value)
+ setattr(self._cm, name, value)
+
@deprecated("TODO")
def __iadd__(self, other):
self._cm._fragment.clock_domains += _flat_list(other)
class CompatModule:
+ # Actually returns nmigen.fhdl.Module, not a Fragment.
def get_fragment(self):
assert not self.get_fragment_called
self.get_fragment_called = True
self.finalize()
- return self._fragment
+ return self._module
def __getattr__(self, name):
if name == "comb":
raise AttributeError("'{}' object has no attribute '{}'"
.format(type(self).__name__, name))
+ def _finalize_submodules(self):
+ for name, submodule in self._submodules:
+ if not submodule.get_fragment_called:
+ self._module._add_submodule(submodule.get_fragment(), name)
+
+ def finalize(self, *args, **kwargs):
+ if not self.finalized:
+ self.finalized = True
+ self._finalize_submodules()
+ self.do_finalize(*args, **kwargs)
+ self._finalize_submodules()
+
+ def do_finalize(self):
+ pass
+
Module = CompatModule
if name in ("comb", "sync"):
raise AttributeError("'{}' object has no attribute '{}'; did you mean 'd.{}'?"
.format(type(self).__name__, name, name))
+ raise AttributeError("'{}' object has no attribute '{}'"
+ .format(type(self).__name__, name))
class _ModuleBuilderIf(_ModuleBuilderRoot):
def _add_submodule(self, submodule, name=None):
if not hasattr(submodule, "get_fragment"):
raise TypeError("Trying to add {!r}, which does not have .get_fragment(), as "
- " a submodule")
+ "a submodule".format(submodule))
self._submodules.append((submodule, name))
def lower(self, platform):
for lhs_signal in signal._lhs_signals():
fragment.drive(lhs_signal, cd_name)
return fragment
+
+ get_fragment = lower