Coverage Report

Created: 2017-09-21 03:39

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