Skip to content

Commit 0c3041f

Browse files
committed
Update output_to_verilog to inline single-use temporaries, using GateGraph:
- Any Gate with a user-specified name is never inlined. - Unnamed constant Gates are always inlined. - Unnamed non-constant Gates are inlined if: - The Gate has one user, AND - The Gate is not a MemBlock read, AND - The Gate is not an arg to a bit-select Gate. Also: - Update `output_verilog_testbench` to use `GateGraph`. - Define `GateGraph.__iter__` to make it easier to iterate over all Gates. - Delete some disabled tests in `test_aes.py`.
1 parent 3deeedd commit 0c3041f

4 files changed

Lines changed: 670 additions & 856 deletions

File tree

pyrtl/gate_graph.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,3 +1114,25 @@ def __str__(self) -> str:
11141114
self.gates, key=lambda gate: gate.name if gate.name else "~~~"
11151115
)
11161116
return "\n".join([str(gate) for gate in sorted_gates])
1117+
1118+
def __iter__(self):
1119+
"""Iterate over each gate in the :class:`GateGraph`.
1120+
1121+
.. doctest only::
1122+
1123+
>>> import pyrtl
1124+
>>> pyrtl.reset_working_block()
1125+
1126+
Example::
1127+
1128+
>>> a = pyrtl.Input(name="a", bitwidth=2)
1129+
>>> b = pyrtl.Input(name="b", bitwidth=2)
1130+
>>> sum = a + b
1131+
>>> sum.name = "sum"
1132+
1133+
>>> gate_graph = pyrtl.GateGraph()
1134+
1135+
>>> sorted(gate.name for gate in gate_graph)
1136+
['a', 'b', 'sum']
1137+
"""
1138+
return iter(self.gates)

0 commit comments

Comments
 (0)