gen/common: Add Unsigned/Signed Signal wrappers.

This commit is contained in:
Florent Kermarrec 2023-02-28 10:16:25 +01:00
parent 6ac8e9ec1f
commit 2f5481dbb9
1 changed files with 14 additions and 4 deletions

View File

@ -19,10 +19,6 @@ def colorer(s, color="bright"):
trailer = "\x1b[0m"
return header + str(s) + trailer
# Signals ------------------------------------------------------------------------------------------
class Open(Signal) : pass
# Bit/Bytes Reversing ------------------------------------------------------------------------------
def reverse_bits(s):
@ -34,6 +30,20 @@ def reverse_bytes(s):
return Cat(*[s[i*8:min((i + 1)*8, len(s))]
for i in reversed(range(n))])
# Signals ------------------------------------------------------------------------------------------
class Open(Signal): pass
class Unsigned(Signal):
def __init__(self, bits=1, *args, **kwargs):
assert isinstance(bits, int)
Signal.__init__(self, bits_sign=(bits, 0), *args, **kwargs)
class Signed(Signal):
def __init__(self, bits=1, *args, **kwargs):
assert isinstance(bits, int)
Signal.__init__(self, bits_sign=(bits, 1), *args, **kwargs)
# Reduction ----------------------------------------------------------------------------------------
from functools import reduce