Fix Windows filename format, etc. (#3873) (#4421)

* Ignore CLion project files and CMake outputs
* Supporting stripping file path that contains backslash
* Set /bigobj flag and increase stack size for windows platform
* Fix MSVC warnings
This commit is contained in:
Anthony Donlon 2023-08-16 19:34:57 +08:00 committed by GitHub
parent 0f66262fa1
commit cbdee5a804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 53 additions and 36 deletions

2
.gitignore vendored
View File

@ -41,3 +41,5 @@ verilator-config-version.cmake
**/_build/* **/_build/*
**/obj_dir/* **/obj_dir/*
/.vscode/ /.vscode/
/.idea/
/cmake-build-*/

View File

@ -577,8 +577,8 @@ static inline double VL_ROUND(double n) {
//========================================================================= //=========================================================================
// Stringify macros // Stringify macros
#define VL_STRINGIFY(x) VL_STRINGIFY2(x) #define VL_STRINGIFY(...) VL_STRINGIFY2(__VA_ARGS__)
#define VL_STRINGIFY2(x) #x #define VL_STRINGIFY2(...) #__VA_ARGS__
//========================================================================= //=========================================================================
// Offset of field in type // Offset of field in type

View File

@ -490,11 +490,13 @@ target_include_directories(${verilator}
) )
if (WIN32) if (WIN32)
target_compile_options(${verilator} PRIVATE /bigobj)
target_compile_definitions(${verilator} PRIVATE target_compile_definitions(${verilator} PRIVATE
YY_NO_UNISTD_H YY_NO_UNISTD_H
) )
target_include_directories(${verilator} PRIVATE ../platform/win32) target_include_directories(${verilator} PRIVATE ../platform/win32)
target_link_libraries(${verilator} PRIVATE bcrypt psapi) target_link_libraries(${verilator} PRIVATE bcrypt psapi)
target_link_options(${verilator} PRIVATE /STACK:10000000)
endif() endif()
install(TARGETS ${verilator}) install(TARGETS ${verilator})

View File

@ -202,7 +202,9 @@ private:
new AstShiftR{fl, lhip, new AstShiftR{fl, lhip,
new AstConst{fl, static_cast<uint32_t>(nbitsonright)}, new AstConst{fl, static_cast<uint32_t>(nbitsonright)},
VL_EDATASIZE}}, VL_EDATASIZE}},
new AstAnd{fl, new AstConst{fl, AstConst::SizedEData{}, ~VL_MASK_E(loffset)}, new AstAnd{fl,
new AstConst{fl, AstConst::SizedEData{},
static_cast<uint32_t>(~VL_MASK_E(loffset))},
new AstShiftL{fl, llowp, new AstShiftL{fl, llowp,
new AstConst{fl, static_cast<uint32_t>(loffset)}, new AstConst{fl, static_cast<uint32_t>(loffset)},
VL_EDATASIZE}}}; VL_EDATASIZE}}};

View File

@ -20,6 +20,7 @@
// clang-format off // clang-format off
#include "V3Error.h" #include "V3Error.h"
#include "V3FileLine.h" #include "V3FileLine.h"
#include "V3Os.h"
#include "V3String.h" #include "V3String.h"
#ifndef V3ERROR_NO_GLOBAL_ #ifndef V3ERROR_NO_GLOBAL_
# include "V3Global.h" # include "V3Global.h"
@ -286,12 +287,7 @@ FileLine* FileLine::copyOrSameFileLine() {
return newp; return newp;
} }
string FileLine::filebasename() const VL_MT_SAFE { string FileLine::filebasename() const VL_MT_SAFE { return V3Os::filenameNonDir(filename()); }
string name = filename();
string::size_type pos;
if ((pos = name.rfind('/')) != string::npos) name.erase(0, pos + 1);
return name;
}
string FileLine::filebasenameNoExt() const { string FileLine::filebasenameNoExt() const {
string name = filebasename(); string name = filebasename();

View File

@ -620,6 +620,7 @@ private:
// LCOV_EXCL_START // LCOV_EXCL_START
if (debug()) rhsp->dumpTree("Don't know how to fold expression: "); if (debug()) rhsp->dumpTree("Don't know how to fold expression: ");
rhsp->v3fatalSrc("Should not try to fold this during conditional merging"); rhsp->v3fatalSrc("Should not try to fold this during conditional merging");
return nullptr;
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
} }

View File

@ -548,8 +548,8 @@ string V3Options::filePath(FileLine* fl, const string& modname, const string& la
// Find a filename to read the specified module name, // Find a filename to read the specified module name,
// using the incdir and libext's. // using the incdir and libext's.
// Return "" if not found. // Return "" if not found.
if (modname[0] == '/') { if (!V3Os::filenameIsRel(modname)) {
// If leading /, obey existing absolute path, so can find getStdPackagePath() // modname is an absolute path, so can find getStdPackagePath()
string exists = filePathCheckOneDir(modname, ""); string exists = filePathCheckOneDir(modname, "");
if (exists != "") return exists; if (exists != "") return exists;
} }

View File

@ -124,7 +124,9 @@ void V3Os::setenvStr(const string& envvar, const string& value, const string& wh
//###################################################################### //######################################################################
// Generic filename utilities // Generic filename utilities
string V3Os::filenameFromDirBase(const string& dir, const string& basename) { static bool isSlash(char ch) VL_PURE { return ch == '/' || ch == '\\'; }
string V3Os::filenameFromDirBase(const string& dir, const string& basename) VL_PURE {
// Don't return ./{filename} because if filename was absolute, that makes it relative // Don't return ./{filename} because if filename was absolute, that makes it relative
if (dir.empty() || dir == ".") { if (dir.empty() || dir == ".") {
return basename; return basename;
@ -133,22 +135,26 @@ string V3Os::filenameFromDirBase(const string& dir, const string& basename) {
} }
} }
string V3Os::filenameDir(const string& filename) { string V3Os::filenameDir(const string& filename) VL_PURE {
string::size_type pos; // std::filesystem::path::parent_path
if ((pos = filename.rfind('/')) != string::npos) { auto it = filename.rbegin();
return filename.substr(0, pos); for (; it != filename.rend(); ++it) {
} else { if (isSlash(*it)) break;
}
if (it.base() == filename.begin()) {
return "."; return ".";
} else {
return {filename.begin(), (++it).base()};
} }
} }
string V3Os::filenameNonDir(const string& filename) VL_PURE { string V3Os::filenameNonDir(const string& filename) VL_PURE {
string::size_type pos; // std::filesystem::path::filename
if ((pos = filename.rfind('/')) != string::npos) { auto it = filename.rbegin();
return filename.substr(pos + 1); for (; it != filename.rend(); ++it) {
} else { if (isSlash(*it)) break;
return filename;
} }
return string{it.base(), filename.end()};
} }
string V3Os::filenameNonExt(const string& filename) VL_PURE { string V3Os::filenameNonExt(const string& filename) VL_PURE {
@ -202,7 +208,7 @@ string V3Os::filenameSubstitute(const string& filename) {
return result; return result;
} }
string V3Os::filenameRealPath(const string& filename) { string V3Os::filenameRealPath(const string& filename) VL_PURE {
// Get rid of all the ../ behavior in the middle of the paths. // Get rid of all the ../ behavior in the middle of the paths.
// If there is a ../ that goes down from the 'root' of this path it is preserved. // If there is a ../ that goes down from the 'root' of this path it is preserved.
char retpath[PATH_MAX]; char retpath[PATH_MAX];
@ -219,8 +225,12 @@ string V3Os::filenameRealPath(const string& filename) {
} }
} }
bool V3Os::filenameIsRel(const string& filename) { bool V3Os::filenameIsRel(const string& filename) VL_PURE {
#if defined(_MSC_VER)
return std::filesystem::path(filename).is_relative();
#else
return (filename.length() > 0 && filename[0] != '/'); return (filename.length() > 0 && filename[0] != '/');
#endif
} }
//###################################################################### //######################################################################
@ -251,12 +261,14 @@ void V3Os::createDir(const string& dirname) {
void V3Os::unlinkRegexp(const string& dir, const string& regexp) { void V3Os::unlinkRegexp(const string& dir, const string& regexp) {
#ifdef _MSC_VER #ifdef _MSC_VER
for (const auto& dirEntry : std::filesystem::directory_iterator(dir.c_str())) { try {
if (VString::wildmatch(dirEntry.path().filename().string(), regexp.c_str())) { for (const auto& dirEntry : std::filesystem::directory_iterator(dir.c_str())) {
const string fullname = dir + "/" + dirEntry.path().filename().string(); if (VString::wildmatch(dirEntry.path().filename().string(), regexp.c_str())) {
_unlink(fullname.c_str()); const string fullname = dir + "/" + dirEntry.path().filename().string();
_unlink(fullname.c_str());
}
} }
} } catch (std::filesystem::filesystem_error const& ex) {}
#else #else
if (DIR* const dirp = opendir(dir.c_str())) { if (DIR* const dirp = opendir(dir.c_str())) {
while (struct dirent* const direntp = readdir(dirp)) { while (struct dirent* const direntp = readdir(dirp)) {

View File

@ -35,20 +35,22 @@ public:
static void setenvStr(const string& envvar, const string& value, const string& why); static void setenvStr(const string& envvar, const string& value, const string& why);
// METHODS (generic filename utilities) // METHODS (generic filename utilities)
static string filenameFromDirBase(const string& dir, const string& basename); static string filenameFromDirBase(const string& dir, const string& basename) VL_PURE;
/// Return non-directory part of filename ///< Return non-directory part of filename
static string filenameNonDir(const string& filename) VL_PURE; static string filenameNonDir(const string& filename) VL_PURE;
/// Return non-extensioned (no .) part of filename ///< Return non-extensioned (no .) part of filename
static string filenameNonExt(const string& filename) VL_PURE; static string filenameNonExt(const string& filename) VL_PURE;
///< Return basename of filename ///< Return basename of filename
static string filenameNonDirExt(const string& filename) VL_PURE { static string filenameNonDirExt(const string& filename) VL_PURE {
return filenameNonExt(filenameNonDir(filename)); return filenameNonExt(filenameNonDir(filename));
} }
static string filenameDir(const string& filename); ///< Return directory part of filename ///< Return directory part of filename
static string filenameDir(const string& filename) VL_PURE;
/// Return filename with env vars removed /// Return filename with env vars removed
static string filenameSubstitute(const string& filename); static string filenameSubstitute(const string& filename);
static string filenameRealPath(const string& filename); ///< Return realpath of filename ///< Return realpath of filename
static bool filenameIsRel(const string& filename); ///< True if relative static string filenameRealPath(const string& filename) VL_PURE;
static bool filenameIsRel(const string& filename) VL_PURE; ///< True if relative
// METHODS (file utilities) // METHODS (file utilities)
static string getline(std::istream& is, char delim = '\n'); static string getline(std::istream& is, char delim = '\n');

View File

@ -181,7 +181,7 @@ public:
// We'll make the table with a separate natural alignment for each output var, so // We'll make the table with a separate natural alignment for each output var, so
// always have 8, 16 or 32 bit widths, so use widthTotalBytes // always have 8, 16 or 32 bit widths, so use widthTotalBytes
m_outWidthBytes += nodep->varp()->dtypeSkipRefp()->widthTotalBytes(); m_outWidthBytes += nodep->varp()->dtypeSkipRefp()->widthTotalBytes();
m_outVarps.emplace_back(vscp, m_outVarps.size()); m_outVarps.emplace_back(vscp, static_cast<unsigned>(m_outVarps.size()));
} }
if (nodep->access().isReadOrRW()) { if (nodep->access().isReadOrRW()) {
m_inWidthBits += nodep->varp()->width(); m_inWidthBits += nodep->varp()->width();