diff options
author | James Henderson <jh7370@my.bristol.ac.uk> | 2019-01-17 15:18:44 +0000 |
---|---|---|
committer | James Henderson <jh7370@my.bristol.ac.uk> | 2019-01-17 15:18:44 +0000 |
commit | ce5b5b486a71939913b1a0909498f216b5528401 (patch) | |
tree | b82d02f6abbae0060909f263503a50d3ea206227 /llvm/lib/Demangle | |
parent | 7630e0bcbe087918b31ba018af742a59989550df (diff) | |
download | bcm5719-llvm-ce5b5b486a71939913b1a0909498f216b5528401.tar.gz bcm5719-llvm-ce5b5b486a71939913b1a0909498f216b5528401.zip |
Move demangling function from llvm-objdump to Demangle library
This allows it to be used in an upcoming llvm-readobj change.
A small change in internal behaviour of the function is to always call
the microsoftDemangle function if the string does not have an itanium
encoding prefix, rather than only if it starts with '?'. This is
harmless because the microsoftDemangle function does the same check
already.
Reviewed by: grimar, erik.pilkington
Differential Revision: https://reviews.llvm.org/D56721
llvm-svn: 351448
Diffstat (limited to 'llvm/lib/Demangle')
-rw-r--r-- | llvm/lib/Demangle/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Demangle/Demangle.cpp | 30 |
2 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/Demangle/CMakeLists.txt b/llvm/lib/Demangle/CMakeLists.txt index a681af979e4..cde1a4c5c28 100644 --- a/llvm/lib/Demangle/CMakeLists.txt +++ b/llvm/lib/Demangle/CMakeLists.txt @@ -1,4 +1,5 @@ add_llvm_library(LLVMDemangle + Demangle.cpp ItaniumDemangle.cpp MicrosoftDemangle.cpp MicrosoftDemangleNodes.cpp diff --git a/llvm/lib/Demangle/Demangle.cpp b/llvm/lib/Demangle/Demangle.cpp new file mode 100644 index 00000000000..8a37b92fc35 --- /dev/null +++ b/llvm/lib/Demangle/Demangle.cpp @@ -0,0 +1,30 @@ +//===-- Demangle.cpp - Common demangling functions ------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file This file contains definitions of common demangling functions. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/Demangle/Demangle.h" + +std::string llvm::demangle(const std::string &MangledName) { + char *Demangled; + if (MangledName.compare(0, 2, "_Z") == 0) + Demangled = itaniumDemangle(MangledName.c_str(), nullptr, nullptr, nullptr); + else + Demangled = + microsoftDemangle(MangledName.c_str(), nullptr, nullptr, nullptr); + + if (!Demangled) + return MangledName; + + std::string Ret = Demangled; + free(Demangled); + return Ret; +} |