1 //===-- llvm-c++filt.cpp --------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Demangle/Demangle.h"
11 #include "llvm/Support/CommandLine.h"
12 #include "llvm/Support/InitLLVM.h"
13 #include "llvm/Support/raw_ostream.h"
20 Auto
, ///< auto-detect mangling
22 Lucid
, ///< Lucid compiler (lcc)
24 HP
, ///< HP compiler (xCC)
25 EDG
, ///< EDG compiler
26 GNUv3
, ///< GNU C++ v3 ABI
28 GNAT
///< ADA copiler (gnat)
31 Format("format", cl::desc("decoration style"),
32 cl::values(clEnumValN(Auto
, "auto", "auto-detect style"),
33 clEnumValN(GNU
, "gnu", "GNU (itanium) style")),
35 static cl::alias
FormatShort("s", cl::desc("alias for --format"),
36 cl::aliasopt(Format
));
38 static cl::opt
<bool> StripUnderscore("strip-underscore",
39 cl::desc("strip the leading underscore"),
41 static cl::alias
StripUnderscoreShort("_",
42 cl::desc("alias for --strip-underscore"),
43 cl::aliasopt(StripUnderscore
));
47 cl::desc("attempt to demangle types as well as function names"),
49 static cl::alias
TypesShort("t", cl::desc("alias for --types"),
52 static cl::list
<std::string
>
53 Decorated(cl::Positional
, cl::desc("<mangled>"), cl::ZeroOrMore
);
55 static void demangle(llvm::raw_ostream
&OS
, const std::string
&Mangled
) {
58 const char *Decorated
= Mangled
.c_str();
60 if (Decorated
[0] == '_')
62 size_t DecoratedLength
= strlen(Decorated
);
64 char *Undecorated
= nullptr;
66 if (Types
|| ((DecoratedLength
>= 2 && strncmp(Decorated
, "_Z", 2) == 0) ||
67 (DecoratedLength
>= 4 && strncmp(Decorated
, "___Z", 4) == 0)))
68 Undecorated
= itaniumDemangle(Decorated
, nullptr, nullptr, &Status
);
71 (DecoratedLength
> 6 && strncmp(Decorated
, "__imp_", 6) == 0)) {
72 OS
<< "import thunk for ";
73 Undecorated
= itaniumDemangle(Decorated
+ 6, nullptr, nullptr, &Status
);
76 OS
<< (Undecorated
? Undecorated
: Mangled
) << '\n';
82 int main(int argc
, char **argv
) {
83 InitLLVM
X(argc
, argv
);
85 cl::ParseCommandLineOptions(argc
, argv
, "llvm symbol undecoration tool\n");
87 if (Decorated
.empty())
88 for (std::string Mangled
; std::getline(std::cin
, Mangled
);)
89 demangle(llvm::outs(), Mangled
);
91 for (const auto &Symbol
: Decorated
)
92 demangle(llvm::outs(), Symbol
);