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

Be able to show multiplicity of identical edges going to a net #358

Closed mdko closed 3 years ago

mdko commented 3 years ago

Problem

When the same wire is the source to a particular net multiple times (e.g. a c net), net_graph(), and by extension all the graphical output functions that use it like output_to_graphviz(), don't properly display the additional edges.

For example, given:

import pyrtl

c = pyrtl.Const(1, 1)
o = pyrtl.Output(3, 'o')
o <<= pyrtl.concat(c, c, c)

the logic of block is:

for net in pyrtl.working_block():
    print(net)
tmp0/3W <-- c -- const_0_1/1C, const_0_1/1C, const_0_1/1C 
o/3O <-- w -- tmp0/3W 

however the result of net_graph() previously was:

for src, vals in pyrtl.net_graph().items():
    for dst, edge in vals.items():
        print(f"({src}) - {edge} -> ({dst})"
(o/3O <-- w -- tmp0/3W ) - o/3O -> (o/3O)
(tmp0/3W <-- c -- const_0_1/1C, const_0_1/1C, const_0_1/1C ) - tmp0/3W -> (o/3O <-- w -- tmp0/3W )
(const_0_1/1C) - const_0_1/1C -> (tmp0/3W <-- c -- const_0_1/1C, const_0_1/1C, const_0_1/1C )

This problem is evident in the visual output as well: graph

Solution

net_graph has been updated so that there are lists of edges between nodes.

for src, vals in pyrtl.net_graph().items():
    for dst, edges in vals.items():
        for edge in edges:
            print(f"({src}) - {edge} -> ({dst})")

producing

(tmp0/3W <-- c -- const_0_1/1C, const_0_1/1C, const_0_1/1C ) - tmp0/3W -> (o/3O <-- w -- tmp0/3W )
(o/3O <-- w -- tmp0/3W ) - o/3O -> (o/3O)
(const_0_1/1C) - const_0_1/1C -> (tmp0/3W <-- c -- const_0_1/1C, const_0_1/1C, const_0_1/1C )
(const_0_1/1C) - const_0_1/1C -> (tmp0/3W <-- c -- const_0_1/1C, const_0_1/1C, const_0_1/1C )
(const_0_1/1C) - const_0_1/1C -> (tmp0/3W <-- c -- const_0_1/1C, const_0_1/1C, const_0_1/1C )

It now looks like: graph

mdko commented 3 years ago

Here's another quick example:

Before

before

After

after

mdko commented 3 years ago

Fixes #357