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