Skip to content

Commit

Permalink
cxxrtl: Use the base name of the interface file for the include direc…
Browse files Browse the repository at this point in the history
…tive

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.
  • Loading branch information
Henkru committed Dec 10, 2023
1 parent 373b651 commit ceed04b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion backends/cxxrtl/cxxrtl_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ceed04b

Please sign in to comment.