compat.fhdl.module: allow adding native submodules to compat modules.
authorwhitequark <cz@m-labs.hk>
Fri, 14 Dec 2018 23:40:15 +0000 (23:40 +0000)
committerwhitequark <cz@m-labs.hk>
Fri, 14 Dec 2018 23:56:50 +0000 (23:56 +0000)
nmigen/compat/fhdl/module.py
nmigen/compat/fhdl/specials.py
nmigen/fhdl/__init__.py

index 1b543ea5db661782b0532a8f0908c211e10e973d..53ff6b438142816cff303bd2d390bdf0023917ae 100644 (file)
@@ -61,12 +61,12 @@ class _CompatModuleSync(_CompatModuleProxy):
 class _CompatModuleSpecials(_CompatModuleProxy):
     @deprecated("instead of `self.specials.<name> =`, use `m.submodules.<name> =`")
     def __setattr__(self, name, value):
-        self._cm._specials.append((name, value))
+        self._cm._submodules.append((name, value))
         setattr(self._cm, name, value)
 
     @deprecated("instead of `self.specials +=`, use `m.submodules +=`")
     def __iadd__(self, other):
-        self._cm._specials += [(None, e) for e in _flat_list(other)]
+        self._cm._submodules += [(None, e) for e in _flat_list(other)]
         return self
 
 
@@ -135,14 +135,15 @@ class CompatModule:
             raise AttributeError("'{}' object has no attribute '{}'"
                                  .format(type(self).__name__, name))
 
-    def _finalize_specials(self):
-        for name, special in self._specials:
-            self._module._add_submodule(special, 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)
+            if hasattr(submodule, "get_fragment_called"):
+                # Compat submodule
+                if not submodule.get_fragment_called:
+                    self._module._add_submodule(submodule.get_fragment(), name)
+            else:
+                # Native submodule
+                self._module._add_submodule(submodule, name)
 
     def finalize(self, *args, **kwargs):
         if not self.finalized:
index e401ecfcc070bfa639adf0b4f9f88f58fbc689d9..c60ee21cc4dee9bce55aaef474449ebc596682fe 100644 (file)
@@ -1,10 +1,10 @@
-from ...genlib.io import TSTriple as NewTSTriple
+from ...genlib.io import TSTriple as NativeTSTriple
 
 
 __all__ = ["TSTriple"]
 
 
-class CompatTSTriple(NewTSTriple):
+class CompatTSTriple(NativeTSTriple):
     def __init__(self, bits_sign=None, min=None, max=None, reset_o=0, reset_oe=0, reset_i=0,
                  name=None):
         super().__init__(shape=bits_sign, min=min, max=max,
index c411310821193fb41800bf182a2e47c33ccff954..cc83fb5821546a114c6144f2c556e5c8fcffe03c 100644 (file)
@@ -1,4 +1,5 @@
 from .cd import ClockDomain
 from .ast import Value, Const, Mux, Cat, Repl, Signal, ClockSignal, ResetSignal
+from .ir import Fragment
 from .dsl import Module
 from .xfrm import ResetInserter, CEInserter