From 1d4d00aac67fc0a9428b988c568aa575e53091e8 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 12 Dec 2018 14:43:03 +0000 Subject: [PATCH] fhdl.ast.Signal: implement .like(). --- nmigen/fhdl/ast.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 -- 2.30.2