diff --git a/llvm/test/tools/llvm-cxxfilt/types.test b/llvm/test/tools/llvm-cxxfilt/types.test new file mode 100644 index 000000000000..4f0b2ecaab16 --- /dev/null +++ b/llvm/test/tools/llvm-cxxfilt/types.test @@ -0,0 +1,5 @@ +RUN: llvm-cxxfilt -t f i | FileCheck %s + +CHECK: float +CHECK-NEXT: int + diff --git a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp index 1e2797ba3334..525cea28ff3d 100644 --- a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp +++ b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp @@ -8,29 +8,42 @@ //===----------------------------------------------------------------------===// #include "llvm/Demangle/Demangle.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" #include #include using namespace llvm; +static cl::opt + Types("types", + cl::desc("attempt to demangle types as well as function names"), + cl::init(false)); +static cl::alias TypesShort("t", cl::desc("alias for --types"), + cl::aliasopt(Types)); + +static cl::list +Decorated(cl::Positional, cl::desc(""), cl::ZeroOrMore); + static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) { int Status; char *Demangled = nullptr; - if ((Mangled.size() >= 2 && Mangled.compare(0, 2, "_Z")) || - (Mangled.size() >= 4 && Mangled.compare(0, 4, "___Z"))) + if (Types || ((Mangled.size() >= 2 && Mangled.compare(0, 2, "_Z")) || + (Mangled.size() >= 4 && Mangled.compare(0, 4, "___Z")))) Demangled = itaniumDemangle(Mangled.c_str(), nullptr, nullptr, &Status); OS << (Demangled ? Demangled : Mangled) << '\n'; free(Demangled); } int main(int argc, char **argv) { - if (argc == 1) + cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n"); + + if (Decorated.empty()) for (std::string Mangled; std::getline(std::cin, Mangled);) demangle(llvm::outs(), Mangled); else - for (int I = 1; I < argc; ++I) - demangle(llvm::outs(), argv[I]); + for (const auto &Symbol : Decorated) + demangle(llvm::outs(), Symbol); return EXIT_SUCCESS; }