1 //===- llvm-cov.cpp - LLVM coverage tool ----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // llvm-cov is a command line tools to analyze and report coverage information.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/Support/CommandLine.h"
17 #include "llvm/Support/InitLLVM.h"
18 #include "llvm/Support/ManagedStatic.h"
19 #include "llvm/Support/Path.h"
20 #include "llvm/Support/Process.h"
21 #include "llvm/Support/raw_ostream.h"
26 /// The main entry point for the 'show' subcommand.
27 int showMain(int argc
, const char *argv
[]);
29 /// The main entry point for the 'report' subcommand.
30 int reportMain(int argc
, const char *argv
[]);
32 /// The main entry point for the 'export' subcommand.
33 int exportMain(int argc
, const char *argv
[]);
35 /// The main entry point for the 'convert-for-testing' subcommand.
36 int convertForTestingMain(int argc
, const char *argv
[]);
38 /// The main entry point for the gcov compatible coverage tool.
39 int gcovMain(int argc
, const char *argv
[]);
42 static int helpMain(int argc
, const char *argv
[]) {
43 errs() << "Usage: llvm-cov {export|gcov|report|show} [OPTION]...\n\n"
44 << "Shows code coverage information.\n\n"
46 << " export: Export instrprof file to structured format.\n"
47 << " gcov: Work with the gcov format.\n"
48 << " report: Summarize instrprof style coverage information.\n"
49 << " show: Annotate source files using instrprof style coverage.\n";
54 /// Top level version information.
55 static int versionMain(int argc
, const char *argv
[]) {
56 cl::PrintVersionMessage();
60 int main(int argc
, const char **argv
) {
61 InitLLVM
X(argc
, argv
);
63 // If argv[0] is or ends with 'gcov', always be gcov compatible
64 if (sys::path::stem(argv
[0]).endswith_lower("gcov"))
65 return gcovMain(argc
, argv
);
67 // Check if we are invoking a specific tool command.
69 typedef int (*MainFunction
)(int, const char *[]);
70 MainFunction Func
= StringSwitch
<MainFunction
>(argv
[1])
71 .Case("convert-for-testing", convertForTestingMain
)
72 .Case("export", exportMain
)
73 .Case("gcov", gcovMain
)
74 .Case("report", reportMain
)
75 .Case("show", showMain
)
76 .Cases("-h", "-help", "--help", helpMain
)
77 .Cases("-version", "--version", versionMain
)
81 std::string Invocation
= std::string(argv
[0]) + " " + argv
[1];
82 argv
[1] = Invocation
.c_str();
83 return Func(argc
- 1, argv
+ 1);
88 if (sys::Process::StandardErrHasColors())
89 errs().changeColor(raw_ostream::RED
);
90 errs() << "Unrecognized command: " << argv
[1] << ".\n\n";
91 if (sys::Process::StandardErrHasColors())