[NFC][Py Reformat] Reformat python files in llvm
[llvm-project.git] / llvm / tools / llvm-cov / llvm-cov.cpp
blob5ada55789b24677024963cb603edd087adf8da9e
1 //===- llvm-cov.cpp - LLVM coverage tool ----------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // llvm-cov is a command line tools to analyze and report coverage information.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/InitLLVM.h"
17 #include "llvm/Support/Path.h"
18 #include "llvm/Support/Process.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include <string>
22 using namespace llvm;
24 /// The main entry point for the 'show' subcommand.
25 int showMain(int argc, const char *argv[]);
27 /// The main entry point for the 'report' subcommand.
28 int reportMain(int argc, const char *argv[]);
30 /// The main entry point for the 'export' subcommand.
31 int exportMain(int argc, const char *argv[]);
33 /// The main entry point for the 'convert-for-testing' subcommand.
34 int convertForTestingMain(int argc, const char *argv[]);
36 /// The main entry point for the gcov compatible coverage tool.
37 int gcovMain(int argc, const char *argv[]);
39 /// Top level help.
40 static int helpMain(int argc, const char *argv[]) {
41 errs() << "Usage: llvm-cov {export|gcov|report|show} [OPTION]...\n\n"
42 << "Shows code coverage information.\n\n"
43 << "Subcommands:\n"
44 << " export: Export instrprof file to structured format.\n"
45 << " gcov: Work with the gcov format.\n"
46 << " report: Summarize instrprof style coverage information.\n"
47 << " show: Annotate source files using instrprof style coverage.\n";
49 return 0;
52 /// Top level version information.
53 static int versionMain(int argc, const char *argv[]) {
54 cl::PrintVersionMessage();
55 return 0;
58 int main(int argc, const char **argv) {
59 InitLLVM X(argc, argv);
61 // If argv[0] is or ends with 'gcov', always be gcov compatible
62 if (sys::path::stem(argv[0]).ends_with_insensitive("gcov"))
63 return gcovMain(argc, argv);
65 // Check if we are invoking a specific tool command.
66 if (argc > 1) {
67 typedef int (*MainFunction)(int, const char *[]);
68 MainFunction Func = StringSwitch<MainFunction>(argv[1])
69 .Case("convert-for-testing", convertForTestingMain)
70 .Case("export", exportMain)
71 .Case("gcov", gcovMain)
72 .Case("report", reportMain)
73 .Case("show", showMain)
74 .Cases("-h", "-help", "--help", helpMain)
75 .Cases("-version", "--version", versionMain)
76 .Default(nullptr);
78 if (Func) {
79 std::string Invocation = std::string(argv[0]) + " " + argv[1];
80 argv[1] = Invocation.c_str();
81 return Func(argc - 1, argv + 1);
85 if (argc > 1) {
86 if (sys::Process::StandardErrHasColors())
87 errs().changeColor(raw_ostream::RED);
88 errs() << "Unrecognized command: " << argv[1] << ".\n\n";
89 if (sys::Process::StandardErrHasColors())
90 errs().resetColor();
92 helpMain(argc, argv);
93 return 1;