[llvm] r193899 - Added command-line option to output llvm-cov to file.

Yuchen Wu yuchenericwu at hotmail.com
Fri Nov 1 17:09:18 PDT 2013


Author: ywu
Date: Fri Nov  1 19:09:17 2013
New Revision: 193899

URL: http://llvm.org/viewvc/llvm-project?rev=193899&view=rev
Log:
Added command-line option to output llvm-cov to file.

Added -o option to llvm-cov. If no output file is specified, it defaults
to STDOUT.

Modified:
    llvm/trunk/include/llvm/Support/GCOV.h
    llvm/trunk/lib/IR/GCOV.cpp
    llvm/trunk/tools/llvm-cov/llvm-cov.cpp

Modified: llvm/trunk/include/llvm/Support/GCOV.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GCOV.h?rev=193899&r1=193898&r2=193899&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GCOV.h (original)
+++ llvm/trunk/include/llvm/Support/GCOV.h Fri Nov  1 19:09:17 2013
@@ -235,7 +235,7 @@ public:
     LineInfo[Filename][Line-1] += Count;
   }
   void setProgramCount(uint32_t PC) { ProgramCount = PC; }
-  void print(StringRef gcnoFile, StringRef gcdaFile);
+  void print(raw_fd_ostream &OS, StringRef gcnoFile, StringRef gcdaFile);
 private:
   StringMap<LineCounts> LineInfo;
   uint32_t ProgramCount;

Modified: llvm/trunk/lib/IR/GCOV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/GCOV.cpp?rev=193899&r1=193898&r2=193899&view=diff
==============================================================================
--- llvm/trunk/lib/IR/GCOV.cpp (original)
+++ llvm/trunk/lib/IR/GCOV.cpp Fri Nov  1 19:09:17 2013
@@ -250,14 +250,15 @@ void GCOVLines::dump() {
 // FileInfo implementation.
 
 /// print -  Print source files with collected line count information.
-void FileInfo::print(StringRef gcnoFile, StringRef gcdaFile) {
+void FileInfo::print(raw_fd_ostream &OS, StringRef gcnoFile,
+                     StringRef gcdaFile) {
   for (StringMap<LineCounts>::iterator I = LineInfo.begin(), E = LineInfo.end();
        I != E; ++I) {
     StringRef Filename = I->first();
-    outs() << "        -:    0:Source:" << Filename << "\n";
-    outs() << "        -:    0:Graph:" << gcnoFile << "\n";
-    outs() << "        -:    0:Data:" << gcdaFile << "\n";
-    outs() << "        -:    0:Programs:" << ProgramCount << "\n";
+    OS << "        -:    0:Source:" << Filename << "\n";
+    OS << "        -:    0:Graph:" << gcnoFile << "\n";
+    OS << "        -:    0:Data:" << gcdaFile << "\n";
+    OS << "        -:    0:Programs:" << ProgramCount << "\n";
     LineCounts &L = LineInfo[Filename];
     OwningPtr<MemoryBuffer> Buff;
     if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
@@ -269,16 +270,16 @@ void FileInfo::print(StringRef gcnoFile,
     while (!AllLines.empty()) {
       if (L.find(i) != L.end()) {
         if (L[i] == 0)
-          outs() << "    #####:";
+          OS << "    #####:";
         else
-          outs() << format("%9lu:", L[i]);
+          OS << format("%9lu:", L[i]);
       } else {
-        outs() << "        -:";
+        OS << "        -:";
       }
       std::pair<StringRef, StringRef> P = AllLines.split('\n');
       if (AllLines != P.first)
-        outs() << format("%5u:", i+1) << P.first;
-      outs() << "\n";
+        OS << format("%5u:", i+1) << P.first;
+      OS << "\n";
       AllLines = P.second;
       ++i;
     }

Modified: llvm/trunk/tools/llvm-cov/llvm-cov.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/llvm-cov.cpp?rev=193899&r1=193898&r2=193899&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/llvm-cov.cpp (original)
+++ llvm/trunk/tools/llvm-cov/llvm-cov.cpp Fri Nov  1 19:09:17 2013
@@ -17,6 +17,7 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryObject.h"
 #include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/system_error.h"
 using namespace llvm;
@@ -30,6 +31,9 @@ InputGCNO("gcno", cl::desc("<input gcno
 static cl::opt<std::string>
 InputGCDA("gcda", cl::desc("<input gcda file>"), cl::init(""));
 
+static cl::opt<std::string>
+OutputFile("o", cl::desc("<output llvm-cov file>"), cl::init("-"));
+
 
 //===----------------------------------------------------------------------===//
 int main(int argc, char **argv) {
@@ -40,6 +44,11 @@ int main(int argc, char **argv) {
 
   cl::ParseCommandLineOptions(argc, argv, "llvm coverage tool\n");
 
+  std::string ErrorInfo;
+  raw_fd_ostream OS(OutputFile.c_str(), ErrorInfo);
+  if (!ErrorInfo.empty())
+    errs() << ErrorInfo << "\n";
+
   GCOVFile GF;
   if (InputGCNO.empty())
     errs() << " " << argv[0] << ": No gcov input file!\n";
@@ -74,6 +83,6 @@ int main(int argc, char **argv) {
 
   FileInfo FI;
   GF.collectLineCounts(FI);
-  FI.print(InputGCNO, InputGCDA);
+  FI.print(OS, InputGCNO, InputGCDA);
   return 0;
 }





More information about the llvm-commits mailing list