Coverage Report

Created: 2019-05-19 14:56

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/llvm-cov/llvm-cov.cpp
Line
Count
Source (jump to first uncovered line)
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.
10
//
11
//===----------------------------------------------------------------------===//
12
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/ManagedStatic.h"
18
#include "llvm/Support/Path.h"
19
#include "llvm/Support/Process.h"
20
#include "llvm/Support/raw_ostream.h"
21
#include <string>
22
23
using namespace llvm;
24
25
/// The main entry point for the 'show' subcommand.
26
int showMain(int argc, const char *argv[]);
27
28
/// The main entry point for the 'report' subcommand.
29
int reportMain(int argc, const char *argv[]);
30
31
/// The main entry point for the 'export' subcommand.
32
int exportMain(int argc, const char *argv[]);
33
34
/// The main entry point for the 'convert-for-testing' subcommand.
35
int convertForTestingMain(int argc, const char *argv[]);
36
37
/// The main entry point for the gcov compatible coverage tool.
38
int gcovMain(int argc, const char *argv[]);
39
40
/// Top level help.
41
0
static int helpMain(int argc, const char *argv[]) {
42
0
  errs() << "Usage: llvm-cov {export|gcov|report|show} [OPTION]...\n\n"
43
0
         << "Shows code coverage information.\n\n"
44
0
         << "Subcommands:\n"
45
0
         << "  export: Export instrprof file to structured format.\n"
46
0
         << "  gcov:   Work with the gcov format.\n"
47
0
         << "  report: Summarize instrprof style coverage information.\n"
48
0
         << "  show:   Annotate source files using instrprof style coverage.\n";
49
0
50
0
  return 0;
51
0
}
52
53
/// Top level version information.
54
0
static int versionMain(int argc, const char *argv[]) {
55
0
  cl::PrintVersionMessage();
56
0
  return 0;
57
0
}
58
59
149
int main(int argc, const char **argv) {
60
149
  InitLLVM X(argc, argv);
61
149
62
149
  // If argv[0] is or ends with 'gcov', always be gcov compatible
63
149
  if (sys::path::stem(argv[0]).endswith_lower("gcov"))
64
0
    return gcovMain(argc, argv);
65
149
66
149
  // Check if we are invoking a specific tool command.
67
149
  if (argc > 1) {
68
149
    typedef int (*MainFunction)(int, const char *[]);
69
149
    MainFunction Func = StringSwitch<MainFunction>(argv[1])
70
149
                            .Case("convert-for-testing", convertForTestingMain)
71
149
                            .Case("export", exportMain)
72
149
                            .Case("gcov", gcovMain)
73
149
                            .Case("report", reportMain)
74
149
                            .Case("show", showMain)
75
149
                            .Cases("-h", "-help", "--help", helpMain)
76
149
                            .Cases("-version", "--version", versionMain)
77
149
                            .Default(nullptr);
78
149
79
149
    if (Func) {
80
149
      std::string Invocation = std::string(argv[0]) + " " + argv[1];
81
149
      argv[1] = Invocation.c_str();
82
149
      return Func(argc - 1, argv + 1);
83
149
    }
84
0
  }
85
0
86
0
  if (argc > 1) {
87
0
    if (sys::Process::StandardErrHasColors())
88
0
      errs().changeColor(raw_ostream::RED);
89
0
    errs() << "Unrecognized command: " << argv[1] << ".\n\n";
90
0
    if (sys::Process::StandardErrHasColors())
91
0
      errs().resetColor();
92
0
  }
93
0
  helpMain(argc, argv);
94
0
  return 1;
95
0
}