cxxrtl: Use the base name of the interface file for the include directive

Prior to this fix, the `CxxrtlBackend` used the entire path for the include
directive when a separated interface file is generated (via the `-header`
option). This commit updates the code to use the base name of the interface
file.

Since the C++11 standard is used by default, we cannot take advantage of
the `std::filesystem` to get the basename.
This commit is contained in:
Henri Nurmi 2023-12-09 22:27:05 +02:00 committed by Catherine
parent 3ea6bca23e
commit dbff694e3d
1 changed files with 17 additions and 1 deletions

View File

@ -628,6 +628,22 @@ std::string escape_cxx_string(const std::string &input)
return output;
}
std::string basename(const std::string &filepath)
{
#ifndef _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 && sep_pos + 1 < filepath.length()) {
return filepath.substr(sep_pos + 1);
}
else {
return filepath;
}
}
template<class T>
std::string get_hdl_name(T *object)
{
@ -2571,7 +2587,7 @@ struct CxxrtlWorker {
}
if (split_intf)
f << "#include \"" << intf_filename << "\"\n";
f << "#include \"" << basename(intf_filename) << "\"\n";
else
f << "#include <cxxrtl/cxxrtl.h>\n";
if (has_prints)