verilator/bin/verilator

488 lines
21 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env perl
######################################################################
#
2022-01-01 14:26:40 +01:00
# Copyright 2003-2022 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
#
######################################################################
require 5.006_001;
use warnings;
use Getopt::Long;
use FindBin qw($RealBin $RealScript);
2014-11-28 13:56:21 +01:00
use IO::File;
use Pod::Usage;
use strict;
use vars qw($Debug @Opt_Verilator_Sw);
#######################################################################
#######################################################################
# main
autoflush STDOUT 1;
autoflush STDERR 1;
$Debug = 0;
my $opt_gdb;
2019-07-26 03:34:09 +02:00
my $opt_rr;
2009-10-05 00:04:37 +02:00
my $opt_gdbbt;
my $opt_quiet_exit;
# No arguments can't do anything useful. Give help
if ($#ARGV < 0) {
pod2usage(-exitstatus => 2, -verbose => 0);
}
# Insert debugging options up front
push @ARGV, (split ' ', $ENV{VERILATOR_TEST_FLAGS} || "");
# We sneak a look at the flags so we can do some pre-environment checks
# All flags will hit verilator...
2010-01-19 02:37:20 +01:00
foreach my $sw (@ARGV) {
push @Opt_Verilator_Sw, $sw;
}
Getopt::Long::config("no_auto_abbrev", "pass_through");
2019-05-14 12:56:20 +02:00
if (! GetOptions(
# Major operating modes
"help" => \&usage,
2019-07-31 00:40:27 +02:00
"debug" => \&debug,
# "version!" => \&version, # Also passthru'ed
# Switches
"gdb!" => \$opt_gdb,
"gdbbt!" => \$opt_gdbbt,
"quiet-exit!" => \$opt_quiet_exit,
2019-07-26 03:34:09 +02:00
"rr!" => \$opt_rr,
# Additional parameters
"<>" => sub {}, # Ignored
)) {
pod2usage(-exitstatus => 2, -verbose => 0);
}
if ($opt_gdbbt && !gdb_works()) {
warn "-Info: --gdbbt ignored: gdb doesn't seem to be working\n" if $Debug;
$opt_gdbbt = 0;
}
# Determine runtime flags and run
# Opt_Verilator_Sw is what we want verilator to see on its argc/argv.
# Starting with that, escape all special chars for the shell;
# The shell will undo the escapes and the verilator binary should
# then see exactly the contents of @Opt_Verilator_Sw.
my @quoted_sw = map { sh_escape($_) } @Opt_Verilator_Sw;
2012-03-10 00:37:38 +01:00
if ($opt_gdb) {
# Generic GDB interactive
run (aslr_off()
. ($ENV{VERILATOR_GDB} || "gdb")
. " " . verilator_bin()
2018-05-01 02:00:38 +02:00
# Note, uncomment to set breakpoints before running:
# ." -ex 'break main'"
# Note, we must use double-quotes ("run <switches>")
# and not single ('run <switches>') below. Bash swallows
# escapes as you would expect in a double-quoted string.
# That's not true for a single-quoted string, where \'
# actually terminates the string -- not what we want!
. " -ex \"run " . join(' ', @quoted_sw) . "\""
. " -ex 'set width 0'"
. " -ex 'bt'");
2019-07-26 03:34:09 +02:00
} elsif ($opt_rr) {
# Record with rr
run (aslr_off()
. "rr record " . verilator_bin()
. " " . join(' ', @quoted_sw));
2012-03-10 00:37:38 +01:00
} elsif ($opt_gdbbt && $Debug) {
2009-10-05 00:04:37 +02:00
# Run under GDB to get gdbbt
run (aslr_off()
. "gdb"
. " " . verilator_bin()
. " --batch --quiet --return-child-result"
. " -ex \"run " . join(' ', @quoted_sw)."\""
. " -ex 'set width 0'"
. " -ex 'bt' -ex 'quit'");
} elsif ($Debug) {
# Debug
run(aslr_off() . verilator_bin() . " " . join(' ', @quoted_sw));
2009-10-05 00:04:37 +02:00
} else {
# Normal, non gdb
run(verilator_bin() . " " . join(' ', @quoted_sw));
2009-10-05 00:04:37 +02:00
}
#----------------------------------------------------------------------
sub usage {
pod2usage(-verbose => 2, -exitval => 0, -output => \*STDOUT);
}
sub debug {
shift;
my $level = shift;
$Debug = $level || 3;
}
#######################################################################
#######################################################################
# Builds
sub verilator_bin {
my $bin = "";
# Use VERILATOR_ROOT if defined, else assume verilator_bin is in the search path
my $basename = ($ENV{VERILATOR_BIN}
2016-10-01 00:14:42 +02:00
|| ($Debug ? "verilator_bin_dbg" : "verilator_bin"));
if (defined($ENV{VERILATOR_ROOT})) {
2016-10-01 00:14:42 +02:00
my $dir = $ENV{VERILATOR_ROOT};
2018-10-13 00:31:45 +02:00
if (-x "$dir/bin/$basename"
|| -x "$dir/bin/$basename.exe") { # From a "make install" into VERILATOR_ROOT
2016-10-01 00:14:42 +02:00
$bin = "$dir/bin/$basename";
} else {
$bin = "$dir/$basename"; # From pointing to kit directory
}
} else {
2018-10-13 00:31:45 +02:00
if (-x "$RealBin/$basename"
|| -x "$RealBin/$basename.exe") {
2016-10-01 00:14:42 +02:00
$bin = "$RealBin/$basename"; # From path/to/verilator with verilator_bin installed
} else {
$bin = $basename; # Find in PATH
}
# Note we don't look under bin/$basename which would be right if running
# in the kit dir. Running that would likely break, since
# VERILATOR_ROOT wouldn't be set and Verilator won't find internal files.
}
return $bin;
}
#######################################################################
#######################################################################
# Utilities
sub gdb_works {
$! = undef; # Cleanup -x
system("gdb /bin/echo"
. " --batch-silent --quiet --return-child-result"
. " -ex 'run -n'" # `echo -n`
. " -ex 'set width 0'"
. " -ex 'bt'"
. " -ex 'quit'");
my $status = $?;
return $status == 0;
}
sub aslr_off {
my $ok = `setarch --addr-no-randomize echo ok 2>/dev/null` || "";
if ($ok =~ /ok/) {
return "setarch --addr-no-randomize ";
} else {
return "";
}
}
sub run {
# Run command, check errors
my $command = shift;
$! = undef; # Cleanup -x
print "\t$command\n" if $Debug >= 3;
system($command);
my $status = $?;
if ($status) {
2016-10-01 00:14:42 +02:00
if ($! =~ /no such file or directory/i) {
warn "%Error: verilator: Misinstalled, or VERILATOR_ROOT might need to be in environment\n";
}
if ($Debug) { # For easy rerunning
warn "%Error: export VERILATOR_ROOT=" . ($ENV{VERILATOR_ROOT} || "") . "\n";
2016-10-01 00:14:42 +02:00
warn "%Error: $command\n";
}
if ($status & 127) {
2019-05-14 12:56:20 +02:00
if (($status & 127) == 4 # SIGILL
|| ($status & 127) == 8 # SIGFPA
|| ($status & 127) == 11) { # SIGSEGV
2020-04-29 03:15:27 +02:00
warn "%Error: Verilator internal fault, sorry. "
. "Suggest trying --debug --gdbbt\n" if !$Debug;
2016-10-01 00:14:42 +02:00
} elsif (($status & 127) == 6) { # SIGABRT
2020-04-29 03:15:27 +02:00
warn "%Error: Verilator aborted. "
. "Suggest trying --debug --gdbbt\n" if !$Debug;
2016-10-01 00:14:42 +02:00
} else {
2020-04-29 03:15:27 +02:00
warn "%Error: Verilator threw signal $status. "
. "Suggest trying --debug --gdbbt\n" if !$Debug;
2016-10-01 00:14:42 +02:00
}
}
if (!$opt_quiet_exit && ($status != 256 || $Debug)) { # i.e. not normal exit(1)
warn "%Error: Command Failed $command\n";
}
exit $! if $!; # errno
exit $? >> 8 if $? >> 8; # child exit status
exit 255; # last resort
}
}
sub sh_escape {
my ($arg) = @_;
# This is similar to quotemeta() but less aggressive.
# There's no need to escape hyphens, periods, or forward slashes
# for the shell as these have no special meaning to the shell.
$arg =~ s/([^0-9a-zA-Z_\-\+\=\.\/])/\\$1/g;
return $arg;
}
#######################################################################
#######################################################################
package main;
__END__
=pod
=head1 NAME
2019-10-27 15:29:19 +01:00
Verilator - Translate and simulate SystemVerilog code using C++/SystemC
2020-06-29 00:37:42 +02:00
=head1 SYNOPSIS
verilator --help
verilator --version
2016-11-27 22:37:51 +01:00
verilator --cc [options] [source_files.v]... [opt_c_files.cpp/c/cc/a/o/so]
verilator --sc [options] [source_files.v]... [opt_c_files.cpp/c/cc/a/o/so]
verilator --lint-only -Wall [source_files.v]...
2020-06-29 00:37:42 +02:00
=head1 DESCRIPTION
2020-06-29 00:37:42 +02:00
The "Verilator" package converts all synthesizable, and many behavioral,
Verilog and SystemVerilog designs into a C++ or SystemC model that after
compiling can be executed. Verilator is not a traditional simulator, but a
compiler.
For documentation see L<https://verilator.org/verilator_doc.html>.
2010-02-07 01:56:14 +01:00
=head1 ARGUMENT SUMMARY
2020-06-29 00:37:42 +02:00
This is a short summary of the arguments to the "verilator" executable.
2021-04-13 15:25:11 +02:00
See L<https://verilator.org/guide/latest/exe_verilator.html> for the
detailed descriptions of these arguments.
2021-04-03 19:11:26 +02:00
=for VL_SPHINX_EXTRACT "_build/gen/args_verilator.rst"
<file.v> Verilog package, module and top module filenames
<file.c/cc/cpp> Optional C++ files to compile in
<file.a/o/so> Optional C++ files to link in
+1364-1995ext+<ext> Use Verilog 1995 with file extension <ext>
+1364-2001ext+<ext> Use Verilog 2001 with file extension <ext>
+1364-2005ext+<ext> Use Verilog 2005 with file extension <ext>
+1800-2005ext+<ext> Use SystemVerilog 2005 with file extension <ext>
+1800-2009ext+<ext> Use SystemVerilog 2009 with file extension <ext>
+1800-2012ext+<ext> Use SystemVerilog 2012 with file extension <ext>
+1800-2017ext+<ext> Use SystemVerilog 2017 with file extension <ext>
--assert Enable all assertions
2008-07-16 20:06:08 +02:00
--autoflush Flush streams after all $displays
--bbox-sys Blackbox unknown $system calls
--bbox-unsup Blackbox unsupported language features
--bin <filename> Override Verilator binary
--build Build model executable/library after Verilation
2021-04-03 19:11:26 +02:00
-CFLAGS <flags> C++ compiler arguments for makefile
--cc Create C++ output
2010-01-07 22:41:19 +01:00
--cdc Clock domain crossing analysis
--clk <signal-name> Mark specified signal as clock
--make <build-tool> Generate scripts for specified build tool
--compiler <compiler-name> Tune for specified C++ compiler
2012-06-01 00:56:31 +02:00
--converge-limit <loops> Tune convergence settle time
--coverage Enable all coverage
--coverage-line Enable line coverage
2021-03-30 00:54:51 +02:00
--coverage-max-width <width> Maximum array depth for coverage
2008-12-12 21:34:02 +01:00
--coverage-toggle Enable toggle coverage
--coverage-user Enable SVL user coverage
2012-03-09 00:36:51 +01:00
--coverage-underscore Enable coverage of _signals
2010-02-02 03:12:00 +01:00
-D<var>[=<value>] Set preprocessor define
--debug Enable debugging
--debug-check Enable debugging assertions
--no-debug-leak Disable leaking memory in --debug mode
2009-01-21 22:56:50 +01:00
--debugi <level> Enable debugging at a specified level
--debugi-<srcfile> <level> Enable debugging a source file at a level
--default-language <lang> Default language to parse
+define+<var>=<value> Set preprocessor define
2019-08-28 03:36:59 +02:00
--dpi-hdr-only Only produce the DPI header file
2018-10-26 01:45:06 +02:00
--dump-defines Show preprocessor defines with -E
--dump-tree Enable dumping .tree files
2012-03-21 03:45:35 +01:00
--dump-treei <level> Enable dumping .tree files at a level
2015-03-13 00:47:54 +01:00
--dump-treei-<srcfile> <level> Enable dumping .tree file at a source file at a level
--dump-tree-addrids Use short identifiers instead of addresses
-E Preprocess, but do not compile
--error-limit <value> Abort after this number of errors
--exe Link to create executable
2021-06-06 16:27:01 +02:00
--expand-limit <value> Set expand optimization limit
2021-04-03 19:11:26 +02:00
-F <file> Parse arguments from a file, relatively
-f <file> Parse arguments from a file
-FI <file> Force include of a file
--flatten Force inlining of all modules, tasks and functions
--fno-<optimization> Disable internal optimization stage
2020-06-29 00:37:42 +02:00
-G<name>=<value> Overwrite top-level parameter
2012-03-10 00:37:38 +01:00
--gdb Run Verilator under GDB interactively
2011-02-18 13:11:03 +01:00
--gdbbt Run Verilator under GDB for backtrace
2019-10-10 00:53:30 +02:00
--generate-key Create random key for --protect-key
2017-09-24 00:03:39 +02:00
--getenv <var> Get environment variable with defaults
--help Display this help
--hierarchical Enable hierarchical Verilation
2010-02-02 03:12:00 +01:00
-I<dir> Directory to search for includes
-j <jobs> Parallelism for --build
--gate-stmts <value> Tune gate optimizer depth
--if-depth <value> Tune IFDEPTH warning
2010-02-02 03:12:00 +01:00
+incdir+<dir> Directory to search for includes
--inline-mult <value> Tune module inlining
--instr-count-dpi <value> Assumed dynamic instruction count of DPI imports
2021-04-03 19:11:26 +02:00
-LDFLAGS <flags> Linker pre-object arguments for makefile
--l2-name <value> Verilog scope name of the top module
--language <lang> Default language standard to parse
--lib-create <name> Create a DPI library
2010-02-02 03:12:00 +01:00
+libext+<ext>+[ext]... Extensions for finding modules
--lint-only Lint, but do not make output
2021-04-03 19:11:26 +02:00
-MAKEFLAGS <flags> Arguments to pass to make during --build
--max-num-width <value> Maximum number width (default: 64K)
--MMD Create .d dependency files
--MP Create phony dependency targets
--Mdir <directory> Name of output object directory
--mod-prefix <topname> Name to prepend to lower classes
--no-clk <signal-name> Prevent marking specified signal as clock
--no-decoration Disable comments and symbol decorations
--no-pins64 Don't use uint64_t's for 33-64 bit sigs
--no-skip-identical Disable skipping identical output
2010-02-02 03:12:00 +01:00
+notimingchecks Ignored
-O0 Disable optimizations
-O3 High performance optimizations
-O<optimization-letter> Selectable optimizations
-o <executable> Name of final executable
--no-order-clock-delay Disable ordering clock enable assignments
2020-06-20 01:22:39 +02:00
--no-verilate Skip verilation and just compile previously Verilated code.
2019-12-01 18:43:41 +01:00
--output-split <statements> Split .cpp files into pieces
2020-06-20 01:22:39 +02:00
--output-split-cfuncs <statements> Split model functions
--output-split-ctrace <statements> Split tracing functions
-P Disable line numbers and blanks with -E
--pins-bv <bits> Specify types for top level ports
--pins-sc-uint Specify types for top level ports
--pins-sc-biguint Specify types for top level ports
--pins-uint8 Specify types for top level ports
--pipe-filter <command> Filter all input through a script
2018-10-26 03:17:25 +02:00
--pp-comments Show preprocessor comments with -E
--prefix <topname> Name of top level class
--prof-c Compile C++ code with profiling
--prof-cfuncs Name functions for profiling
--prof-exec Enable generating execution profile for gantt chart
--prof-pgo Enable generating profiling data for PGO
--protect-key <key> Key for symbol protection
--protect-ids Hash identifier names for obscurity
--protect-lib <name> Create a DPI protected library
--private Debugging; see docs
--public Debugging; see docs
--public-flat-rw Mark all variables, etc as public_flat_rw
-pvalue+<name>=<value> Overwrite toplevel parameter
--quiet-exit Don't print the command on failure
2017-02-10 00:33:18 +01:00
--relative-includes Resolve includes relative to current file
--reloop-limit Minimum iterations for forming loops
--report-unoptflat Extra diagnostics for UNOPTFLAT
2019-07-26 03:34:09 +02:00
--rr Run Verilator and record with rr
2016-10-01 00:14:42 +02:00
--savable Enable model save-restore
--sc Create SystemC output
--stats Create statistics file
2014-12-20 14:28:31 +01:00
--stats-vars Provide statistics on variables
2010-02-02 03:12:00 +01:00
-sv Enable SystemVerilog parsing
+systemverilogext+<ext> Synonym for +1800-2017ext+<ext>
--threads <threads> Enable multithreading
--threads-dpi <mode> Enable multithreaded DPI
--threads-max-mtasks <mtasks> Tune maximum mtask partitioning
--timescale <timescale> Sets default timescale
--timescale-override <timescale> Overrides all timescales
--top <topname> Alias of --top-module
--top-module <topname> Name of top level input module
--trace Enable waveform creation
2019-10-27 14:27:18 +01:00
--trace-coverage Enable tracing of coverage
--trace-depth <levels> Depth of tracing
--trace-fst Enable FST waveform creation
2011-09-15 03:11:14 +02:00
--trace-max-array <depth> Maximum bit width for tracing
--trace-max-width <width> Maximum array depth for tracing
2019-10-27 14:27:18 +01:00
--trace-params Enable tracing of parameters
--trace-structs Enable tracing structure names
--trace-threads <threads> Enable FST waveform creation on separate threads
--trace-underscore Enable tracing of _signals
2010-02-02 03:12:00 +01:00
-U<var> Undefine preprocessor define
--unroll-count <loops> Tune maximum loop iterations
--unroll-stmts <stmts> Tune maximum loop body size
2011-01-02 01:43:22 +01:00
--unused-regexp <regexp> Tune UNUSED lint signals
2010-02-02 03:12:00 +01:00
-V Verbose version and config
-v <filename> Verilog library
+verilog1995ext+<ext> Synonym for +1364-1995ext+<ext>
+verilog2001ext+<ext> Synonym for +1364-2001ext+<ext>
2018-05-19 20:50:28 +02:00
--version Displays program version and exits
--vpi Enable VPI compiles
--waiver-output <filename> Create a waiver file based on the linter warnings
-Wall Enable all style warnings
-Werror-<message> Convert warnings to errors
2010-02-02 03:12:00 +01:00
-Wfuture-<message> Disable unknown message warnings
-Wno-<message> Disable warning
-Wno-context Disable source context on warnings
2019-11-16 17:59:21 +01:00
-Wno-fatal Disable fatal exit on warnings
2010-02-02 03:12:00 +01:00
-Wno-lint Disable all lint warnings
-Wno-style Disable all style warnings
2019-11-16 17:59:21 +01:00
-Wpedantic Warn on compliance-test issues
2017-10-02 03:31:40 +02:00
--x-assign <mode> Assign non-initial Xs to this value
--x-initial <mode> Assign initial Xs to this value
--x-initial-edge Enable initial X->0 and X->1 edge triggers
2018-10-28 13:16:19 +01:00
--xml-only Create XML parser output
2019-11-01 02:17:05 +01:00
--xml-output XML output filename
2010-02-02 03:12:00 +01:00
-y <dir> Directory to search for modules
2020-06-29 00:37:42 +02:00
This is a short summary of the simulation runtime arguments, i.e. for the
final Verilated simulation runtime models. See
2021-04-13 15:25:11 +02:00
L<https://verilator.org/guide/latest/exe_verilator.html> for the detailed
description of these arguments.
2018-05-20 14:40:35 +02:00
2021-04-03 19:11:26 +02:00
=for VL_SPHINX_EXTRACT "_build/gen/args_verilated.rst"
2018-05-20 14:40:35 +02:00
+verilator+debug Enable debugging
2018-05-20 15:16:37 +02:00
+verilator+debugi+<value> Enable debugging at a level
2021-04-03 19:11:26 +02:00
+verilator+error+limit+<value> Set error limit
2018-05-20 14:40:35 +02:00
+verilator+help Display help
2021-04-03 19:11:26 +02:00
+verilator+noassert Disable assert checking
+verilator+prof+exec+file+<filename> Set execution profile filename
+verilator+prof+exec+start+<value> Set execution profile starting point
+verilator+prof+exec+window+<value> Set execution profile duration
+verilator+prof+vlt+file+<filename> Set PGO profile filename
2021-02-15 14:40:49 +01:00
+verilator+rand+reset+<value> Set random reset technique
+verilator+seed+<value> Set random seed
2018-05-20 14:40:35 +02:00
+verilator+V Verbose version and config
+verilator+version Show version and exit
2010-02-07 01:56:14 +01:00
=head1 DISTRIBUTION
2019-11-08 04:33:59 +01:00
The latest version is available from L<https://verilator.org>.
2022-01-01 14:26:40 +01:00
Copyright 2003-2022 by Wilson Snyder. This program is free software; you can
redistribute it and/or modify the Verilator internals under the terms of
either the GNU Lesser General Public License Version 3 or the Perl Artistic
License Version 2.0.
2020-02-13 04:46:59 +01:00
All Verilog and C++/SystemC code quoted within this documentation file are
released as Creative Commons Public Domain (CC0). Many example files and
test files are likewise released under CC0 into effectively the Public
Domain as described in the files themselves.
2020-06-29 00:37:42 +02:00
=head1 SEE ALSO
L<verilator_coverage>, L<verilator_gantt>, L<verilator_profcfunc>, L<make>,
2012-11-04 01:11:53 +01:00
L<verilator --help> which is the source for this document,
and L<https://verilator.org/verilator_doc.html> for detailed documentation.
=cut
######################################################################
2020-06-28 03:44:32 +02:00
# Local Variables:
# fill-column: 75
# End: