2026-01-26 20:24:34 -05:00
|
|
|
.. SPDX-FileCopyrightText: 2003-2026 Wilson Snyder
|
2022-09-28 09:04:14 -04:00
|
|
|
.. SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
|
|
|
|
|
2025-11-21 22:25:03 -05:00
|
|
|
.. _example create-binary execution:
|
2022-09-28 09:04:14 -04:00
|
|
|
|
2022-10-02 16:47:32 -04:00
|
|
|
Example Create-Binary Execution
|
|
|
|
|
===============================
|
2022-09-28 09:04:14 -04:00
|
|
|
|
2025-11-22 10:39:52 -05:00
|
|
|
We'll compile this SystemVerilog example into a Verilated simulation
|
|
|
|
|
binary. For an example that discusses the next level of detail see
|
|
|
|
|
:ref:`Example C++ Execution`.
|
2022-09-28 09:04:14 -04:00
|
|
|
|
|
|
|
|
.. include:: example_common_install.rst
|
|
|
|
|
|
|
|
|
|
Now, let's create an example Verilog file:
|
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
2025-11-22 10:39:52 -05:00
|
|
|
mkdir test_our
|
|
|
|
|
cd test_our
|
2022-09-28 09:04:14 -04:00
|
|
|
|
2025-11-22 10:39:52 -05:00
|
|
|
cat >our.v <<'EOF'
|
|
|
|
|
module our;
|
|
|
|
|
initial begin $display("Hello World"); $finish; end
|
|
|
|
|
endmodule
|
|
|
|
|
EOF
|
2022-09-28 09:04:14 -04:00
|
|
|
|
|
|
|
|
Now we run Verilator on our little example.
|
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
2025-11-22 10:39:52 -05:00
|
|
|
verilator --binary -j 0 -Wall our.v
|
2022-09-28 09:04:14 -04:00
|
|
|
|
|
|
|
|
Breaking this command down:
|
|
|
|
|
|
|
|
|
|
#. :vlopt:`--binary` telling Verilator to do everything needed to create a
|
|
|
|
|
simulation executable.
|
|
|
|
|
|
2022-10-02 16:47:32 -04:00
|
|
|
#. :vlopt:`-j` `0` to Verilate using use as many CPU threads as the machine
|
2022-09-28 09:04:14 -04:00
|
|
|
has.
|
|
|
|
|
|
2025-12-20 22:41:26 -05:00
|
|
|
#. :vlopt:`-Wall` so Verilator has stronger lint warnings enabled.
|
2022-09-28 09:04:14 -04:00
|
|
|
|
2022-12-10 20:09:47 -05:00
|
|
|
#. An finally, :command:`our.v`, which is our SystemVerilog design file.
|
2022-09-28 09:04:14 -04:00
|
|
|
|
|
|
|
|
And now we run it:
|
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
2025-11-22 10:39:52 -05:00
|
|
|
obj_dir/Vour
|
2022-09-28 09:04:14 -04:00
|
|
|
|
|
|
|
|
And we get as output:
|
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
2025-11-22 10:39:52 -05:00
|
|
|
Hello World
|
|
|
|
|
- our.v:2: Verilog $finish
|
2022-09-28 09:04:14 -04:00
|
|
|
|
2022-12-10 20:09:47 -05:00
|
|
|
You're better off using a Makefile to run the steps for you, so when your
|
2025-11-22 10:39:52 -05:00
|
|
|
source changes, it will automatically run all of the appropriate steps. To
|
|
|
|
|
aid this, Verilator can create a makefile dependency file. For examples
|
2022-12-10 20:09:47 -05:00
|
|
|
that do this, see the :file:`examples` directory in the distribution.
|