Skip to main content

A comprehensive Python framework for parsing Verilog code and generating circuit diagrams (Verilog Parser + Circuit Visualization)

Project description

DooPourd - Verilog Parser & Circuit Diagram Generator

A comprehensive Python framework for parsing Verilog code and generating circuit diagrams (SVG/PNG).

GitHub: https://github.com/Dev-vesper/DooPourd
PyPI: https://pypi.org/project/DooPourd/
License: MIT

Features

  • Verilog Parsing - Parse Verilog modules into Abstract Syntax Trees (AST)
  • Lexical Analysis - Tokenize Verilog with full support for keywords, identifiers, operators
  • Circuit Diagrams - Generate SVG and PNG circuit diagrams from Verilog
  • AST Visualization - Generate graphical representation of code structure
  • Logging System - Built-in debugging with detailed logs
  • Command-Line Tool - Use via CLI without coding
  • Cross-Platform - Works on Windows, Linux, macOS

Directory Structure

verilog_framework/
├── core/                      # Parser and Lexer components
│   ├── ast_nodes.py          # AST node definitions
│   ├── lexer.py              # Tokenization engine
│   └── parser.py             # Syntax parser
├── visualization/            # Graph and diagram generation
│   ├── visitor.py            # AST visitor pattern implementation
│   └── visualizer.py         # Graphviz-based visualization
├── verilogtoimage/          # Circuit diagram generation
│   ├── logger.py            # Logging utilities
│   ├── converters.py        # Yosys, netlistsvg, CairoSVG converters
│   └── pipeline.py          # Image generation pipeline
└── utils/                    # Utility functions

Installation

⏃ Easiest: Using Docker (All platforms!)

Windows, macOS, Linux - Works identically!

git clone https://github.com/Dev-vesper/DooPourd.git
cd DooPourd
docker-compose up -d
docker-compose exec doopound bash

Everything (Yosys, netlistsvg, Python) pre-installed!


💻 Windows Only - No Docker Needed!

See WINDOWS_SETUP.md for complete Windows native setup.

# Quick:
pip install DooPourd[all]
# Then install Yosys from: https://github.com/YosysHQ/oss-cad-suite/releases
# And: npm install -g netlistsvg

Basic Installation (Parsing Only - Lightweight!)

Works on Windows, Linux, macOS with just Python:

pip install DooPourd

This includes:

  • ✅ Verilog parsing (lexer + parser)
  • ✅ AST generation
  • ✅ Port/declaration analysis

No external dependencies required!

With Visualization (Optional)

To visualize code structure as graphs:

pip install DooPourd[graph]

With Circuit Diagrams (Optional - Requires Linux/WSL)

To generate circuit diagrams (SVG/PNG):

pip install DooPourd[circuit]

Also requires Yosys and netlistsvg (Linux/WSL only):

# On Ubuntu/Debian WSL:
sudo apt-get install yosys netlistsvg

# Or use Docker:
docker run -it ubuntu:22.04 bash
apt-get update && apt-get install -y yosys npm
npm install -g netlistsvg

All Features

pip install DooPourd[all]

From source

git clone https://github.com/Dev-vesper/DooPourd.git
cd DooPourd
pip install -e .

Quick Start

✅ Works Everywhere (Windows/Linux/macOS)

The first 3 examples work with basic installation on any OS:

from verilog_framework.core import parse_verilog

# Your Verilog code
verilog_code = """
module adder(input a, input b, output sum);
    assign sum = a + b;
endmodule
"""

# Parse it
ast = parse_verilog(verilog_code)

# Get information
print(f"Module name: {ast.name}")
print(f"Number of ports: {len(ast.port_list)}")
print(f"Number of statements: {len(ast.statements)}")

2. Parse from File

from pathlib import Path
from verilog_framework.core import parse_verilog

# Read Verilog file
code = Path("my_module.v").read_text()

# Parse
ast = parse_verilog(code)

print(f"Module: {ast.name}")

3. Get Port Information

from verilog_framework.core import parse_verilog

code = """
module counter(
    input clk,
    input reset,
    output [7:0] count
);
    reg [7:0] count;
endmodule
"""

ast = parse_verilog(code)

# Get inputs
inputs = [p.name for p in ast.port_list if p.direction == 'input']
print(f"Inputs: {inputs}")

# Get outputs
outputs = [p.name for p in ast.port_list if p.direction == 'output']
print(f"Outputs: {outputs}")

Output:

Inputs: ['clk', 'reset']
Outputs: ['count']

🔧 Windows/Linux/macOS - Stop Here! ✅

Above examples (1-3) work on any OS! Continue with example 4 only if you have Linux/WSL.


4️⃣ Generate Circuit Diagram (Linux/WSL Only - Optional)

from verilog_framework.verilogtoimage import VerilogToImagePipeline

code = """
module full_adder(
    input a,
    input b,
    input cin,
    output sum,
    output cout
);
    assign sum = a ^ b ^ cin;
    assign cout = (a & b) | (cin & (a ^ b));
endmodule
"""

# Create pipeline
pipeline = VerilogToImagePipeline()

# Generate SVG
svg_file = pipeline.verilog_to_svg(code, "adder.svg")
print(f"SVG saved: {svg_file}")

# Generate PNG (requires CairoSVG)
try:
    png_file = pipeline.verilog_to_png(code, "adder.png")
    print(f"PNG saved: {png_file}")
except Exception as e:
    print(f"PNG generation skipped: {str(e)[:60]}")

Requires Linux/WSL:

sudo apt-get install yosys netlistsvg
pip install DooPourd[circuit]

5️⃣ Visualize Code Structure (Optional)

from verilog_framework.core import parse_verilog
from verilog_framework.visualization import GraphvizVisualizer

code = """
module test(input a, output b);
    assign b = a;
endmodule
"""

ast = parse_verilog(code)
visualizer = GraphvizVisualizer()
dot_code = visualizer.generate_dot(ast)

# Save to file
with open("structure.dot", "w") as f:
    f.write(dot_code)
    
print("Structure saved to structure.dot")

# Render to PNG (requires Graphviz installed)
try:
    import subprocess
    subprocess.run(["dot", "-Tpng", "structure.dot", "-o", "structure.png"])
    print("PNG rendered: structure.png")
except:
    print("Install Graphviz to render PNG")

Optional (for rendering to PNG):

# Ubuntu/WSL:
sudo apt-get install graphviz
# Or macOS:
brew install graphviz

Windows Support ✅

Good news: DooPourd core parsing works perfectly on Windows!

Feature Windows macOS Linux
Parse Verilog
Extract AST
Analyze modules
Graphviz visualization ⚠️ Need graphviz
Circuit diagrams (PNG) ⚠️ WSL only

Just install with: pip install DooPourd

No Yosys, no external tools needed!

Supported Verilog Features

Feature Supported
Module declarations
Ports (input/output/inout)
Wire declarations
Reg declarations
Continuous assignments
Always blocks
Always @(posedge/negedge)
Expressions (binary/unary)
Comments
Multi-line code

Note: Some advanced Verilog features (functions, tasks, generate blocks) are not yet supported.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doopourd-0.7.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

doopourd-0.7.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file doopourd-0.7.0.tar.gz.

File metadata

  • Download URL: doopourd-0.7.0.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for doopourd-0.7.0.tar.gz
Algorithm Hash digest
SHA256 a1d3b6072edd6ac2054e40ab85f44cfef5cb3afb1828251dd12796d0908110c8
MD5 d23ec6b80679391b2a9ca4343d388654
BLAKE2b-256 2899a44c2f54b702c4090e287127bc6e0fb3ca6c57b8176162e69d713db9fc0f

See more details on using hashes here.

File details

Details for the file doopourd-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: doopourd-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for doopourd-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1c1fbce8d0f324051af692fc5ee18793bb7b479070af3aff9df1f7cd5bea743
MD5 15f3cd163f6a59a5baa148f42fe894e8
BLAKE2b-256 815711e888ae119fd1a373147e357ce06b094deaa5055a1e1fc787309efd64af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page