llvm-cov: Clean up memory leaks.
[oota-llvm.git] / tools / llvm-cov / llvm-cov.cpp
index 4a69c7145037cefc3f062acfcce790e5005b4946..5f6999e90564d8f631b0044aa21aa3d7914dbc1f 100644 (file)
@@ -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 file>"), cl::init(""));
 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";
@@ -49,7 +58,7 @@ int main(int argc, char **argv) {
     errs() << InputGCNO << ": " << ec.message() << "\n";
     return 1;
   }
-  GCOVBuffer GCNO_GB(GCNO_Buff.take());
+  GCOVBuffer GCNO_GB(GCNO_Buff.get());
   if (!GF.read(GCNO_GB)) {
     errs() << "Invalid .gcno File!\n";
     return 1;
@@ -61,7 +70,7 @@ int main(int argc, char **argv) {
       errs() << InputGCDA << ": " << ec.message() << "\n";
       return 1;
     }
-    GCOVBuffer GCDA_GB(GCDA_Buff.take());
+    GCOVBuffer GCDA_GB(GCDA_Buff.get());
     if (!GF.read(GCDA_GB)) {
       errs() << "Invalid .gcda File!\n";
       return 1;
@@ -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;
 }