Path: blob/main/contrib/llvm-project/llvm/tools/llvm-cov/llvm-cov.cpp
35231 views
//===- llvm-cov.cpp - LLVM coverage tool ----------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// llvm-cov is a command line tools to analyze and report coverage information.9//10//===----------------------------------------------------------------------===//1112#include "llvm/ADT/StringRef.h"13#include "llvm/ADT/StringSwitch.h"14#include "llvm/Support/CommandLine.h"15#include "llvm/Support/InitLLVM.h"16#include "llvm/Support/Path.h"17#include "llvm/Support/Process.h"18#include "llvm/Support/raw_ostream.h"19#include <string>2021using namespace llvm;2223/// The main entry point for the 'show' subcommand.24int showMain(int argc, const char *argv[]);2526/// The main entry point for the 'report' subcommand.27int reportMain(int argc, const char *argv[]);2829/// The main entry point for the 'export' subcommand.30int exportMain(int argc, const char *argv[]);3132/// The main entry point for the 'convert-for-testing' subcommand.33int convertForTestingMain(int argc, const char *argv[]);3435/// The main entry point for the gcov compatible coverage tool.36int gcovMain(int argc, const char *argv[]);3738/// Top level help.39static int helpMain(int argc, const char *argv[]) {40errs() << "Usage: llvm-cov {export|gcov|report|show} [OPTION]...\n\n"41<< "Shows code coverage information.\n\n"42<< "Subcommands:\n"43<< " export: Export instrprof file to structured format.\n"44<< " gcov: Work with the gcov format.\n"45<< " report: Summarize instrprof style coverage information.\n"46<< " show: Annotate source files using instrprof style coverage.\n";4748return 0;49}5051/// Top level version information.52static int versionMain(int argc, const char *argv[]) {53cl::PrintVersionMessage();54return 0;55}5657int main(int argc, const char **argv) {58InitLLVM X(argc, argv);5960// If argv[0] is or ends with 'gcov', always be gcov compatible61if (sys::path::stem(argv[0]).ends_with_insensitive("gcov"))62return gcovMain(argc, argv);6364// Check if we are invoking a specific tool command.65if (argc > 1) {66typedef int (*MainFunction)(int, const char *[]);67MainFunction Func = StringSwitch<MainFunction>(argv[1])68.Case("convert-for-testing", convertForTestingMain)69.Case("export", exportMain)70.Case("gcov", gcovMain)71.Case("report", reportMain)72.Case("show", showMain)73.Cases("-h", "-help", "--help", helpMain)74.Cases("-version", "--version", versionMain)75.Default(nullptr);7677if (Func) {78std::string Invocation = std::string(argv[0]) + " " + argv[1];79argv[1] = Invocation.c_str();80return Func(argc - 1, argv + 1);81}82}8384if (argc > 1) {85if (sys::Process::StandardErrHasColors())86errs().changeColor(raw_ostream::RED);87errs() << "Unrecognized command: " << argv[1] << ".\n\n";88if (sys::Process::StandardErrHasColors())89errs().resetColor();90}91helpMain(argc, argv);92return 1;93}949596