fhdl.ast.Signal: implement .like().
authorwhitequark <cz@m-labs.hk>
Wed, 12 Dec 2018 14:43:03 +0000 (14:43 +0000)
committerwhitequark <cz@m-labs.hk>
Wed, 12 Dec 2018 14:43:19 +0000 (14:43 +0000)
nmigen/fhdl/ast.py

index 1f87e391929658740d026ad0cb9a0cf10dcd9803..74aaadfa9001a5889b351aceca788aa3ed326161 100644 (file)
@@ -553,6 +553,21 @@ class Signal(Value, DUID):
 
         self.attrs = OrderedDict(() if attrs is None else attrs)
 
+    @classmethod
+    def like(cls, other, **kwargs):
+        """Create Signal based on another.
+
+        Parameters
+        ----------
+        other : Value
+            Object to base this Signal on.
+        """
+        kw = dict(bits_sign=cls.wrap(other).bits_sign())
+        if isinstance(other, cls):
+            kw.update(reset=other.reset.value, reset_less=other.reset_less, attrs=other.attrs)
+        kw.update(kwargs)
+        return cls(**kw)
+
     def bits_sign(self):
         return self.nbits, self.signed