Skip to content

Commit

Permalink
reduce OS ifdefs with OS_PATH_SEP
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Sep 11, 2024
1 parent 3457270 commit 7129b0e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
7 changes: 1 addition & 6 deletions backends/cxxrtl/cxxrtl_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,7 @@ std::string escape_cxx_string(const std::string &input)

std::string basename(const std::string &filepath)
{
#ifdef _WIN32
const std::string dir_seps = "\\/";
#else
const std::string dir_seps = "/";
#endif
size_t sep_pos = filepath.find_last_of(dir_seps);
size_t sep_pos = filepath.find_last_of(OS_PATH_SEP);
if (sep_pos != std::string::npos)
return filepath.substr(sep_pos + 1);
else
Expand Down
7 changes: 1 addition & 6 deletions frontends/ast/simplify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4382,12 +4382,7 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m
std::ifstream f;
f.open(mem_filename.c_str());
if (f.fail()) {
#ifdef _WIN32
char slash = '\\';
#else
char slash = '/';
#endif
std::string path = filename.substr(0, filename.find_last_of(slash)+1);
std::string path = filename.substr(0, filename.find_last_of(OS_PATH_SEP)+1);
f.open(path + mem_filename.c_str());
yosys_input_files.insert(path + mem_filename);
} else {
Expand Down
6 changes: 1 addition & 5 deletions frontends/verilog/preproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -892,11 +892,7 @@ frontend_verilog_preproc(std::istream &f,
// if the include file was not found, it is not given with an absolute path, and the
// currently read file is given with a path, then try again relative to its directory
ff.clear();
#ifdef _WIN32
fixed_fn = filename.substr(0, filename.find_last_of("/\\")+1) + fn;
#else
fixed_fn = filename.substr(0, filename.rfind('/')+1) + fn;
#endif
fixed_fn = filename.substr(0, filename.find_last_of(OS_PATH_SEP)+1) + fn;
ff.open(fixed_fn);
}
if (ff.fail() && fn.size() > 0 && fn_relative) {
Expand Down
5 changes: 5 additions & 0 deletions kernel/yosys_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ bool is_absolute_path(std::string filename);
void remove_directory(std::string dirname);
bool create_directory(const std::string& dirname);
std::string escape_filename_spaces(const std::string& filename);
#ifdef _WIN32
const char* const OS_PATH_SEP = "/\\";
#else
const char* const OS_PATH_SEP = "/";
#endif

template<typename T> int GetSize(const T &obj) { return obj.size(); }
inline int GetSize(RTLIL::Wire *wire);
Expand Down

0 comments on commit 7129b0e

Please sign in to comment.