]> git.proxmox.com Git - rustc.git/blame - src/llvm/tools/llvm-cov/llvm-cov.cpp
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / tools / llvm-cov / llvm-cov.cpp
CommitLineData
1a4d82fc 1//===- llvm-cov.cpp - LLVM coverage tool ----------------------------------===//
223e47cc
LB
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
1a4d82fc 14#include "llvm/ADT/StringRef.h"
85aaf69f 15#include "llvm/ADT/StringSwitch.h"
1a4d82fc 16#include "llvm/Support/Path.h"
85aaf69f 17#include "llvm/Support/raw_ostream.h"
1a4d82fc
JJ
18#include <string>
19
223e47cc
LB
20using namespace llvm;
21
1a4d82fc 22/// \brief The main entry point for the 'show' subcommand.
85aaf69f 23int showMain(int argc, const char *argv[]);
223e47cc 24
1a4d82fc 25/// \brief The main entry point for the 'report' subcommand.
85aaf69f 26int reportMain(int argc, const char *argv[]);
223e47cc 27
1a4d82fc 28/// \brief The main entry point for the 'convert-for-testing' subcommand.
85aaf69f 29int convertForTestingMain(int argc, const char *argv[]);
223e47cc 30
1a4d82fc 31/// \brief The main entry point for the gcov compatible coverage tool.
85aaf69f
SL
32int gcovMain(int argc, const char *argv[]);
33
34/// \brief Top level help.
35int helpMain(int argc, const char *argv[]) {
36 errs() << "OVERVIEW: LLVM code coverage tool\n\n"
37 << "USAGE: llvm-cov {gcov|report|show}\n";
38 return 0;
39}
223e47cc 40
1a4d82fc
JJ
41int main(int argc, const char **argv) {
42 // If argv[0] is or ends with 'gcov', always be gcov compatible
43 if (sys::path::stem(argv[0]).endswith_lower("gcov"))
85aaf69f 44 return gcovMain(argc, argv);
223e47cc 45
1a4d82fc
JJ
46 // Check if we are invoking a specific tool command.
47 if (argc > 1) {
85aaf69f
SL
48 typedef int (*MainFunction)(int, const char *[]);
49 MainFunction Func = StringSwitch<MainFunction>(argv[1])
50 .Case("convert-for-testing", convertForTestingMain)
51 .Case("gcov", gcovMain)
52 .Case("report", reportMain)
53 .Case("show", showMain)
54 .Cases("-h", "-help", "--help", helpMain)
55 .Default(nullptr);
223e47cc 56
85aaf69f 57 if (Func) {
1a4d82fc
JJ
58 std::string Invocation = std::string(argv[0]) + " " + argv[1];
59 argv[1] = Invocation.c_str();
85aaf69f 60 return Func(argc - 1, argv + 1);
223e47cc
LB
61 }
62 }
63
1a4d82fc
JJ
64 // Give a warning and fall back to gcov
65 errs().changeColor(raw_ostream::RED);
66 errs() << "warning:";
67 // Assume that argv[1] wasn't a command when it stats with a '-' or is a
68 // filename (i.e. contains a '.')
69 if (argc > 1 && !StringRef(argv[1]).startswith("-") &&
70 StringRef(argv[1]).find(".") == StringRef::npos)
71 errs() << " Unrecognized command '" << argv[1] << "'.";
72 errs() << " Using the gcov compatible mode "
73 "(this behaviour may be dropped in the future).";
74 errs().resetColor();
75 errs() << "\n";
223e47cc 76
85aaf69f 77 return gcovMain(argc, argv);
223e47cc 78}