๐ง What is Verilator? #
Verilator is an open-source simulator that converts Verilog HDL (Hardware Description Language) code into high-performance C++ or SystemC code. It is primarily used for hardware modeling and verification. Unlike other HDL simulators, Verilator is designed for cycle-accurate, synthesizable Verilog code.
๐ Key Features of Verilator #
- Translates Verilog into high-speed C++/SystemC models.
- Offers excellent performance for large-scale designs.
- Open source under the GNU GPL license.
- Supports waveform generation and debugging.
- Suitable for FPGA and ASIC development flows.
๐ ๏ธ Verilator Installation Guide #
There are several ways to install Verilator: prebuilt packages, source build, or package managers.
๐ง 1. Installing on WSL (Ubuntu) or Native Linux #
Step 1: Install Required Dependencies #
Run the following in your terminal:
sudo apt update
sudo apt install git make autoconf g++ flex bison libfl2 libfl-dev zlib1g zlib1g-dev
Step 2: Clone Verilator Source Code #
git clone https://github.com/verilator/verilator.git
cd verilator
Step 3: Checkout Stable Version & Build #
git checkout stable
๐ If you encounter an error related to
help2man
, it’s because the utility used for generating man pages is missing.
Fix: Install help2man
#
sudo apt install help2man -y
Step 4: Build and Install #
autoconf
./configure
make -j$(nproc)
sudo make install
Step 5: Verify Installation #
verilator --version
๐ช 2. Installing on Windows (via WSL) #
- Install WSL and a Linux distribution (e.g., Ubuntu). WSL Setup Guide
- Open the WSL terminal and follow the Linux installation steps above.
๐ 3. Installing on macOS #
Using Homebrew #
brew update
brew install verilator
verilator --version
๐ป 4. Installing on Native Windows #
Verilator cannot run natively on Windows without a Linux-like environment. Use:
- WSL
- Cygwin
- Virtual Machine
- Docker
๐ Verilator Usage Example #
Step 1: Create a Verilog Design #
// hello.v
module hello(input logic clk, output logic led);
always @(posedge clk) led <= ~led;
endmodule
Step 2: Simulate with Verilator #
1. Generate C++ Model #
verilator --cc hello.v --exe sim_main.cpp
2. Compile the Model #
make -j -C obj_dir -f Vhello.mk Vhello
3. Run Simulation #
./obj_dir/Vhello
Step 3: Generate Waveform (Optional) #
Use the --trace
flag to enable VCD waveform dumping:
verilator --cc hello.v --exe sim_main.cpp --trace
๐งฉ Useful Verilator Commands #
Command | Description |
---|---|
verilator --version |
Shows the installed Verilator version. |
verilator --lint-only file.v |
Lints Verilog file for syntax/warnings. |
verilator --trace |
Enables waveform tracing during simulation. |
verilator --cc file.v |
Translates Verilog to C++ code. |
โ Frequently Asked Questions #
1. Does Verilator support only synthesizable Verilog? #
Yes. Verilator is limited to synthesizable, cycle-accurate Verilog. It does not support event-driven simulation or non-synthesizable testbenches.
2. Why is Verilator so fast? #
Verilator converts Verilog to native C++/SystemC code, which is then compiled and run as a software applicationโmuch faster than traditional interpreted simulators.
If you need further help or want a walkthrough for integrating with testbenches, waveform viewers (GTKWave), or CMake setups, feel free to ask! ๐