diff tools/llvm-cov/llvm-cov.cpp @ 95:afa8332a0e37 LLVM3.8

LLVM 3.8
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Tue, 13 Oct 2015 17:48:58 +0900
parents 60c9769439b8
children 1172e4bd9c6f
line wrap: on
line diff
--- a/tools/llvm-cov/llvm-cov.cpp	Wed Feb 18 14:56:07 2015 +0900
+++ b/tools/llvm-cov/llvm-cov.cpp	Tue Oct 13 17:48:58 2015 +0900
@@ -13,7 +13,9 @@
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/raw_ostream.h"
 #include <string>
 
@@ -32,9 +34,19 @@
 int gcovMain(int argc, const char *argv[]);
 
 /// \brief Top level help.
-int helpMain(int argc, const char *argv[]) {
-  errs() << "OVERVIEW: LLVM code coverage tool\n\n"
-         << "USAGE: llvm-cov {gcov|report|show}\n";
+static int helpMain(int argc, const char *argv[]) {
+  errs() << "Usage: llvm-cov {gcov|report|show} [OPTION]...\n\n"
+         << "Shows code coverage information.\n\n"
+         << "Subcommands:\n"
+         << "  gcov:   Work with the gcov format.\n"
+         << "  show:   Annotate source files using instrprof style coverage.\n"
+         << "  report: Summarize instrprof style coverage information.\n";
+  return 0;
+}
+
+/// \brief Top level version information.
+static int versionMain(int argc, const char *argv[]) {
+  cl::PrintVersionMessage();
   return 0;
 }
 
@@ -52,6 +64,7 @@
                             .Case("report", reportMain)
                             .Case("show", showMain)
                             .Cases("-h", "-help", "--help", helpMain)
+                            .Cases("-version", "--version", versionMain)
                             .Default(nullptr);
 
     if (Func) {
@@ -61,18 +74,13 @@
     }
   }
 
-  // Give a warning and fall back to gcov
-  errs().changeColor(raw_ostream::RED);
-  errs() << "warning:";
-  // Assume that argv[1] wasn't a command when it stats with a '-' or is a
-  // filename (i.e. contains a '.')
-  if (argc > 1 && !StringRef(argv[1]).startswith("-") &&
-      StringRef(argv[1]).find(".") == StringRef::npos)
-    errs() << " Unrecognized command '" << argv[1] << "'.";
-  errs() << " Using the gcov compatible mode "
-            "(this behaviour may be dropped in the future).";
-  errs().resetColor();
-  errs() << "\n";
-
-  return gcovMain(argc, argv);
+  if (argc > 1) {
+    if (sys::Process::StandardErrHasColors())
+      errs().changeColor(raw_ostream::RED);
+    errs() << "Unrecognized command: " << argv[1] << ".\n\n";
+    if (sys::Process::StandardErrHasColors())
+      errs().resetColor();
+  }
+  helpMain(argc, argv);
+  return 1;
 }