2013-12-06 06:02:29 +08:00
|
|
|
//===- llvm-cov.cpp - LLVM coverage tool ----------------------------------===//
|
2011-09-29 02:50:00 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-09-29 02:50:00 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// llvm-cov is a command line tools to analyze and report coverage information.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2014-10-31 04:29:48 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2015-06-03 10:48:09 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2018-04-14 02:26:06 +08:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
2016-06-09 08:53:21 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2014-08-23 06:56:03 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2015-03-25 07:34:36 +08:00
|
|
|
#include "llvm/Support/Process.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2014-08-23 06:56:03 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The main entry point for the 'show' subcommand.
|
2014-10-31 04:57:49 +08:00
|
|
|
int showMain(int argc, const char *argv[]);
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The main entry point for the 'report' subcommand.
|
2014-10-31 04:57:49 +08:00
|
|
|
int reportMain(int argc, const char *argv[]);
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The main entry point for the 'export' subcommand.
|
2016-07-27 06:50:58 +08:00
|
|
|
int exportMain(int argc, const char *argv[]);
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The main entry point for the 'convert-for-testing' subcommand.
|
2014-10-31 04:57:49 +08:00
|
|
|
int convertForTestingMain(int argc, const char *argv[]);
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The main entry point for the gcov compatible coverage tool.
|
2014-10-31 04:57:49 +08:00
|
|
|
int gcovMain(int argc, const char *argv[]);
|
2011-09-29 02:50:00 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Top level help.
|
2015-03-10 00:23:46 +08:00
|
|
|
static int helpMain(int argc, const char *argv[]) {
|
2016-07-27 06:50:58 +08:00
|
|
|
errs() << "Usage: llvm-cov {export|gcov|report|show} [OPTION]...\n\n"
|
2015-03-25 07:34:36 +08:00
|
|
|
<< "Shows code coverage information.\n\n"
|
|
|
|
<< "Subcommands:\n"
|
2016-07-27 06:50:58 +08:00
|
|
|
<< " export: Export instrprof file to structured format.\n"
|
2015-03-25 07:34:36 +08:00
|
|
|
<< " gcov: Work with the gcov format.\n"
|
2016-07-27 06:50:58 +08:00
|
|
|
<< " report: Summarize instrprof style coverage information.\n"
|
|
|
|
<< " show: Annotate source files using instrprof style coverage.\n";
|
|
|
|
|
2014-10-31 04:29:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Top level version information.
|
2015-06-03 10:48:09 +08:00
|
|
|
static int versionMain(int argc, const char *argv[]) {
|
|
|
|
cl::PrintVersionMessage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-29 02:03:51 +08:00
|
|
|
int main(int argc, const char **argv) {
|
2018-04-14 02:26:06 +08:00
|
|
|
InitLLVM X(argc, argv);
|
2016-06-09 08:53:21 +08:00
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
// If argv[0] is or ends with 'gcov', always be gcov compatible
|
|
|
|
if (sys::path::stem(argv[0]).endswith_lower("gcov"))
|
2014-10-31 04:57:49 +08:00
|
|
|
return gcovMain(argc, argv);
|
2014-08-23 06:56:03 +08:00
|
|
|
|
|
|
|
// Check if we are invoking a specific tool command.
|
|
|
|
if (argc > 1) {
|
2014-10-31 04:57:49 +08:00
|
|
|
typedef int (*MainFunction)(int, const char *[]);
|
|
|
|
MainFunction Func = StringSwitch<MainFunction>(argv[1])
|
|
|
|
.Case("convert-for-testing", convertForTestingMain)
|
2016-07-27 06:50:58 +08:00
|
|
|
.Case("export", exportMain)
|
2014-10-31 04:57:49 +08:00
|
|
|
.Case("gcov", gcovMain)
|
|
|
|
.Case("report", reportMain)
|
|
|
|
.Case("show", showMain)
|
|
|
|
.Cases("-h", "-help", "--help", helpMain)
|
2015-06-03 10:48:09 +08:00
|
|
|
.Cases("-version", "--version", versionMain)
|
2014-10-31 04:57:49 +08:00
|
|
|
.Default(nullptr);
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2014-10-31 04:57:49 +08:00
|
|
|
if (Func) {
|
2014-09-18 19:52:57 +08:00
|
|
|
std::string Invocation = std::string(argv[0]) + " " + argv[1];
|
2014-08-23 06:56:03 +08:00
|
|
|
argv[1] = Invocation.c_str();
|
2014-10-31 04:57:49 +08:00
|
|
|
return Func(argc - 1, argv + 1);
|
2014-08-23 06:56:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
if (argc > 1)
|
|
|
|
errs() << raw_ostream::RED << "Unrecognized command: " << argv[1] << ".\n\n"
|
|
|
|
<< raw_ostream::RESET;
|
|
|
|
|
2015-03-25 07:34:36 +08:00
|
|
|
helpMain(argc, argv);
|
|
|
|
return 1;
|
2011-09-29 02:50:00 +08:00
|
|
|
}
|