Make obj_dir only when needed, and use OS calls rather than system to clean up
git-svn-id: file://localhost/svn/verilator/trunk/verilator@984 77ca24e4-aefa-0310-84f0-b9a241c72d87
This commit is contained in:
parent
8bc1e75d9f
commit
ad591767c9
|
|
@ -232,6 +232,14 @@ bool V3File::checkTimes(const string& filename, const string& cmdline) {
|
||||||
return dependImp.checkTimes(filename, cmdline);
|
return dependImp.checkTimes(filename, cmdline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void V3File::createMakeDir() {
|
||||||
|
static bool created = false;
|
||||||
|
if (!created) {
|
||||||
|
created = true;
|
||||||
|
mkdir(v3Global.opt.makeDir().c_str(), 0777);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//######################################################################
|
//######################################################################
|
||||||
// V3OutFile: A class for printing to a file, with automatic indentation of C++ code.
|
// V3OutFile: A class for printing to a file, with automatic indentation of C++ code.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ public:
|
||||||
return new_ofstream_nodepend (filename, append);
|
return new_ofstream_nodepend (filename, append);
|
||||||
}
|
}
|
||||||
static ofstream* new_ofstream_nodepend(const string& filename, bool append=false) {
|
static ofstream* new_ofstream_nodepend(const string& filename, bool append=false) {
|
||||||
|
createMakeDir();
|
||||||
if (append) {
|
if (append) {
|
||||||
return new ofstream(filename.c_str(), ios::app);
|
return new ofstream(filename.c_str(), ios::app);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -53,15 +54,20 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static FILE* new_fopen_w(const string& filename) {
|
static FILE* new_fopen_w(const string& filename) {
|
||||||
|
createMakeDir();
|
||||||
addTgtDepend(filename);
|
addTgtDepend(filename);
|
||||||
return fopen(filename.c_str(),"w");
|
return fopen(filename.c_str(),"w");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
static void addSrcDepend(const string& filename);
|
static void addSrcDepend(const string& filename);
|
||||||
static void addTgtDepend(const string& filename);
|
static void addTgtDepend(const string& filename);
|
||||||
static void writeDepend(const string& filename);
|
static void writeDepend(const string& filename);
|
||||||
static void writeTimes(const string& filename, const string& cmdline);
|
static void writeTimes(const string& filename, const string& cmdline);
|
||||||
static bool checkTimes(const string& filename, const string& cmdline);
|
static bool checkTimes(const string& filename, const string& cmdline);
|
||||||
|
|
||||||
|
// Directory utilities
|
||||||
|
static void createMakeDir();
|
||||||
};
|
};
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,55 @@ string V3Options::filePath (FileLine* fl, const string& modname, const string& e
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void V3Options::unlinkRegexp(const string& dir, const string& regexp) {
|
||||||
|
if (DIR* dirp = opendir(dir.c_str())) {
|
||||||
|
while (struct dirent* direntp = readdir(dirp)) {
|
||||||
|
if (wildmatch(direntp->d_name, regexp.c_str())) {
|
||||||
|
string fullname = dir + "/" + string(direntp->d_name);
|
||||||
|
unlink (fullname.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dirp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Double procedures, inlined, unrolls loop much better
|
||||||
|
inline bool V3Options::wildmatchi(const char* s, const char* p) {
|
||||||
|
for ( ; *p; s++, p++) {
|
||||||
|
if (*p!='*') {
|
||||||
|
if (((*s)!=(*p)) && *p != '?')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Trailing star matches everything.
|
||||||
|
if (!*++p) return true;
|
||||||
|
while (wildmatch(s, p) == false)
|
||||||
|
if (*++s == '\0')
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(*s == '\0' || *s == '[');
|
||||||
|
}
|
||||||
|
|
||||||
|
bool V3Options::wildmatch(const char* s, const char* p) {
|
||||||
|
for ( ; *p; s++, p++) {
|
||||||
|
if (*p!='*') {
|
||||||
|
if (((*s)!=(*p)) && *p != '?')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Trailing star matches everything.
|
||||||
|
if (!*++p) return true;
|
||||||
|
while (wildmatchi(s, p) == false)
|
||||||
|
if (*++s == '\0')
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(*s == '\0' || *s == '[');
|
||||||
|
}
|
||||||
|
|
||||||
//######################################################################
|
//######################################################################
|
||||||
// V3 Options accessors
|
// V3 Options accessors
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@ class V3Options {
|
||||||
void optimize(int level);
|
void optimize(int level);
|
||||||
void coverage(bool flag) { m_coverageLine = m_coverageUser = flag; }
|
void coverage(bool flag) { m_coverageLine = m_coverageUser = flag; }
|
||||||
bool onoff(const char* sw, const char* arg, bool& flag);
|
bool onoff(const char* sw, const char* arg, bool& flag);
|
||||||
|
static bool wildmatchi(const char* s, const char* p);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// CREATORS
|
// CREATORS
|
||||||
|
|
@ -203,12 +204,16 @@ class V3Options {
|
||||||
void parseOptsList (FileLine* fl, int argc, char** argv);
|
void parseOptsList (FileLine* fl, int argc, char** argv);
|
||||||
void parseOptsFile (FileLine* fl, const string& filename);
|
void parseOptsFile (FileLine* fl, const string& filename);
|
||||||
|
|
||||||
|
// METHODS (generic string utilities)
|
||||||
|
static bool wildmatch(const char* s, const char* p);
|
||||||
|
|
||||||
// METHODS (generic file utilities)
|
// METHODS (generic file utilities)
|
||||||
static string filenameFromDirBase (const string& dir, const string& basename);
|
static string filenameFromDirBase (const string& dir, const string& basename);
|
||||||
static string filenameNonDir (const string& filename); ///< Return non-directory part of filename
|
static string filenameNonDir (const string& filename); ///< Return non-directory part of filename
|
||||||
static string filenameNonExt (const string& filename); ///< Return non-extensioned (no .) part of filename
|
static string filenameNonExt (const string& filename); ///< Return non-extensioned (no .) part of filename
|
||||||
static string filenameNonDirExt (const string& filename) { return filenameNonExt(filenameNonDir(filename)); } ///< Return basename of filename
|
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 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) {
|
static string getenvStr(const char* envvar, const char* defaultValue) {
|
||||||
if (const char* envvalue = getenv(envvar)) {
|
if (const char* envvalue = getenv(envvar)) {
|
||||||
return envvalue;
|
return envvalue;
|
||||||
|
|
|
||||||
|
|
@ -521,13 +521,9 @@ int main(int argc, char** argv, char** env) {
|
||||||
//--FRONTEND------------------
|
//--FRONTEND------------------
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
mkdir(v3Global.opt.makeDir().c_str(), 0777);
|
V3Options::unlinkRegexp(v3Global.opt.makeDir(), v3Global.opt.prefix()+"_*.tree");
|
||||||
string cleanFilename = "/bin/rm -rf "+v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"_*.tree";
|
V3Options::unlinkRegexp(v3Global.opt.makeDir(), v3Global.opt.prefix()+"_*.dot");
|
||||||
system(cleanFilename.c_str());
|
V3Options::unlinkRegexp(v3Global.opt.makeDir(), v3Global.opt.prefix()+"_*.txt");
|
||||||
cleanFilename = "/bin/rm -rf "+v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"_*.dot";
|
|
||||||
system(cleanFilename.c_str());
|
|
||||||
cleanFilename = "/bin/rm -rf "+v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"_*.txt";
|
|
||||||
system(cleanFilename.c_str());
|
|
||||||
|
|
||||||
// Read first filename
|
// Read first filename
|
||||||
v3Global.readFiles();
|
v3Global.readFiles();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue