mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-23 08:50:57 +01:00
Move demangle impl to cpp
This commit is contained in:
parent
80a55c1663
commit
ce0b8d618d
3 changed files with 36 additions and 23 deletions
|
@ -38,6 +38,7 @@ add_library(common STATIC
|
||||||
common_precompiled_headers.h
|
common_precompiled_headers.h
|
||||||
common_types.h
|
common_types.h
|
||||||
concepts.h
|
concepts.h
|
||||||
|
demangle.cpp
|
||||||
demangle.h
|
demangle.h
|
||||||
div_ceil.h
|
div_ceil.h
|
||||||
dynamic_library.cpp
|
dynamic_library.cpp
|
||||||
|
|
33
src/common/demangle.cpp
Normal file
33
src/common/demangle.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "common/demangle.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!demangled) {
|
||||||
|
return mangled;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ret = demangled;
|
||||||
|
std::free(demangled);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Common
|
|
@ -5,29 +5,8 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
char* itaniumDemangle(const char* mangled_name, char* buf, size_t* n, int* status);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Common {
|
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;
|
std::string DemangleSymbol(const std::string& mangled);
|
||||||
if (is_itanium(mangled)) {
|
|
||||||
demangled = llvm::itaniumDemangle(mangled.c_str(), nullptr, nullptr, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!demangled) {
|
|
||||||
return mangled;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ret = demangled;
|
|
||||||
std::free(demangled);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} // namespace Common
|
} // namespace Common
|
Loading…
Reference in a new issue