Fix MSVCC issues (#3813)

This commit is contained in:
Kritik Bhimani 2022-12-14 17:37:25 +05:30 committed by GitHub
parent f331c192b4
commit 9d2f1c607a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 4 deletions

View File

@ -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

View File

@ -36,7 +36,12 @@
#endif
#include <algorithm>
#include <cctype>
#include <dirent.h>
#ifdef _MSC_VER
# include <filesystem> // C++17
# define S_ISDIR(mode) (((mode) & _S_IFMT) == _S_IFDIR)
#else
# include <dirent.h>
#endif
#include <fcntl.h>
#include <list>
#include <map>
@ -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<string>* 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<string>* filesetp = &(diriter->second);

View File

@ -40,7 +40,12 @@ VL_DEFINE_DEBUG_FUNCTIONS;
#include <cerrno>
#include <climits> // PATH_MAX (especially on FreeBSD)
#include <cstdarg>
#include <dirent.h>
#ifdef _MSC_VER
# include <filesystem> // C++17
# define PATH_MAX MAX_PATH
#else
# include <dirent.h>
#endif
#include <fstream>
#include <memory>
@ -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
}
//######################################################################

View File

@ -302,7 +302,7 @@ struct TriggerKit {
// The map from input sensitivity list to trigger sensitivity list
const std::unordered_map<const AstSenTree*, AstSenTree*> 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 {