Skip to content

Commit 5d5cdea

Browse files
committed
Initial implementation of GateGraph, an alternative PyRTL logic representation:
`GateGraph` attempts to address several issues with PyRTL's standard `WireVector` and `LogicNet` representation: 1. A `GateGraph` can be directly traversed, without the help of side data structures like the `wire_src_dict` and `wire_sink_dict` returned by `net_connections`. 2. `GateGraph` builds a graph where each node is a `Gate`, and the edges are all references to other `Gates`. By using only one node type, rather than two (`WireVector`, `LogicNet`), it becomes easier to work with the nodes in a `GateGraph`, because every node is the same type, with the same interface. 3. `GateGraph` decouples the user interface and the internal representation. Users directly instantiate `WireVectors` as they build circuits. A user that is only building circuits should never interact with a `GateGraph` or a `Gate`. Users should only interact with `GateGraph` when they need reflection, which typically happens when writing an analysis or optimization pass. Another advantage of this decoupling is that `Gate` does not need to support `WireVector`'s quality-of-life features for users, like inferring bitwidth from assignment.
1 parent 370aa4b commit 5d5cdea

4 files changed

Lines changed: 993 additions & 0 deletions

File tree

docs/blocks.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,17 @@ LogicNets
3434
.. autoclass:: pyrtl.LogicNet
3535
:members:
3636
:undoc-members:
37+
38+
GateGraphs
39+
----------
40+
41+
.. automodule:: pyrtl.gate_graph
42+
43+
.. autoclass:: pyrtl.Gate
44+
:members:
45+
:special-members: __init__, __str__
46+
47+
.. autoclass:: pyrtl.GateGraph
48+
:members:
49+
:special-members: __init__, __str__
50+

pyrtl/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# convenience classes for building hardware
2020
from .wire import WireVector, Input, Output, Const, Register
2121

22+
from .gate_graph import GateGraph, Gate
23+
2224
# helper functions
2325
from .helperfuncs import (
2426
input_list,
@@ -160,6 +162,9 @@
160162
"Output",
161163
"Const",
162164
"Register",
165+
# gate_graph
166+
"GateGraph",
167+
"Gate",
163168
# helperfuncs
164169
"input_list",
165170
"output_list",

0 commit comments

Comments
 (0)