summaryrefslogtreecommitdiff
path: root/tools/llvm-cxxfilt
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2016-11-13 20:43:38 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2016-11-13 20:43:38 +0000
commita5627e5c59e8c60905dc1cf138ad86e311723417 (patch)
tree955b8b8719cc1f249c464b81188dd46749dfad8d /tools/llvm-cxxfilt
parent38feb36e4af139f1f231ff0f5da3a38953d9f167 (diff)
llvm-cxxfilt: support reading from stdin
`c++filt` when given no arguments runs as a REPL, decoding each line as a decorated name. Unify the test structure to be more uniform, with the tests for llvm-cxxfilt living under test/tools/llvm-cxxfilt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286777 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-cxxfilt')
-rw-r--r--tools/llvm-cxxfilt/llvm-cxxfilt.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/tools/llvm-cxxfilt/llvm-cxxfilt.cpp b/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
index 07b0e4e54ae..80a54bbf63d 100644
--- a/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
+++ b/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
@@ -9,18 +9,25 @@
#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/raw_ostream.h"
-
-#include <stdlib.h>
+#include <cstdlib>
+#include <iostream>
using namespace llvm;
+static void demangle(llvm::raw_ostream &OS, const char *Mangled) {
+ int Status;
+ char *Demangled = itaniumDemangle(Mangled, nullptr, nullptr, &Status);
+ OS << (Demangled ? Demangled : Mangled) << '\n';
+ free(Demangled);
+}
+
int main(int argc, char **argv) {
- for (int I = 1; I < argc; ++I) {
- const char *Mangled = argv[I];
- int Status;
- char *Demangled = itaniumDemangle(Mangled, nullptr, nullptr, &Status);
- llvm::outs() << (Demangled ? Demangled : Mangled) << '\n';
- free(Demangled);
- }
- return 0;
+ if (argc == 1)
+ for (std::string Mangled; std::getline(std::cin, Mangled);)
+ demangle(llvm::outs(), Mangled.c_str());
+ else
+ for (int I = 1; I < argc; ++I)
+ demangle(llvm::outs(), argv[I]);
+
+ return EXIT_SUCCESS;
}