[llvm-pdbdump] Remove unused variables.
[oota-llvm.git] / tools / llvm-cov / CodeCoverage.cpp
index 9e2f154c233f63b564acc291b42062194d2c37c1..cf8ab3377979aab5bf2886fca7e69aecfb1863e3 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "RenderingSupport.h"
-#include "CoverageViewOptions.h"
 #include "CoverageFilters.h"
-#include "SourceCoverageView.h"
-#include "CoverageSummary.h"
 #include "CoverageReport.h"
-#include "llvm/ADT/StringRef.h"
+#include "CoverageViewOptions.h"
+#include "SourceCoverageView.h"
 #include "llvm/ADT/SmallString.h"
-#include "llvm/ProfileData/InstrProfReader.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ProfileData/CoverageMapping.h"
-#include "llvm/ProfileData/CoverageMappingReader.h"
+#include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/MemoryObject.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/Signals.h"
 #include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Signals.h"
 #include <functional>
 #include <system_error>
 
@@ -81,7 +78,7 @@ public:
   int report(int argc, const char **argv,
              CommandLineParserType commandLineParser);
 
-  StringRef ObjectFilename;
+  std::string ObjectFilename;
   CoverageViewOptions ViewOpts;
   std::string PGOFilename;
   CoverageFiltersMatchAll Filters;
@@ -233,6 +230,10 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
   PrettyStackTraceProgram X(argc, argv);
   llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
 
+  cl::opt<std::string, true> ObjectFilename(
+      cl::Positional, cl::Required, cl::location(this->ObjectFilename),
+      cl::desc("Covered executable or object file."));
+
   cl::list<std::string> InputSourceFiles(
       cl::Positional, cl::desc("<Source files>"), cl::ZeroOrMore);
 
@@ -323,32 +324,16 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
 
     for (const auto &File : InputSourceFiles) {
       SmallString<128> Path(File);
-      if (std::error_code EC = sys::fs::make_absolute(Path)) {
-        errs() << "error: " << File << ": " << EC.message();
-        return 1;
-      }
+      if (!CompareFilenamesOnly)
+        if (std::error_code EC = sys::fs::make_absolute(Path)) {
+          errs() << "error: " << File << ": " << EC.message();
+          return 1;
+        }
       SourceFiles.push_back(Path.str());
     }
     return 0;
   };
 
-  // Parse the object filename
-  if (argc > 1) {
-    StringRef Arg(argv[1]);
-    if (Arg.equals_lower("-help") || Arg.equals_lower("-version")) {
-      cl::ParseCommandLineOptions(2, argv, "LLVM code coverage tool\n");
-      return 0;
-    }
-    ObjectFilename = Arg;
-
-    argv[1] = argv[0];
-    --argc;
-    ++argv;
-  } else {
-    errs() << sys::path::filename(argv[0]) << ": No executable file given!\n";
-    return 1;
-  }
-
   switch (Cmd) {
   case Show:
     return show(argc, argv, commandLineParser);
@@ -474,24 +459,20 @@ int CodeCoverageTool::report(int argc, const char **argv,
   if (!Coverage)
     return 1;
 
-  CoverageSummary Summarizer;
-  Summarizer.createSummaries(Coverage->getCoveredFunctions());
-  CoverageReport Report(ViewOpts, Summarizer);
-  if (SourceFiles.empty() && Filters.empty()) {
+  CoverageReport Report(ViewOpts, std::move(Coverage));
+  if (SourceFiles.empty())
     Report.renderFileReports(llvm::outs());
-    return 0;
-  }
-
-  Report.renderFunctionReports(llvm::outs());
+  else
+    Report.renderFunctionReports(SourceFiles, llvm::outs());
   return 0;
 }
 
-int show_main(int argc, const char **argv) {
+int showMain(int argc, const char *argv[]) {
   CodeCoverageTool Tool;
   return Tool.run(CodeCoverageTool::Show, argc, argv);
 }
 
-int report_main(int argc, const char **argv) {
+int reportMain(int argc, const char *argv[]) {
   CodeCoverageTool Tool;
   return Tool.run(CodeCoverageTool::Report, argc, argv);
 }