Install & Compatibility
Where this runs
tested against v1.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.073s · 22.2MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.0s · import 0.069s · 23MB
20MB installed
● package 20MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
VerilogParser
✓ from pyverilog.vparser.parser import VerilogParser
vast
✓ import pyverilog.vparser.ast as vast
DataflowAnalyzer
✓ from pyverilog.dataflow.dataflow import DataflowAnalyzer
DotGraph
✓ from pyverilog.dataflow.graph import DotGraph
This quickstart demonstrates how to parse a simple Verilog module into an Abstract Syntax Tree (AST) using `VerilogParser`, and then perform a basic dataflow analysis using `DataflowAnalyzer`. It prints key nodes from the AST and basic information from the dataflow graph. To visualize the dataflow graph as an image, you would also need to install Graphviz and use `DotGraph` to write a '.dot' file which can then be rendered externally.
import os
from pyverilog.vparser.parser import VerilogParser
import pyverilog.vparser.ast as vast
from pyverilog.dataflow.dataflow import DataflowAnalyzer
from pyverilog.dataflow.graph import DotGraph
# Create a dummy Verilog file for parsing
verilog_code = """
module test_module (input clk, input rst, output reg [7:0] count);
always @(posedge clk or posedge rst) begin
if (rst) begin
count <= 8'h00;
end else begin
count <= count + 1;
end
end
endmodule
"""
with open('example.v', 'w') as f:
f.write(verilog_code)
# 1. Parse the Verilog file into an AST
parser = VerilogParser()
ast = parser.parse(['example.v'])
print("--- Verilog AST --- ")
# ast.show() # Uncomment to print the full AST
# 2. Perform Dataflow Analysis
analyzer = DataflowAnalyzer()
analyzer.visit(ast)
# Get dataflow graph and print some nodes
dfg = analyzer.get_dfg()
print("\n--- Dataflow Analysis (some nodes) ---")
for node_id, node in dfg.items():
if isinstance(node_id, vast.Port) or isinstance(node_id, vast.Reg):
print(f"Node: {node_id.name}, Type: {type(node_id).__name__}, Defs: {len(node.definitions)}")
# 3. Generate a DOT graph (requires graphviz and dot command)
# try:
# graph = DotGraph(dfg)
# graph.write_dot('dfg.dot')
# print("\nDataflow graph written to dfg.dot (requires Graphviz to visualize).")
# except Exception as e:
# print(f"\nCould not generate DOT graph: {e} (Is Graphviz installed?)")
# Clean up the dummy file
os.remove('example.v')
pyverilog --version
Upgrade
Version history
1.3.0latest on PyPI · released Dec 30, 2020
Audit
Dependencies
plyrequiredRequired for parsing Verilog. As of v1.3.0, it is no longer bundled and must be installed separately.
Icarus Verilog (iverilog)optionalAn external tool often required by Pyverilog's preprocessor for handling Verilog 'include' directives and macros. Must be installed separately on the system PATH.