2016-09-07 03:16:48 +08:00
|
|
|
//===-- llvm-c++filt.cpp --------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Demangle/Demangle.h"
|
2017-01-20 12:25:26 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2016-09-28 02:50:30 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2016-11-14 04:43:38 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
2016-09-07 03:16:48 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2017-01-20 12:25:26 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
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<std::string>
|
|
|
|
Decorated(cl::Positional, cl::desc("<mangled>"), cl::ZeroOrMore);
|
|
|
|
|
2017-01-19 10:58:46 +08:00
|
|
|
static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
|
2016-11-14 04:43:38 +08:00
|
|
|
int Status;
|
2017-01-19 10:58:46 +08:00
|
|
|
char *Demangled = nullptr;
|
2017-01-20 12:25:26 +08:00
|
|
|
if (Types || ((Mangled.size() >= 2 && Mangled.compare(0, 2, "_Z")) ||
|
|
|
|
(Mangled.size() >= 4 && Mangled.compare(0, 4, "___Z"))))
|
2017-01-19 10:58:46 +08:00
|
|
|
Demangled = itaniumDemangle(Mangled.c_str(), nullptr, nullptr, &Status);
|
2016-11-14 04:43:38 +08:00
|
|
|
OS << (Demangled ? Demangled : Mangled) << '\n';
|
|
|
|
free(Demangled);
|
|
|
|
}
|
|
|
|
|
2016-09-07 03:16:48 +08:00
|
|
|
int main(int argc, char **argv) {
|
2017-01-20 12:25:26 +08:00
|
|
|
cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
|
|
|
|
|
|
|
|
if (Decorated.empty())
|
2016-11-14 04:43:38 +08:00
|
|
|
for (std::string Mangled; std::getline(std::cin, Mangled);)
|
2017-01-19 10:58:46 +08:00
|
|
|
demangle(llvm::outs(), Mangled);
|
2016-11-14 04:43:38 +08:00
|
|
|
else
|
2017-01-20 12:25:26 +08:00
|
|
|
for (const auto &Symbol : Decorated)
|
|
|
|
demangle(llvm::outs(), Symbol);
|
2016-11-14 04:43:38 +08:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2016-09-07 03:16:48 +08:00
|
|
|
}
|