From: whitequark Date: Wed, 12 Dec 2018 14:43:03 +0000 (+0000) Subject: fhdl.ast.Signal: implement .like(). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6ad2ba989bb99f1a3e71ed27e924d24ac26e3317;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