Coverage Report

Created: 2018-08-19 14:04

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