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 9f35507
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 @@ -334,6 +334,11 @@ int run_command(const std::string &command, std::function<void(const std::string
std::string get_base_tmpdir();
std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
#ifdef _WIN32
const char* OS_PATH_SEP = "/\\";
#else
const char* OS_PATH_SEP = "/";
#endif
bool check_file_exists(std::string filename, bool is_exec = false);
bool check_directory_exists(const std::string& dirname);
bool is_absolute_path(std::string filename);
Expand Down

0 comments on commit 9f35507

Please sign in to comment.