mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-06 22:23:23 +00:00
reduce OS ifdefs, refactor getting dirs and filenames from paths to files
This commit is contained in:
parent
f20f913223
commit
1759609321
5 changed files with 24 additions and 26 deletions
|
@ -637,20 +637,6 @@ std::string escape_cxx_string(const std::string &input)
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
if (sep_pos != std::string::npos)
|
|
||||||
return filepath.substr(sep_pos + 1);
|
|
||||||
else
|
|
||||||
return filepath;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
std::string get_hdl_name(T *object)
|
std::string get_hdl_name(T *object)
|
||||||
{
|
{
|
||||||
|
@ -2841,7 +2827,7 @@ struct CxxrtlWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split_intf)
|
if (split_intf)
|
||||||
f << "#include \"" << basename(intf_filename) << "\"\n";
|
f << "#include \"" << name_from_file_path(intf_filename) << "\"\n";
|
||||||
else
|
else
|
||||||
f << "#include <cxxrtl/cxxrtl.h>\n";
|
f << "#include <cxxrtl/cxxrtl.h>\n";
|
||||||
f << "\n";
|
f << "\n";
|
||||||
|
|
|
@ -4440,12 +4440,7 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m
|
||||||
std::ifstream f;
|
std::ifstream f;
|
||||||
f.open(mem_filename.c_str());
|
f.open(mem_filename.c_str());
|
||||||
if (f.fail()) {
|
if (f.fail()) {
|
||||||
#ifdef _WIN32
|
std::string path = parent_from_file_path(filename);
|
||||||
char slash = '\\';
|
|
||||||
#else
|
|
||||||
char slash = '/';
|
|
||||||
#endif
|
|
||||||
std::string path = filename.substr(0, filename.find_last_of(slash)+1);
|
|
||||||
f.open(path + mem_filename.c_str());
|
f.open(path + mem_filename.c_str());
|
||||||
yosys_input_files.insert(path + mem_filename);
|
yosys_input_files.insert(path + mem_filename);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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
|
// 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
|
// currently read file is given with a path, then try again relative to its directory
|
||||||
ff.clear();
|
ff.clear();
|
||||||
#ifdef _WIN32
|
fixed_fn = parent_from_file_path(filename) + fn;
|
||||||
fixed_fn = filename.substr(0, filename.find_last_of("/\\")+1) + fn;
|
|
||||||
#else
|
|
||||||
fixed_fn = filename.substr(0, filename.rfind('/')+1) + fn;
|
|
||||||
#endif
|
|
||||||
ff.open(fixed_fn);
|
ff.open(fixed_fn);
|
||||||
}
|
}
|
||||||
if (ff.fail() && fn.size() > 0 && fn_relative) {
|
if (ff.fail() && fn.size() > 0 && fn_relative) {
|
||||||
|
|
|
@ -540,6 +540,25 @@ std::string escape_filename_spaces(const std::string& filename)
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
const char* const OS_PATH_SEP = "/\\";
|
||||||
|
#else
|
||||||
|
const char* const OS_PATH_SEP = "/";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string name_from_file_path(std::string path) {
|
||||||
|
size_t sep_pos = path.find_last_of(OS_PATH_SEP);
|
||||||
|
if (sep_pos != std::string::npos)
|
||||||
|
return path.substr(sep_pos + 1);
|
||||||
|
else
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Includes OS_PATH_SEP at the end if present
|
||||||
|
std::string parent_from_file_path(std::string path) {
|
||||||
|
return path.substr(0, path.find_last_of(OS_PATH_SEP)+1);
|
||||||
|
}
|
||||||
|
|
||||||
bool already_setup = false;
|
bool already_setup = false;
|
||||||
|
|
||||||
void yosys_setup()
|
void yosys_setup()
|
||||||
|
|
|
@ -343,6 +343,8 @@ bool is_absolute_path(std::string filename);
|
||||||
void remove_directory(std::string dirname);
|
void remove_directory(std::string dirname);
|
||||||
bool create_directory(const std::string& dirname);
|
bool create_directory(const std::string& dirname);
|
||||||
std::string escape_filename_spaces(const std::string& filename);
|
std::string escape_filename_spaces(const std::string& filename);
|
||||||
|
std::string name_from_file_path(std::string path);
|
||||||
|
std::string parent_from_file_path(std::string path);
|
||||||
|
|
||||||
template<typename T> int GetSize(const T &obj) { return obj.size(); }
|
template<typename T> int GetSize(const T &obj) { return obj.size(); }
|
||||||
inline int GetSize(RTLIL::Wire *wire);
|
inline int GetSize(RTLIL::Wire *wire);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue