Add common.deduce_ports, improve to_signed

This commit is contained in:
Peder Bergebakken Sundt 2020-08-19 16:34:16 +02:00
parent 8d2c12225b
commit b865a8d19a
1 changed files with 10 additions and 3 deletions

View File

@ -8,6 +8,13 @@ pipeline = data *: funcs -> data where
data = func data
# cast to signed, extending the signal by one bit
to_signed = signal -> out where
out = Signal$ signed (signal.width + 1)
Comb$ out ::= signal
to_signed = signal ->
Cat signal 0 |>.as_signed!
# only works before any elaboration, assuming ports are defined in __init__
deduce_ports = elaboratable -> ports where
ports = []
for name in dir elaboratable =>
if not$ name.startswith "_" =>
value = getattr elaboratable name
value :: Signal => ports.append value