This is a Python-based AI tool that takes natural language prompts and generates Verilog hardware modules and testbenches using OpenAI GPT-4. It then automatically compiles, simulates, and visualizes the resulting design using Icarus Verilog and waveform generation.
You can either:
- Use the Streamlit web interface, or
- Use the command-line script (CLI)
-
Natural Language to Verilog
Enter prompts like"4-bit full adder"and get clean, syntactically correct Verilog modules. -
Powered by GPT-4 via OpenAI API
Uses your OpenAI key to generate both the module and a corresponding testbench. -
Testbench Enhancement
Injects$monitor,$dumpfile,$dumpvars, and$finishif missing — making testbenches simulation-ready. -
Automatic Simulation
Compiles and simulates the design using Icarus Verilog (iverilog + vvp). -
Waveform Generation
Dumps simulation data to a VCD file (wave.vcd) viewable in GTKWave or as a PNG (via matplotlib — still improving). -
Modular Design Comes with both a Streamlit GUI and a lightweight CLI script.
- Run the app locally (
streamlit run streamlit_app.py) - Enter your OpenAI API key and hardware prompt
- App:
- Calls GPT-4 to generate module and testbench
- Validates and patches testbench if needed
- Lets you view, download, and simulate your design
- After simulation:
- Shows console output
- Generates
wave.vcd - Plots waveform as a PNG (basic version)
- Optionally download waveform file to open in GTKWave
- Add your OpenAI API key in the script (
openai.api_key = "sk-...") - Run the script (
python verilog_cli_generator.py) - Flow:
- Asks you for a hardware design prompt
- GPT returns module + testbench
- Automatically saves
.vfiles in current directory - Asks if you want to simulate using
iverilog - If yes, runs simulation and creates
wave.vcd - Asks if you want to open waveform in GTKWave
| Tool | Required | Description |
|---|---|---|
| Python 3.8+ | Yes | For both CLI and Streamlit |
| OpenAI API key | Yes | To access GPT-4 via OpenAI API |
| Icarus Verilog | Yes | Icarus Verilog compiler and simulator |
| gtkwave | Optional | For viewing wave.vcd (CLI + Streamlit) |
| matplotlib | Optional | For waveform plotting in Streamlit app |
| vcdvcd | Optional | VCD parsing library for PNG generation |
To use either version, you'll need an OpenAI API key.
- Go to https://platform.openai.com/account/api-keys
- Click Create new secret key
- Copy the key
- In Streamlit: Paste the key into the app when prompted
- In CLI: Replace
"sk-..."in the script:openai.api_key = "sk-..."
Note: GPT-4 access requires a paid account
- Clone the repository:
git clone https://github.com/YOUR_USERNAME/verilog-ai-agent.git cd verilog-ai-agent/streamlit_app - Install Python dependencies:
pip install -r requirements.txt
- Run the app:
streamlit run streamlit_app.py
Once running:
- Enter your OpenAI API key
- Enter a prompt like "3-bit up counter"
- Click Generate
- Click Run Simulation
- View results, waveform, and download files
- Clone the repository:
git clone https://github.com/YOUR_USERNAME/verilog-ai-agent.git cd verilog-ai-agent/cli_version
2.Add your API key to the script
- Install Python dependencies:
pip install -r requirements.txt
- Run the script:
python verilog_cli_generator.py
Once running, you will be prompted to:
- Hardware prompt
- Simulation option
- Whether to view waveform in GTKWave
├── streamlit_app/
│ ├── streamlit_app.py # Main Streamlit code
│ ├── requirements.txt # Python dependencies
│ ├── waveform.png # Rendered waveform (optional)
│ ├── wave.vcd # Simulation output
│ └── *.v # Generated Verilog + Testbench
│
├── cli_version/
│ └── verilog_cli_generator.py # Simple CLI version
- Waveform visualization is a work in progress — matplotlib rendering is still being improved.
- Use GTKWave (gtkwave wave.vcd) for detailed signal visualization
- The tool assumes a valid module/testbench is generated; please check logs if simulation fails
As a student passionate about both AI and hardware design, I built this tool to explore hardware-software co-design. It reflects my interest in bridging LLMs with digital design and using Python to streamline RTL workflows.
It lets me:
- Apply generative AI in an EDA context
- Automate repetitive design + simulation tasks
- Build practical AI tooling for Verilog users