3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-11-23 14:11:28 +00:00
yosys/tests/pyosys/test_sigspec_it.py
Mohamed Gaber 58e831486d
pyosys: __getitem__ for supported classes
- functions that have a const `[]` operator method now support `__getitem__` in Python
- fields of a pointer type now return a `reference_internal` instead of a `copy` because classes referenced to by pointers typically aren't copyable (e.g. RTLIL::Wire, RTLIL::Module, etc)
- removed duplicate of test_script.py
2025-11-19 18:09:41 +02:00

28 lines
809 B
Python

from pyosys import libyosys as ys
from pathlib import Path
__file_dir__ = Path(__file__).absolute().parent
def _dump_sigbit(bit):
if bit.is_wire():
if bit.wire.width == 1:
return bit.wire.name.str()
else:
return f"{bit.wire.name} [{bit.offset}]"
else:
if bit.data == ys.State.S1:
return 1
elif bit.data == ys.State.S0:
return 0
else:
assert "unknown constants not supported"
d = ys.Design()
ys.run_pass(f"read_verilog {__file_dir__ / 'spm.cut.v.gz'}", d)
ys.run_pass(f"hierarchy -top spm", d)
module = d.module(r"\spm")
for conn_from, conn_to in module.connections_:
for bit_from, bit_to in zip(conn_from, conn_to):
print(f"assign {_dump_sigbit(bit_from)} = {_dump_sigbit(bit_to)};")