llvm-cov: Don't manually parse an option for no reason
authorJustin Bogner <mail@justinbogner.com>
Thu, 30 Oct 2014 20:51:24 +0000 (20:51 +0000)
committerJustin Bogner <mail@justinbogner.com>
Thu, 30 Oct 2014 20:51:24 +0000 (20:51 +0000)
We're using cl::opt here, but for some reason we're reading out one
particular option by hand instead. This makes -help and the like
behave rather poorly, so let's not do it this way.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220928 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-cov/CodeCoverage.cpp

index 9e2f154..eef4732 100644 (file)
@@ -81,7 +81,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 +233,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);
 
@@ -332,23 +336,6 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
     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);