Add --getenv option.

This commit is contained in:
Wilson Snyder 2017-09-23 18:03:39 -04:00
parent c693e52f6c
commit 46e300b2c5
6 changed files with 64 additions and 4 deletions

View File

@ -4,6 +4,8 @@ The contributors that suggested a given feature are shown in []. Thanks!
* Verilator 3.913 devel
*** Add --getenv option.
**** The internal test_verilated test directory is moved to be part of test_regress.

View File

@ -286,6 +286,7 @@ descriptions in the next sections for more information.
-G<name>=<value> Overwrite toplevel parameter
--gdb Run Verilator under GDB interactively
--gdbbt Run Verilator under GDB for backtrace
--getenv <var> Get environment variable with defaults
--help Display this help
-I<dir> Directory to search for includes
--if-depth <value> Tune IFDEPTH warning
@ -762,6 +763,14 @@ backtrace on exit, then exit GDB immediately. Without --debug or if GDB
doesn't seem to work, this flag is ignored. Intended for easy creation of
backtraces by users; otherwise see the --gdb flag.
=item --getenv I<variable>
If the variable is declared in the environment, print it and exit
immediately. Otherwise, if it's built into Verilator (e.g. VERILATOR_ROOT),
print that and exit immediately. Otherwise, print a newline and exit
immediately. This can be useful in makefiles. See also -V, and the various
*.mk files.
=item --help
Displays this message and program version and exits.
@ -1181,7 +1190,7 @@ Setting it to "" disables matching.
=item -V
Shows the verbose version, including configuration information compiled
into Verilator. (Similar to perl -V.)
into Verilator. (Similar to perl -V.) See also --getenv.
=item -v I<filename>
@ -1409,8 +1418,8 @@ And we get as output
Really, you're better off writing a Makefile to do all this for you. Then,
when your source changes it will automatically run all of these steps; to
aid this Verilator can create a makefile dependency file. See the test_c
directory in the distribution for an example.
aid this Verilator can create a makefile dependency file. See the examples
directory in the distribution.
=head1 EXAMPLE SYSTEMC EXECUTION
@ -1487,7 +1496,7 @@ And we get the same output as the C++ example:
Really, you're better off using a Makefile to do all this for you. Then,
when your source changes it will automatically run all of these steps. See
the test_sc directory in the distribution for an example.
the examples directory in the distribution.
=head1 BENCHMARKING & OPTIMIZATION

View File

@ -410,6 +410,18 @@ V3LangCode V3Options::fileLanguage(const string &filename) {
//######################################################################
// Environment
string V3Options::getenvBuiltins(const string& var) {
if (var == "PERL") return getenvPERL();
else if (var == "SYSTEMC") return getenvSYSTEMC();
else if (var == "SYSTEMC_ARCH") return getenvSYSTEMC_ARCH();
else if (var == "SYSTEMC_INCLUDE") return getenvSYSTEMC_INCLUDE();
else if (var == "SYSTEMC_LIBDIR") return getenvSYSTEMC_LIBDIR();
else if (var == "VERILATOR_ROOT") return getenvVERILATOR_ROOT();
else {
return V3Os::getenvStr(var,"");
}
}
string V3Options::getenvPERL() {
return V3Os::getenvStr("PERL","perl");
}
@ -762,6 +774,11 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
else if ( !strncmp (sw, "-G", strlen("-G"))) {
addParameter(string (sw+strlen("-G")), false);
}
else if ( !strcmp (sw, "-getenv") && (i+1)<argc ) {
shift;
cout<<V3Options::getenvBuiltins(argv[i])<<endl;
exit(0);
}
else if ( !strncmp (sw, "-I", 2)) {
addIncDirUser(parseFileArg(optdir, string (sw+strlen("-I"))));
}

View File

@ -329,6 +329,7 @@ class V3Options {
// Most of these may be built into the executable with --enable-defenv,
// see the README. If adding new variables, also see src/Makefile_obj.in
// Also add to V3Options::showVersion()
static string getenvBuiltins(const string& var);
static string getenvPERL();
static string getenvSYSTEMC();
static string getenvSYSTEMC_ARCH();

25
test_regress/t/t_flag_getenv.pl Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2008 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.
$Self->{vlt} or $Self->skip("Verilator only test");
$ENV{FOOBARTEST} = "gotit";
compile (
v_flags2 => ["--getenv FOOBARTEST"],
expect=>
'gotit
',
make_top_shell => 0,
make_main => 0,
verilator_make_gcc => 0,
);
ok(1);
1;

View File

@ -0,0 +1,6 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2008 by Wilson Snyder.
`define EMPTY 1