[llvm] r286777 - llvm-cxxfilt: support reading from stdin
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 13 12:43:39 PST 2016
Author: compnerd
Date: Sun Nov 13 14:43:38 2016
New Revision: 286777
URL: http://llvm.org/viewvc/llvm-project?rev=286777&view=rev
Log:
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.
Added:
llvm/trunk/test/tools/llvm-cxxfilt/
llvm/trunk/test/tools/llvm-cxxfilt/noargs.test
llvm/trunk/test/tools/llvm-cxxfilt/simple.test
- copied, changed from r286776, llvm/trunk/test/Demangle/simple.test
Removed:
llvm/trunk/test/Demangle/lit.local.cfg
llvm/trunk/test/Demangle/simple.test
Modified:
llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
Removed: llvm/trunk/test/Demangle/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Demangle/lit.local.cfg?rev=286776&view=auto
==============================================================================
--- llvm/trunk/test/Demangle/lit.local.cfg (original)
+++ llvm/trunk/test/Demangle/lit.local.cfg (removed)
@@ -1 +0,0 @@
-config.suffixes = ['.test']
Removed: llvm/trunk/test/Demangle/simple.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Demangle/simple.test?rev=286776&view=auto
==============================================================================
--- llvm/trunk/test/Demangle/simple.test (original)
+++ llvm/trunk/test/Demangle/simple.test (removed)
@@ -1,4 +0,0 @@
-RUN: llvm-cxxfilt _Z1fi abc | FileCheck %s
-
-CHECK: f(int)
-CHECK-NEXT: abc
Added: llvm/trunk/test/tools/llvm-cxxfilt/noargs.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cxxfilt/noargs.test?rev=286777&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cxxfilt/noargs.test (added)
+++ llvm/trunk/test/tools/llvm-cxxfilt/noargs.test Sun Nov 13 14:43:38 2016
@@ -0,0 +1,10 @@
+RUN: sed -n 's/^STDIN: //p' %s | llvm-cxxfilt | FileCheck %s
+
+STDIN: _Znw
+STDIN: _Znwj
+STDIN: _Znwm
+
+CHECK: operator new
+CHECK: operator new(unsigned int)
+CHECK: operator new(unsigned long)
+
Copied: llvm/trunk/test/tools/llvm-cxxfilt/simple.test (from r286776, llvm/trunk/test/Demangle/simple.test)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cxxfilt/simple.test?p2=llvm/trunk/test/tools/llvm-cxxfilt/simple.test&p1=llvm/trunk/test/Demangle/simple.test&r1=286776&r2=286777&rev=286777&view=diff
==============================================================================
(empty)
Modified: llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp?rev=286777&r1=286776&r2=286777&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp (original)
+++ llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp Sun Nov 13 14:43:38 2016
@@ -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;
}
More information about the llvm-commits
mailing list