Example Create-Binary Execution

We’ll compile this SystemVerilog example into a Verilated simulation binary. For an example that discusses the next level of detail see Example C++ Execution.

First you need Verilator installed, see Installation. In brief, if you installed Verilator using the package manager of your operating system, or did a make install to place Verilator into your default path, you do not need anything special in your environment, and should not have VERILATOR_ROOT set. However, if you installed Verilator from sources and want to run Verilator out of where you compiled Verilator, you need to point to the kit:

# See above; don't do this if using an OS-distributed Verilator
export VERILATOR_ROOT=/path/to/where/verilator/was/installed
export PATH=$VERILATOR_ROOT/bin:$PATH

Now, let’s create an example Verilog file:

mkdir test_our
cd test_our

cat >our.v <<'EOF'
  module our;
     initial begin $display("Hello World"); $finish; end
  endmodule
EOF

Now we run Verilator on our little example.

verilator --binary -j 0 -Wall our.v

Breaking this command down:

  1. --binary telling Verilator to do everything needed to create a simulation executable.

  2. -j 0 to Verilate using use as many CPU threads as the machine has.

  3. -Wall so Verilator has stronger lint warnings enabled.

  4. An finally, our.v, which is our SystemVerilog design file.

And now we run it:

obj_dir/Vour

And we get as output:

Hello World
- our.v:2: Verilog $finish

You’re better off using a Makefile to run the steps for you, so when your source changes, it will automatically run all of the appropriate steps. To aid this, Verilator can create a makefile dependency file. For examples that do this, see the examples directory in the distribution.