Move demangle impl to cpp

This commit is contained in:
Kelebek1 2023-01-14 05:12:41 +00:00
parent 80a55c1663
commit ce0b8d618d
3 changed files with 36 additions and 23 deletions

View file

@ -5,29 +5,8 @@
#include <string>
namespace llvm {
char* itaniumDemangle(const char* mangled_name, char* buf, size_t* n, int* status);
}
namespace Common {
std::string DemangleSymbol(const std::string& mangled) {
auto is_itanium = [](const std::string& name) -> bool {
// A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
auto pos = name.find_first_not_of('_');
return pos > 0 && pos <= 4 && name[pos] == 'Z';
};
char* demangled = nullptr;
if (is_itanium(mangled)) {
demangled = llvm::itaniumDemangle(mangled.c_str(), nullptr, nullptr, nullptr);
}
std::string DemangleSymbol(const std::string& mangled);
if (!demangled) {
return mangled;
}
std::string ret = demangled;
std::free(demangled);
return ret;
}
} // namespace Common
} // namespace Common