Add -F option to read relative option files, bug297.
This commit is contained in:
parent
3d1baf3f2f
commit
eeb8fc2626
4
Changes
4
Changes
|
|
@ -3,6 +3,10 @@ Revision history for Verilator
|
|||
The contributors that suggested a given feature are shown in []. [by ...]
|
||||
indicates the contributor was also the author of the fix; Thanks!
|
||||
|
||||
* Verilator 3.80***
|
||||
|
||||
*** Add -F option to read relative option files, bug297. [Neil Hamilton]
|
||||
|
||||
* Verilator 3.805 2010/11/02
|
||||
|
||||
**** Add warning when directory contains spaces, msg378. [Salman Sheikh]
|
||||
|
|
|
|||
|
|
@ -227,6 +227,7 @@ descriptions in the next sections for more information.
|
|||
-E Preprocess, but do not compile
|
||||
--error-limit <value> Abort after this number of errors
|
||||
--exe Link to create executable
|
||||
-F <file> Parse options from a file, relatively
|
||||
-f <file> Parse options from a file
|
||||
--help Display this help.
|
||||
-I<dir> Directory to search for includes
|
||||
|
|
@ -502,10 +503,18 @@ After this number of errors or warnings are encountered, exit. Defaults to
|
|||
Generate a executable. You will also need to pass additional .cpp files on
|
||||
the command line that implement the main loop for your simulation.
|
||||
|
||||
=item -F I<file>
|
||||
|
||||
Read the specified file, and act as if all text inside it was specified as
|
||||
command line parameters. Any relative paths are relative to the directory
|
||||
containing the specified file. Note -F is fairly standard across Verilog
|
||||
tools.
|
||||
|
||||
=item -f I<file>
|
||||
|
||||
Read the specified file, and act as if all text inside it was specified as
|
||||
command line parameters. Note -f is fairly standard across Verilog tools.
|
||||
command line parameters. Any relative paths are relative to the current
|
||||
directory. Note -f is fairly standard across Verilog tools.
|
||||
|
||||
=item --help
|
||||
|
||||
|
|
|
|||
|
|
@ -213,6 +213,10 @@ string V3Options::filenameSubstitute (const string& filename) {
|
|||
return out;
|
||||
}
|
||||
|
||||
bool V3Options::filenameIsRel(const string& filename) {
|
||||
return (filename.length()>0 && filename[0] != '/');
|
||||
}
|
||||
|
||||
bool V3Options::fileStatDir(const string& filename) {
|
||||
struct stat m_stat; // Stat information
|
||||
int err = stat(filename.c_str(), &m_stat);
|
||||
|
|
@ -520,7 +524,7 @@ string V3Options::argString (int argc, char** argv) {
|
|||
void V3Options::parseOpts (FileLine* fl, int argc, char** argv) {
|
||||
// Parse all options
|
||||
// Inital entry point from Verilator.cpp
|
||||
parseOptsList (fl, argc, argv);
|
||||
parseOptsList (fl, ".", argc, argv);
|
||||
|
||||
// Default certain options and error check
|
||||
// Detailed error, since this is what we often get when run with minimal arguments
|
||||
|
|
@ -556,7 +560,7 @@ bool V3Options::suffixed(const char* sw, const char* arg) {
|
|||
return (0==strcmp(sw+strlen(sw)-strlen(arg), arg));
|
||||
}
|
||||
|
||||
void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
|
||||
void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char** argv) {
|
||||
// Parse parameters
|
||||
// Note argc and argv DO NOT INCLUDE the filename in [0]!!!
|
||||
// May be called recursively when there are -f files.
|
||||
|
|
@ -572,7 +576,7 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
|
|||
addDefine (string (sw+strlen("+define+")));
|
||||
}
|
||||
else if ( !strncmp (sw, "+incdir+", 8)) {
|
||||
addIncDir (filenameSubstitute(string (sw+strlen("+incdir+"))));
|
||||
addIncDir (parseFileArg(optdir, string (sw+strlen("+incdir+"))));
|
||||
}
|
||||
else if ( !strncmp (sw, "+libext+", 8)) {
|
||||
string exts = string(sw+strlen("+libext+"));
|
||||
|
|
@ -694,7 +698,7 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
|
|||
m_errorLimit = atoi(argv[i]);
|
||||
}
|
||||
else if ( !strncmp (sw, "-I", 2)) {
|
||||
addIncDir (string (sw+strlen("-I")));
|
||||
addIncDir (parseFileArg(optdir, string (sw+strlen("-I"))));
|
||||
}
|
||||
else if ( !strcmp (sw, "-inline-mult") && (i+1)<argc ) {
|
||||
shift;
|
||||
|
|
@ -753,7 +757,7 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
|
|||
}
|
||||
else if ( !strcmp (sw, "-v") && (i+1)<argc ) {
|
||||
shift;
|
||||
V3Options::addLibraryFile(filenameSubstitute(argv[i]));
|
||||
V3Options::addLibraryFile(parseFileArg(optdir,argv[i]));
|
||||
}
|
||||
else if ( !strcmp (sw, "-V") ) {
|
||||
showVersion(true);
|
||||
|
|
@ -815,9 +819,13 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
|
|||
fl->v3fatal("Unknown setting for --compiler: "<<argv[i]);
|
||||
}
|
||||
}
|
||||
else if ( !strcmp (sw, "-F") && (i+1)<argc ) {
|
||||
shift;
|
||||
parseOptsFile(fl, parseFileArg(optdir,argv[i]), true);
|
||||
}
|
||||
else if ( !strcmp (sw, "-f") && (i+1)<argc ) {
|
||||
shift;
|
||||
parseOptsFile(fl, filenameSubstitute(argv[i]));
|
||||
parseOptsFile(fl, parseFileArg(optdir,argv[i]), false);
|
||||
}
|
||||
else if ( !strcmp (sw, "-gdb") && (i+1)<argc ) {
|
||||
shift; // Used only in perl shell
|
||||
|
|
@ -852,7 +860,7 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
|
|||
}
|
||||
}
|
||||
else if ( !strcmp (sw, "-y") && (i+1)<argc ) {
|
||||
shift; addIncDir (string (argv[i]));
|
||||
shift; addIncDir (parseFileArg(optdir,string (argv[i])));
|
||||
}
|
||||
else {
|
||||
fl->v3fatal ("Invalid Option: "<<argv[i]);
|
||||
|
|
@ -861,7 +869,7 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
|
|||
} // - options
|
||||
else {
|
||||
// Filename
|
||||
string filename = filenameSubstitute(argv[i]);
|
||||
string filename = parseFileArg(optdir,argv[i]);
|
||||
if (suffixed(filename.c_str(), ".cpp")
|
||||
|| suffixed(filename.c_str(), ".cxx")
|
||||
|| suffixed(filename.c_str(), ".cc")
|
||||
|
|
@ -884,7 +892,7 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
|
|||
|
||||
//======================================================================
|
||||
|
||||
void V3Options::parseOptsFile(FileLine* fl, const string& filename) {
|
||||
void V3Options::parseOptsFile(FileLine* fl, const string& filename, bool rel) {
|
||||
// Read the specified -f filename and process as arguments
|
||||
UINFO(1,"Reading Options File "<<filename<<endl);
|
||||
|
||||
|
|
@ -946,12 +954,25 @@ void V3Options::parseOptsFile(FileLine* fl, const string& filename) {
|
|||
startpos = endpos;
|
||||
}
|
||||
|
||||
// Path
|
||||
string optdir = (rel ? V3Options::filenameDir(filename) : ".");
|
||||
|
||||
// Convert to argv style arg list and parse them
|
||||
char* argv [args.size()+1];
|
||||
for (unsigned i=0; i<args.size(); ++i) {
|
||||
argv[i] = (char*)args[i].c_str();
|
||||
}
|
||||
parseOptsList(fl, args.size(), argv);
|
||||
parseOptsList(fl, optdir, args.size(), argv);
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
string V3Options::parseFileArg(const string& optdir, const string& relfilename) {
|
||||
string filename = V3Options::filenameSubstitute(relfilename);
|
||||
if (optdir != "." && filenameIsRel(filename)) {
|
||||
filename = optdir + "/" + filename;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
|
|
|||
|
|
@ -182,6 +182,7 @@ class V3Options {
|
|||
void coverage(bool flag) { m_coverageLine = m_coverageToggle = m_coverageUser = flag; }
|
||||
bool onoff(const char* sw, const char* arg, bool& flag);
|
||||
bool suffixed(const char* sw, const char* arg);
|
||||
string parseFileArg(const string& optdir, const string& relfilename);
|
||||
|
||||
static bool wildmatchi(const char* s, const char* p);
|
||||
static string getenvStr(const string& envvar, const string& defaultValue);
|
||||
|
|
@ -301,8 +302,8 @@ class V3Options {
|
|||
string allArgsString(); ///< Return all passed arguments as simple string
|
||||
void bin(const string& flag) { m_bin = flag; }
|
||||
void parseOpts(FileLine* fl, int argc, char** argv);
|
||||
void parseOptsList (FileLine* fl, int argc, char** argv);
|
||||
void parseOptsFile (FileLine* fl, const string& filename);
|
||||
void parseOptsList (FileLine* fl, const string& optdir, int argc, char** argv);
|
||||
void parseOptsFile (FileLine* fl, const string& filename, bool rel);
|
||||
|
||||
// METHODS (generic string utilities)
|
||||
static bool wildmatch(const char* s, const char* p);
|
||||
|
|
@ -315,6 +316,7 @@ 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 string filenameSubstitute (const string& filename); ///< Return filename with env vars removed
|
||||
static bool filenameIsRel (const string& filename); ///< True if relative
|
||||
static void unlinkRegexp(const string& dir, const string& regexp);
|
||||
|
||||
// METHODS (environment)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
|
||||
`include "t_flag_f_tsub_inc.v"
|
||||
|
||||
module t;
|
||||
initial begin
|
||||
`ifndef GOT_DEF1
|
||||
|
|
@ -11,6 +13,15 @@ module t;
|
|||
`ifndef GOT_DEF3
|
||||
$write("%%Error: NO GOT_DEF3\n"); $stop;
|
||||
`endif
|
||||
`ifndef GOT_DEF4
|
||||
$write("%%Error: NO GOT_DEF4\n"); $stop;
|
||||
`endif
|
||||
`ifndef GOT_DEF5
|
||||
$write("%%Error: NO GOT_DEF5\n"); $stop;
|
||||
`endif
|
||||
`ifndef GOT_DEF6
|
||||
$write("%%Error: NO GOT_DEF6\n"); $stop;
|
||||
`endif
|
||||
`ifdef NON_DEF
|
||||
$write("%%Error: NON_DEF\n"); $stop;
|
||||
`endif
|
||||
|
|
|
|||
|
|
@ -2,3 +2,5 @@
|
|||
-f $VERILATOR_ROOT/test_regress/t/t_flag_f__2.vc
|
||||
// Env var with .v file
|
||||
$VERILATOR_ROOT/test_regress/t/t_flag_f__3.v
|
||||
// Test -f
|
||||
-F $VERILATOR_ROOT/test_regress/t/tsub/t_flag_f_tsub.vc
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
|
||||
`define GOT_DEF6
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
|
||||
+define+GOT_DEF4=1
|
||||
+incdir+.
|
||||
t_flag_f_tsub.v
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
|
||||
`define GOT_DEF5
|
||||
Loading…
Reference in New Issue