From 9d2f1c607a1fe12a0410e6dcb93cfab139edddd2 Mon Sep 17 00:00:00 2001 From: Kritik Bhimani Date: Wed, 14 Dec 2022 17:37:25 +0530 Subject: [PATCH] Fix MSVCC issues (#3813) --- include/verilatedos.h | 8 +++++++- src/V3Options.cpp | 18 +++++++++++++++++- src/V3Os.cpp | 16 +++++++++++++++- src/V3Sched.cpp | 2 +- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/include/verilatedos.h b/include/verilatedos.h index d5906b526..9906e876f 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -231,10 +231,16 @@ } while (false); \ } while (false) +#ifdef _MSC_VER +# if _MSC_VER < 1929 +# error "Verilator requires at least Visual Studio 2019 version 16.11.2" +# endif +#endif + //========================================================================= // C++-2011 -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(VL_CPPCHECK) || (defined(_MSC_VER) && _MSC_VER >= 1900) +#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(VL_CPPCHECK) || defined(_MSC_VER) #else # error "Verilator requires a C++11 or newer compiler" #endif diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 49ef7aeed..3d920dfca 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -36,7 +36,12 @@ #endif #include #include -#include +#ifdef _MSC_VER +# include // C++17 +# define S_ISDIR(mode) (((mode) & _S_IFMT) == _S_IFDIR) +#else +# include +#endif #include #include #include @@ -454,11 +459,17 @@ void V3Options::fileNfsFlush(const string& filename) { // NFS caches stat() calls so to get up-to-date information must // do a open or opendir on the filename. // Faster to just try both rather than check if a file is a dir. +#ifdef _MSC_VER + if (int fd = ::open(filename.c_str(), O_RDONLY)) { // LCOV_EXCL_BR_LINE + if (fd > 0) ::close(fd); + } +#else if (DIR* const dirp = opendir(filename.c_str())) { // LCOV_EXCL_BR_LINE closedir(dirp); // LCOV_EXCL_LINE } else if (int fd = ::open(filename.c_str(), O_RDONLY)) { // LCOV_EXCL_BR_LINE if (fd > 0) ::close(fd); } +#endif } string V3Options::fileExists(const string& filename) { @@ -477,10 +488,15 @@ string V3Options::fileExists(const string& filename) { std::set* setp = &(diriter->second); +#ifdef _MSC_VER + for (const auto& dirEntry : std::filesystem::directory_iterator(dir.c_str())) + setp->insert(dirEntry.path().filename().string()); +#else if (DIR* const dirp = opendir(dir.c_str())) { while (struct dirent* direntp = readdir(dirp)) setp->insert(direntp->d_name); closedir(dirp); } +#endif } // Find it const std::set* filesetp = &(diriter->second); diff --git a/src/V3Os.cpp b/src/V3Os.cpp index 75b82de44..5fa1ef11b 100644 --- a/src/V3Os.cpp +++ b/src/V3Os.cpp @@ -40,7 +40,12 @@ VL_DEFINE_DEBUG_FUNCTIONS; #include #include // PATH_MAX (especially on FreeBSD) #include -#include +#ifdef _MSC_VER +# include // C++17 +# define PATH_MAX MAX_PATH +#else +# include +#endif #include #include @@ -245,6 +250,14 @@ void V3Os::createDir(const string& dirname) { } void V3Os::unlinkRegexp(const string& dir, const string& regexp) { +#ifdef _MSC_VER + for (const auto& dirEntry : std::filesystem::directory_iterator(dir.c_str())) { + if (VString::wildmatch(dirEntry.path().filename().string(), regexp.c_str())) { + const string fullname = dir + "/" + dirEntry.path().filename().string(); + _unlink(fullname.c_str()); + } + } +#else if (DIR* const dirp = opendir(dir.c_str())) { while (struct dirent* const direntp = readdir(dirp)) { if (VString::wildmatch(direntp->d_name, regexp.c_str())) { @@ -258,6 +271,7 @@ void V3Os::unlinkRegexp(const string& dir, const string& regexp) { } closedir(dirp); } +#endif } //###################################################################### diff --git a/src/V3Sched.cpp b/src/V3Sched.cpp index 73dd6afff..885e5d4a0 100644 --- a/src/V3Sched.cpp +++ b/src/V3Sched.cpp @@ -302,7 +302,7 @@ struct TriggerKit { // The map from input sensitivity list to trigger sensitivity list const std::unordered_map m_map; - VL_UNCOPYABLE(TriggerKit); + // No VL_UNCOPYABLE(TriggerKit) as causes C++20 errors on MSVC // Utility that assigns the given index trigger to fire when the given variable is zero void addFirstIterationTriggerAssignment(AstVarScope* counterp, uint32_t /*index*/) const {