summaryrefslogtreecommitdiffstats
path: root/lld/Common/Strings.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-11-28 02:15:26 +0000
committerRui Ueyama <ruiu@google.com>2017-11-28 02:15:26 +0000
commit53fe469162ea0ed8fd24377dd44de9f560307312 (patch)
treec48a6b5fca8b71523c6f02fb27ec5cdb1d6f4cfa /lld/Common/Strings.cpp
parent3ecd20430cace7eb9e78ef0a9ff9cc95a377feb9 (diff)
downloadbcm5719-llvm-53fe469162ea0ed8fd24377dd44de9f560307312.tar.gz
bcm5719-llvm-53fe469162ea0ed8fd24377dd44de9f560307312.zip
Factor out common code to Common/Strings.cpp.
Differential Revision: https://reviews.llvm.org/D40530 llvm-svn: 319138
Diffstat (limited to 'lld/Common/Strings.cpp')
-rw-r--r--lld/Common/Strings.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/lld/Common/Strings.cpp b/lld/Common/Strings.cpp
new file mode 100644
index 00000000000..6cd4ad8d600
--- /dev/null
+++ b/lld/Common/Strings.cpp
@@ -0,0 +1,32 @@
+//===- Strings.cpp -------------------------------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lld/Common/Strings.h"
+#include "llvm/Demangle/Demangle.h"
+
+using namespace llvm;
+using namespace lld;
+
+// Returns the demangled C++ symbol name for Name.
+Optional<std::string> lld::demangleItanium(StringRef Name) {
+ // itaniumDemangle can be used to demangle strings other than symbol
+ // names which do not necessarily start with "_Z". Name can be
+ // either a C or C++ symbol. Don't call itaniumDemangle if the name
+ // does not look like a C++ symbol name to avoid getting unexpected
+ // result for a C symbol that happens to match a mangled type name.
+ if (!Name.startswith("_Z"))
+ return None;
+
+ char *Buf = itaniumDemangle(Name.str().c_str(), nullptr, nullptr, nullptr);
+ if (!Buf)
+ return None;
+ std::string S(Buf);
+ free(Buf);
+ return S;
+}
OpenPOWER on IntegriCloud