From 46e300b2c5b5d9a1033bf8be94f8fb1a20992f60 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 23 Sep 2017 18:03:39 -0400 Subject: [PATCH] Add --getenv option. --- Changes | 2 ++ bin/verilator | 17 +++++++++++++---- src/V3Options.cpp | 17 +++++++++++++++++ src/V3Options.h | 1 + test_regress/t/t_flag_getenv.pl | 25 +++++++++++++++++++++++++ test_regress/t/t_flag_getenv.v | 6 ++++++ 6 files changed, 64 insertions(+), 4 deletions(-) create mode 100755 test_regress/t/t_flag_getenv.pl create mode 100644 test_regress/t/t_flag_getenv.v diff --git a/Changes b/Changes index 47d4a3257..417d83f58 100644 --- a/Changes +++ b/Changes @@ -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. diff --git a/bin/verilator b/bin/verilator index e8178b299..7b929bd99 100755 --- a/bin/verilator +++ b/bin/verilator @@ -286,6 +286,7 @@ descriptions in the next sections for more information. -G= Overwrite toplevel parameter --gdb Run Verilator under GDB interactively --gdbbt Run Verilator under GDB for backtrace + --getenv Get environment variable with defaults --help Display this help -I Directory to search for includes --if-depth 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 + +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 @@ -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 diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 1ea4a7a8b..6f0802380 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -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){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; diff --git a/test_regress/t/t_flag_getenv.v b/test_regress/t/t_flag_getenv.v new file mode 100644 index 000000000..99a0ead12 --- /dev/null +++ b/test_regress/t/t_flag_getenv.v @@ -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