aboutsummaryrefslogtreecommitdiff
path: root/Common/Strings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Common/Strings.cpp')
-rw-r--r--Common/Strings.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/Common/Strings.cpp b/Common/Strings.cpp
new file mode 100644
index 000000000000..6cd4ad8d600a
--- /dev/null
+++ b/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;
+}