mirror of
https://github.com/verilator/verilator.git
synced 2025-01-05 22:27:35 +00:00
Move most env vars from wrapper to verilator_bin, and wrap in accessor
functions. The functionallity should be mostly the same as before, except allow verilator_bin to be in the search-path and VERILATOR_ROOT not set. git-svn-id: file://localhost/svn/verilator/trunk/verilator@997 77ca24e4-aefa-0310-84f0-b9a241c72d87
This commit is contained in:
parent
d545ae242c
commit
45940ff820
@ -34,27 +34,7 @@ use Config;
|
||||
use Cwd qw(abs_path getcwd);
|
||||
|
||||
use strict;
|
||||
use vars qw ($Debug %Vars $Opt $Opt_Make_Dir $Opt_Sp @Opt_Verilator_Sw
|
||||
$Opt_Trace
|
||||
%Modules
|
||||
);
|
||||
|
||||
#######################################################################
|
||||
# Global constants -- Configuration info
|
||||
|
||||
# Where to find real executables
|
||||
# We could find it by using $RealBin, but we require this path
|
||||
# so that when the user runs make, they will have it and not get strange error.
|
||||
$ENV{VERILATOR_ROOT} or die "%Error: verilator: VERILATOR_ROOT needs to be in environment\n";
|
||||
print "export VERILATOR_ROOT=$ENV{VERILATOR_ROOT}\n" if $Debug;
|
||||
|
||||
# Read by verilator for populating makefile
|
||||
if (!defined $ENV{SYSTEMC_ARCH}) {
|
||||
$ENV{SYSTEMC_ARCH} ||= (($Config{osname} =~ /solaris/i && "gccsparcOS5")
|
||||
|| ($Config{osname} =~ /cygwin/i && "cygwin")
|
||||
|| "linux");
|
||||
print "export SYSTEMC_ARCH=$ENV{SYSTEMC_ARCH}\n" if $Debug;
|
||||
}
|
||||
use vars qw ($Debug @Opt_Verilator_Sw);
|
||||
|
||||
#######################################################################
|
||||
#######################################################################
|
||||
@ -65,7 +45,6 @@ autoflush STDERR 1;
|
||||
|
||||
$Debug = 0;
|
||||
my $opt_gdb;
|
||||
$Opt_Sp = undef;
|
||||
|
||||
# No arguments can't do anything useful. Give help
|
||||
if ($#ARGV < 0) {
|
||||
@ -84,34 +63,15 @@ if (! GetOptions (
|
||||
# Major operating modes
|
||||
"help" => \&usage,
|
||||
"debug:s" => \&debug,
|
||||
"version!" => \&version,
|
||||
# "version!" => \&version, # Also passthru'ed
|
||||
# Switches
|
||||
"gdb=s" => \$opt_gdb, # Undocumented debugging
|
||||
"trace!" => \$Opt_Trace,
|
||||
"sp!" => sub {$Opt_Sp = 'sp';},
|
||||
"sc!" => sub {$Opt_Sp = 'sc';},
|
||||
"cc!" => sub {$Opt_Sp = 0;},
|
||||
"lint-only!" => sub {$Opt_Sp = 0;},
|
||||
#"ignc!" => ..., # Undocumented debugging, disable $c but don't complain
|
||||
# Additional parameters
|
||||
"<>" => sub {}, # Ignored
|
||||
)) {
|
||||
pod2usage(-exitstatus=>2, -verbose=>0);
|
||||
}
|
||||
|
||||
# Check configuration
|
||||
if ($Opt_Sp) {
|
||||
(defined $ENV{SYSTEMC}) or die "%Error: verilator: Need \$SYSTEMC in environment\nProbably System-C isn't installed, see http://www.systemc.org\n";
|
||||
}
|
||||
if ($Opt_Sp eq 'sp' || $Opt_Trace) {
|
||||
if (!defined $ENV{SYSTEMPERL}) {
|
||||
my $try = "$ENV{W}/hw/utils/perltools/SystemC";
|
||||
$ENV{SYSTEMPERL} = $try if -d $try;
|
||||
}
|
||||
(defined $ENV{SYSTEMPERL}) or die "%Error: verilator: Need \$SYSTEMPERL in environment for --sp or --trace\nProbably System-Perl isn't installed, see http://www.veripool.com/systemperl.html\n";
|
||||
(-d "$ENV{SYSTEMPERL}/src") or die "%Error: verilator: \$SYSTEMPERL environment var doesn't seem to point to System-Perl kit\n";
|
||||
}
|
||||
|
||||
# Determine runtime flags
|
||||
my $vcmd =(($opt_gdb?"$opt_gdb ":"")
|
||||
.verilator_bin()
|
||||
@ -135,23 +95,16 @@ sub debug {
|
||||
$Debug = $level||3;
|
||||
}
|
||||
|
||||
sub version {
|
||||
bin_version();
|
||||
exit (0);
|
||||
}
|
||||
|
||||
sub bin_version {
|
||||
($ENV{VERILATOR_ROOT}) or print "%Warning: Unknown rev: VERILATOR_ROOT undefined\n";
|
||||
run (verilator_bin()." --version");
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
#######################################################################
|
||||
# Builds
|
||||
|
||||
sub verilator_bin {
|
||||
my $bin = "$ENV{VERILATOR_ROOT}/".($ENV{VERILATOR_BIN}||"verilator_bin");
|
||||
if ($Debug && -x "${bin}_dbg") { $bin = "${bin}_dbg"; }
|
||||
my $bin = "";
|
||||
# Use VERILATOR_ROOT if defined, else assume verilator_bin is in the search path
|
||||
$bin .= $ENV{VERILATOR_ROOT}."/" if defined($ENV{VERILATOR_ROOT});
|
||||
$bin .= ($ENV{VERILATOR_BIN}||"verilator_bin");
|
||||
if ($Debug) { $bin = "${bin}_dbg"; }
|
||||
return $bin;
|
||||
}
|
||||
|
||||
@ -166,8 +119,11 @@ sub run {
|
||||
system($command);
|
||||
my $status = $?;
|
||||
if ($status) {
|
||||
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";
|
||||
warn "%Error: export VERILATOR_ROOT=".($ENV{VERILATOR_ROOT}||"")."\n";
|
||||
warn "%Error: $command\n";
|
||||
}
|
||||
die "%Error: Command Failed $command\n";
|
||||
@ -1944,11 +1900,14 @@ Visual C++ Version 7 or newer, but this is not tested by the author.
|
||||
|
||||
=item Can you provide binaries?
|
||||
|
||||
At this time I'd prefer to get patches out quickly than have to generate
|
||||
myriad binaries for many different OS flavors. People have generally
|
||||
requested binaries when they are having problems with their C++
|
||||
compiler. Alas, binaries won't help this, as in the end a fully working C++
|
||||
compiler is required to compile the output of Verilator.
|
||||
Verilator is available as a RPM for SuSE and perhaps other systems; this is
|
||||
done by porters and may slightly lag the primary distribution. If there
|
||||
isn't a binary build for your distribution, how about you set one up?
|
||||
Please contact the authors for assistance.
|
||||
|
||||
Note people sometimes request binaries when they are having problems with
|
||||
their C++ compiler. Alas, binaries won't help this, as in the end a fully
|
||||
working C++ compiler is required to compile the output of Verilator.
|
||||
|
||||
=item How can it be faster than (name-the-simulator)?
|
||||
|
||||
|
@ -79,16 +79,16 @@ public:
|
||||
of.puts("default: "+v3Global.opt.prefix()+"__ALL.a\n");
|
||||
}
|
||||
of.puts("\n# Constants...\n");
|
||||
of.puts("PERL = "+V3Options::getenvStr("PERL","perl")+"\n");
|
||||
of.puts("VERILATOR_ROOT = "+V3Options::getenvStr("VERILATOR_ROOT","")+"\n");
|
||||
of.puts("SYSTEMPERL = "+V3Options::getenvStr("SYSTEMPERL","")+"\n");
|
||||
of.puts("PERL = "+V3Options::getenvPERL()+"\n");
|
||||
of.puts("VERILATOR_ROOT = "+V3Options::getenvVERILATOR_ROOT()+"\n");
|
||||
of.puts("SYSTEMPERL = "+V3Options::getenvSYSTEMPERL()+"\n");
|
||||
|
||||
of.puts("\n# Switches...\n");
|
||||
of.puts(string("VM_SP = ")+(v3Global.opt.systemPerl()?"1":"0")+"\n");
|
||||
of.puts(string("VM_SC = ")+((v3Global.opt.systemC()&&!v3Global.opt.systemPerl())?"1":"0")+"\n");
|
||||
of.puts(string("VM_SP_OR_SC = ")+(v3Global.opt.systemC()?"1":"0")+"\n");
|
||||
of.puts(string("VM_PCLI = ")+(v3Global.opt.systemC()?"0":"1")+"\n");
|
||||
of.puts(string("VM_SC_TARGET_ARCH = ")+V3Options::getenvStr("SYSTEMC_ARCH","")+"\n");
|
||||
of.puts(string("VM_SC_TARGET_ARCH = ")+V3Options::getenvSYSTEMC_ARCH()+"\n");
|
||||
|
||||
of.puts("\n# Vars...\n");
|
||||
of.puts(string("VM_PREFIX = ")+v3Global.opt.prefix()+"\n");
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "verilatedos.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <set>
|
||||
@ -147,6 +149,14 @@ string V3Options::filenameNonExt (const string& filename) {
|
||||
return base;
|
||||
}
|
||||
|
||||
bool V3Options::fileStatDir(const string& filename) {
|
||||
struct stat m_stat; // Stat information
|
||||
int err = stat(filename.c_str(), &m_stat);
|
||||
if (err!=0) return false;
|
||||
if (!S_ISDIR(m_stat.st_mode)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool V3Options::fileStatNormal(const string& filename) {
|
||||
struct stat m_stat; // Stat information
|
||||
int err = stat(filename.c_str(), &m_stat);
|
||||
@ -239,6 +249,76 @@ void V3Options::unlinkRegexp(const string& dir, const string& regexp) {
|
||||
}
|
||||
}
|
||||
|
||||
//######################################################################
|
||||
// Environment
|
||||
|
||||
string V3Options::getenvStr(const char* envvar, const char* defaultValue) {
|
||||
if (const char* envvalue = getenv(envvar)) {
|
||||
return envvalue;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
string V3Options::getenvSYSTEMC() {
|
||||
string var = getenvStr("SYSTEMC","");
|
||||
// Only correct or check it if we really need the value
|
||||
if ((v3Global.opt.systemPerl() || v3Global.opt.systemC())
|
||||
&& !v3Global.opt.lintOnly()) {
|
||||
if (var == "") {
|
||||
v3fatal("Need $SYSTEMC in environment\n"
|
||||
"Probably System-C isn't installed, see http://www.systemc.org\n");
|
||||
}
|
||||
}
|
||||
return var;
|
||||
}
|
||||
string V3Options::getenvSYSTEMC_ARCH() {
|
||||
string var = getenvStr("SYSTEMC_ARCH","");
|
||||
if (var == "") {
|
||||
struct utsname uts;
|
||||
uname(&uts);
|
||||
string sysname = downcase(uts.sysname); // aka 'uname -s'
|
||||
if (wildmatch(sysname.c_str(), "*solaris*")) { var = "gccsparcOS5"; }
|
||||
else if (wildmatch(sysname.c_str(), "*cygwin*")) { var ="cygwin"; }
|
||||
else { var = "linux"; }
|
||||
UINFO(1,"export SYSTEMC_ARCH="<<var<<" # From sysname '"<<sysname<<"'"<<endl);
|
||||
setenv("SYSTEMC_ARCH", var.c_str(), false);
|
||||
}
|
||||
return var;
|
||||
}
|
||||
string V3Options::getenvSYSTEMPERL() {
|
||||
string var = getenvStr("SYSTEMPERL","");
|
||||
// Only correct or check it if we really need the value
|
||||
if ((v3Global.opt.systemPerl() || v3Global.opt.trace()) && !v3Global.opt.lintOnly()) {
|
||||
if (var == "") {
|
||||
string testdir = V3Options::getenvW() + "/hw/utils/perltools/SystemC"; // Hack for internal testing
|
||||
if (V3Options::fileStatDir(testdir)) {
|
||||
var = testdir;
|
||||
UINFO(1,"export SYSTEMPERL="<<var<<endl);
|
||||
setenv ("SYSTEMPERL", var.c_str(), false);
|
||||
}
|
||||
}
|
||||
if (var == "") {
|
||||
v3fatal("Need $SYSTEMPERL in environment for --sp or --trace\n"
|
||||
"Probably System-Perl isn't installed, see http://www.veripool.com/systemperl.html\n");
|
||||
}
|
||||
if (var != ""
|
||||
&& !V3Options::fileStatNormal(var+"/src/systemperl.h")) {
|
||||
v3fatal("$SYSTEMPERL environment var doesn't seem to point to System-Perl kit\n");
|
||||
}
|
||||
}
|
||||
return var;
|
||||
}
|
||||
string V3Options::getenvVERILATOR_ROOT() {
|
||||
string var = getenvStr("VERILATOR_ROOT","");
|
||||
if (var == "") {
|
||||
v3fatal("$VERILATOR_ROOT needs to be in environment\n");
|
||||
}
|
||||
return var;
|
||||
}
|
||||
|
||||
//######################################################################
|
||||
// Wildcard
|
||||
|
||||
// Double procedures, inlined, unrolls loop much better
|
||||
inline bool V3Options::wildmatchi(const char* s, const char* p) {
|
||||
for ( ; *p; s++, p++) {
|
||||
@ -276,6 +356,14 @@ bool V3Options::wildmatch(const char* s, const char* p) {
|
||||
return(*s == '\0' || *s == '[');
|
||||
}
|
||||
|
||||
string V3Options::downcase(const string& str) {
|
||||
string out = str;
|
||||
for (string::iterator pos = out.begin(); pos != out.end(); pos++) {
|
||||
*pos = tolower(*pos);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
//######################################################################
|
||||
// V3 Options accessors
|
||||
|
||||
|
@ -116,6 +116,7 @@ class V3Options {
|
||||
void coverage(bool flag) { m_coverageLine = m_coverageUser = flag; }
|
||||
bool onoff(const char* sw, const char* arg, bool& flag);
|
||||
static bool wildmatchi(const char* s, const char* p);
|
||||
static string getenvStr(const char* envvar, const char* defaultValue);
|
||||
|
||||
public:
|
||||
// CREATORS
|
||||
@ -206,6 +207,7 @@ class V3Options {
|
||||
|
||||
// METHODS (generic string utilities)
|
||||
static bool wildmatch(const char* s, const char* p);
|
||||
static string downcase(const string& str);
|
||||
|
||||
// METHODS (generic file utilities)
|
||||
static string filenameFromDirBase (const string& dir, const string& basename);
|
||||
@ -214,17 +216,18 @@ class V3Options {
|
||||
static string filenameNonDirExt (const string& filename) { return filenameNonExt(filenameNonDir(filename)); } ///< Return basename of filename
|
||||
static string filenameDir (const string& filename); ///< Return directory part of filename
|
||||
static void unlinkRegexp(const string& dir, const string& regexp);
|
||||
static string getenvStr(const char* envvar, const char* defaultValue) {
|
||||
if (const char* envvalue = getenv(envvar)) {
|
||||
return envvalue;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
static string getenvPERL() { return getenvStr("PERL","perl"); }
|
||||
static string getenvSYSTEMC();
|
||||
static string getenvSYSTEMC_ARCH();
|
||||
static string getenvSYSTEMPERL();
|
||||
static string getenvVERILATOR_ROOT();
|
||||
static string getenvW() { return getenvStr("W",""); }
|
||||
|
||||
// METHODS (file utilities using these options)
|
||||
string fileExists (const string& filename);
|
||||
string filePath (FileLine* fl, const string& modname, const string& errmsg);
|
||||
static bool fileStatDir (const string& filename);
|
||||
static bool fileStatNormal (const string& filename);
|
||||
};
|
||||
|
||||
|
@ -503,6 +503,10 @@ int main(int argc, char** argv, char** env) {
|
||||
if (!v3Global.opt.outFormatOk() && !v3Global.opt.preprocOnly() && !v3Global.opt.lintOnly()) {
|
||||
v3fatal("verilator: Need --cc, --sc, --sp, --lint-only or --E option");
|
||||
}
|
||||
// Check enviornment
|
||||
V3Options::getenvSYSTEMC();
|
||||
V3Options::getenvSYSTEMC_ARCH();
|
||||
V3Options::getenvSYSTEMPERL();
|
||||
|
||||
V3Error::abortIfErrors();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user