Registry / data / pyverilog

pyverilog

JSON →
library1.3.0pypypiunverified

Pyverilog is a Python-based Hardware Design Processing Toolkit for Verilog HDL, providing a parser, dataflow analyzer, controlflow analyzer, and code generator. It allows users to parse Verilog code into an Abstract Syntax Tree (AST), analyze its structure, and extract design information. The current version is 1.3.0, and releases occur periodically, typically every few months, addressing bugs and adding new features.

pip install pyverilog ply
INSTALL
IMPORT
SIG · PYVERILOG
P
pyverilog
datapythonv1.3.0
Install
3.0s avg
Import
71ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
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
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.073s · 22.2MB
glibc
py 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
Debug
Known issues
breakingThe `ply` library, a core dependency for Verilog parsing, is no longer bundled with Pyverilog since version 1.3.0. Users upgrading from prior versions will encounter `ModuleNotFoundError` if `ply` is not installed separately.
fix
Explicitly install `ply` using `pip install ply` alongside `pyverilog`.
affects: >=1.3.0
breakingPython 2 support was officially disabled in version 1.1.3. Pyverilog now exclusively supports Python 3.
fix
Ensure you are using Python 3.x. Upgrade your Python environment if necessary.
affects: >=1.1.3
gotchaFor features like Verilog preprocessor (`-p` or `preprocess=True` in `VerilogParser`) which handle `include` directives or macros, the external tool `Icarus Verilog` (specifically the `iverilog` command) must be installed and accessible in your system's PATH.
fix
Install Icarus Verilog on your operating system and verify `iverilog` is available in your command-line PATH.
affects: all
breakingIn version 1.2.0, the `subprocess.call()` method used within the preprocessor no longer uses `shell=True` for security reasons. This could affect users who relied on specific shell behaviors or complex custom `iverilog` commands that implicitly leveraged shell features.
fix
Review any custom preprocessor configurations or `iverilog` commands passed to Pyverilog to ensure they function correctly without `shell=True`. Adjust commands to be direct arguments rather than shell constructs.
affects: >=1.2.0
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.
Agent activity
11 hits · last 30 days
node
10
Resources
pyverilog — pip install pyverilog · libregistry