mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-24 14:41:31 +00:00
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
This commit is contained in:
parent
9aa2dde7ef
commit
58e831486d
4 changed files with 36 additions and 24 deletions
28
tests/pyosys/test_sigspec_it.py
Normal file
28
tests/pyosys/test_sigspec_it.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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)};")
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue