UCSBarchlab / PyRTL

A collection of classes providing simple hardware specification, simulation, tracing, and testing suitable for teaching and research. Simplicity, usability, clarity, and extensibility are the overarching goals, rather than performance or optimization.
http://ucsbarchlab.github.io/PyRTL
BSD 3-Clause "New" or "Revised" License
257 stars 78 forks source link

Remove `replace_wire`, use `replace_wire_fast` instead; add tests and more documentation #347

Closed mdko closed 3 years ago

mdko commented 3 years ago

replace_wire is incorrect, I believe. In line 101, it uses new_src when it should be using new_dst. In addition, iterating over block.logic in lines 85 and 96 causes alterations to block.logic in lines 92 and 103, respectively, to cause a "Set changed size during iteration" error.

In addition, this was only used in wire_transform, which has a single unit test. I think we can instead just use and export replace_wire_fast and replace_wires, and use replace_wire_fast where replace_wire was used in wire_transform.

mdko commented 3 years ago

Question: should we also make a wrapper function, replace_wire(orig_wire, new_wire, block=None), that just callsreplace_wires({orig_wire: new_wire}, block=block)? If not, we should instead rename replace_wire_fast to replace_wire.