-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
space-time-stack: allow demangled names
- Loading branch information
1 parent
6dae155
commit 0d318fd
Showing
4 changed files
with
77 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#ifndef KOKKOSTOOLS_COMMON_UTILS_DEMANGLE_HPP | ||
#define KOKKOSTOOLS_COMMON_UTILS_DEMANGLE_HPP | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#if defined(__GXX_ABI_VERSION) | ||
#define HAVE_GCC_ABI_DEMANGLE | ||
#endif | ||
|
||
#if defined(HAVE_GCC_ABI_DEMANGLE) | ||
#include <cxxabi.h> | ||
#endif // HAVE_GCC_ABI_DEMANGLE | ||
|
||
namespace KokkosTools | ||
{ | ||
|
||
//! Demangle @p mangledName implementation. | ||
inline auto demangleNameImpl(const char* mangled_name) | ||
{ | ||
int status = 0; | ||
|
||
std::unique_ptr<char, decltype(&std::free)> demangled_name( | ||
abi::__cxa_demangle(mangled_name, nullptr, nullptr, &status), | ||
&std::free | ||
); | ||
|
||
if(status != 0) demangled_name.reset(); | ||
|
||
return demangled_name; | ||
} | ||
|
||
/** | ||
* @brief Demangle @p mangledName. | ||
* | ||
* @note If the name was successfully demangled, @p mangledName | ||
* is freed and the returned pointer must be freed by the caller. | ||
*/ | ||
inline char* demangleName(char* mangledName) | ||
{ | ||
#if defined(HAVE_GCC_ABI_DEMANGLE) | ||
auto demangled_name = demangleNameImpl(mangledName); | ||
|
||
if(demangled_name != nullptr) | ||
{ | ||
std::free(mangledName); | ||
mangledName = demangled_name.release(); | ||
} | ||
#endif // HAVE_GCC_ABI_DEMANGLE | ||
return mangledName; | ||
} | ||
|
||
//! @overload | ||
inline std::string demangleName(const std::string& mangledName ) | ||
{ | ||
#if defined(HAVE_GCC_ABI_DEMANGLE) | ||
auto demangled_name = demangleNameImpl(mangledName.c_str()); | ||
|
||
if(demangled_name != nullptr) | ||
{ | ||
return std::string(demangled_name.get()); | ||
} | ||
#else | ||
return mangledName; | ||
#endif | ||
} | ||
|
||
} // namespace KokkosTools | ||
|
||
#endif // KOKKOSTOOLS_COMMON_UTILS_DEMANGLE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters