33
|
1 //===- llvm-cov.cpp - LLVM coverage tool ----------------------------------===//
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 // llvm-cov is a command line tools to analyze and report coverage information.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13
|
77
|
14 #include "llvm/ADT/StringRef.h"
|
83
|
15 #include "llvm/ADT/StringSwitch.h"
|
95
|
16 #include "llvm/Support/CommandLine.h"
|
83
|
17 #include "llvm/Support/Path.h"
|
95
|
18 #include "llvm/Support/Process.h"
|
77
|
19 #include "llvm/Support/raw_ostream.h"
|
|
20 #include <string>
|
|
21
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 using namespace llvm;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23
|
77
|
24 /// \brief The main entry point for the 'show' subcommand.
|
83
|
25 int showMain(int argc, const char *argv[]);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26
|
77
|
27 /// \brief The main entry point for the 'report' subcommand.
|
83
|
28 int reportMain(int argc, const char *argv[]);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29
|
77
|
30 /// \brief The main entry point for the 'convert-for-testing' subcommand.
|
83
|
31 int convertForTestingMain(int argc, const char *argv[]);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32
|
77
|
33 /// \brief The main entry point for the gcov compatible coverage tool.
|
83
|
34 int gcovMain(int argc, const char *argv[]);
|
|
35
|
|
36 /// \brief Top level help.
|
95
|
37 static int helpMain(int argc, const char *argv[]) {
|
|
38 errs() << "Usage: llvm-cov {gcov|report|show} [OPTION]...\n\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();
|
83
|
50 return 0;
|
|
51 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52
|
77
|
53 int main(int argc, const char **argv) {
|
|
54 // If argv[0] is or ends with 'gcov', always be gcov compatible
|
|
55 if (sys::path::stem(argv[0]).endswith_lower("gcov"))
|
83
|
56 return gcovMain(argc, argv);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57
|
77
|
58 // Check if we are invoking a specific tool command.
|
|
59 if (argc > 1) {
|
83
|
60 typedef int (*MainFunction)(int, const char *[]);
|
|
61 MainFunction Func = StringSwitch<MainFunction>(argv[1])
|
|
62 .Case("convert-for-testing", convertForTestingMain)
|
|
63 .Case("gcov", gcovMain)
|
|
64 .Case("report", reportMain)
|
|
65 .Case("show", showMain)
|
|
66 .Cases("-h", "-help", "--help", helpMain)
|
95
|
67 .Cases("-version", "--version", versionMain)
|
83
|
68 .Default(nullptr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69
|
83
|
70 if (Func) {
|
|
71 std::string Invocation = std::string(argv[0]) + " " + argv[1];
|
77
|
72 argv[1] = Invocation.c_str();
|
83
|
73 return Func(argc - 1, argv + 1);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76
|
95
|
77 if (argc > 1) {
|
|
78 if (sys::Process::StandardErrHasColors())
|
|
79 errs().changeColor(raw_ostream::RED);
|
|
80 errs() << "Unrecognized command: " << argv[1] << ".\n\n";
|
|
81 if (sys::Process::StandardErrHasColors())
|
|
82 errs().resetColor();
|
|
83 }
|
|
84 helpMain(argc, argv);
|
|
85 return 1;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 }
|