Skip to content

Commit 44c6e52

Browse files
jordenssbourdeauducq
authored andcommittedJul 25, 2014
migen.fhdl.structure: add Signal.like(other)
This is a convenience method. Signal(flen(other)) is used frequently but that drops the signedness. Signal((other.nbits, other.signed)) would be correct but is long.
1 parent 9fcea6e commit 44c6e52

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎migen/fhdl/structure.py

+14
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,20 @@ def __init__(self, bits_sign=None, name=None, variable=False, reset=0, name_over
274274
def __repr__(self):
275275
return "<Signal " + (self.backtrace[-1][0] or "anonymous") + " at " + hex(id(self)) + ">"
276276

277+
@classmethod
278+
def like(cls, other):
279+
"""Create Signal based on another.
280+
281+
Parameters
282+
----------
283+
other : Value
284+
Object to base this Signal on.
285+
286+
See `migen.fhdl.bitcontainer.value_bits_sign`() for details.
287+
"""
288+
from migen.fhdl.bitcontainer import value_bits_sign
289+
return cls(value_bits_sign(other))
290+
277291
class ClockSignal(Value):
278292
"""Clock signal for a given clock domain
279293

0 commit comments

Comments
 (0)
Please sign in to comment.