Mercurial > hg > CbC > CbC_llvm
comparison 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 |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
11 // | 11 // |
12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
13 | 13 |
14 #include "llvm/ADT/StringRef.h" | 14 #include "llvm/ADT/StringRef.h" |
15 #include "llvm/ADT/StringSwitch.h" | 15 #include "llvm/ADT/StringSwitch.h" |
16 #include "llvm/Support/CommandLine.h" | |
16 #include "llvm/Support/Path.h" | 17 #include "llvm/Support/Path.h" |
18 #include "llvm/Support/Process.h" | |
17 #include "llvm/Support/raw_ostream.h" | 19 #include "llvm/Support/raw_ostream.h" |
18 #include <string> | 20 #include <string> |
19 | 21 |
20 using namespace llvm; | 22 using namespace llvm; |
21 | 23 |
30 | 32 |
31 /// \brief The main entry point for the gcov compatible coverage tool. | 33 /// \brief The main entry point for the gcov compatible coverage tool. |
32 int gcovMain(int argc, const char *argv[]); | 34 int gcovMain(int argc, const char *argv[]); |
33 | 35 |
34 /// \brief Top level help. | 36 /// \brief Top level help. |
35 int helpMain(int argc, const char *argv[]) { | 37 static int helpMain(int argc, const char *argv[]) { |
36 errs() << "OVERVIEW: LLVM code coverage tool\n\n" | 38 errs() << "Usage: llvm-cov {gcov|report|show} [OPTION]...\n\n" |
37 << "USAGE: llvm-cov {gcov|report|show}\n"; | 39 << "Shows code coverage information.\n\n" |
40 << "Subcommands:\n" | |
41 << " gcov: Work with the gcov format.\n" | |
42 << " show: Annotate source files using instrprof style coverage.\n" | |
43 << " report: Summarize instrprof style coverage information.\n"; | |
44 return 0; | |
45 } | |
46 | |
47 /// \brief Top level version information. | |
48 static int versionMain(int argc, const char *argv[]) { | |
49 cl::PrintVersionMessage(); | |
38 return 0; | 50 return 0; |
39 } | 51 } |
40 | 52 |
41 int main(int argc, const char **argv) { | 53 int main(int argc, const char **argv) { |
42 // If argv[0] is or ends with 'gcov', always be gcov compatible | 54 // If argv[0] is or ends with 'gcov', always be gcov compatible |
50 .Case("convert-for-testing", convertForTestingMain) | 62 .Case("convert-for-testing", convertForTestingMain) |
51 .Case("gcov", gcovMain) | 63 .Case("gcov", gcovMain) |
52 .Case("report", reportMain) | 64 .Case("report", reportMain) |
53 .Case("show", showMain) | 65 .Case("show", showMain) |
54 .Cases("-h", "-help", "--help", helpMain) | 66 .Cases("-h", "-help", "--help", helpMain) |
67 .Cases("-version", "--version", versionMain) | |
55 .Default(nullptr); | 68 .Default(nullptr); |
56 | 69 |
57 if (Func) { | 70 if (Func) { |
58 std::string Invocation = std::string(argv[0]) + " " + argv[1]; | 71 std::string Invocation = std::string(argv[0]) + " " + argv[1]; |
59 argv[1] = Invocation.c_str(); | 72 argv[1] = Invocation.c_str(); |
60 return Func(argc - 1, argv + 1); | 73 return Func(argc - 1, argv + 1); |
61 } | 74 } |
62 } | 75 } |
63 | 76 |
64 // Give a warning and fall back to gcov | 77 if (argc > 1) { |
65 errs().changeColor(raw_ostream::RED); | 78 if (sys::Process::StandardErrHasColors()) |
66 errs() << "warning:"; | 79 errs().changeColor(raw_ostream::RED); |
67 // Assume that argv[1] wasn't a command when it stats with a '-' or is a | 80 errs() << "Unrecognized command: " << argv[1] << ".\n\n"; |
68 // filename (i.e. contains a '.') | 81 if (sys::Process::StandardErrHasColors()) |
69 if (argc > 1 && !StringRef(argv[1]).startswith("-") && | 82 errs().resetColor(); |
70 StringRef(argv[1]).find(".") == StringRef::npos) | 83 } |
71 errs() << " Unrecognized command '" << argv[1] << "'."; | 84 helpMain(argc, argv); |
72 errs() << " Using the gcov compatible mode " | 85 return 1; |
73 "(this behaviour may be dropped in the future)."; | |
74 errs().resetColor(); | |
75 errs() << "\n"; | |
76 | |
77 return gcovMain(argc, argv); | |
78 } | 86 } |