From: whitequark Date: Wed, 12 Dec 2018 14:43:03 +0000 (+0000) Subject: fhdl.ast.Signal: implement .like(). X-Git-Tag: working~332 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1d4d00aac67fc0a9428b988c568aa575e53091e8;p=nmigen.git fhdl.ast.Signal: implement .like(). --- diff --git a/nmigen/fhdl/ast.py b/nmigen/fhdl/ast.py index 1f87e39..74aaadf 100644 --- a/nmigen/fhdl/ast.py +++ b/nmigen/fhdl/ast.py @@ -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