Yuchen Wu | c3e6424 | 2013-12-05 22:02:29 +0000 | [diff] [blame] | 1 | //===- llvm-cov.cpp - LLVM coverage tool ----------------------------------===// |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 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 | // |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 10 | // llvm-cov is a command line tools to analyze and report coverage information. |
| 11 | // |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/StringRef.h" |
| 15 | #include "llvm/Support/raw_ostream.h" |
| 16 | #include "llvm/Support/Path.h" |
| 17 | #include <string> |
| 18 | |
| 19 | using namespace llvm; |
| 20 | |
| 21 | /// \brief The main entry point for the 'show' subcommand. |
| 22 | int show_main(int argc, const char **argv); |
| 23 | |
| 24 | /// \brief The main entry point for the 'report' subcommand. |
| 25 | int report_main(int argc, const char **argv); |
| 26 | |
| 27 | /// \brief The main entry point for the 'convert-for-testing' subcommand. |
| 28 | int convert_for_testing_main(int argc, const char **argv); |
| 29 | |
| 30 | /// \brief The main entry point for the gcov compatible coverage tool. |
Alex Lorenz | 2b5d03a | 2014-07-28 18:03:51 +0000 | [diff] [blame] | 31 | int gcov_main(int argc, const char **argv); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 32 | |
Alex Lorenz | 2b5d03a | 2014-07-28 18:03:51 +0000 | [diff] [blame] | 33 | int main(int argc, const char **argv) { |
Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [diff] [blame] | 34 | // If argv[0] is or ends with 'gcov', always be gcov compatible |
| 35 | if (sys::path::stem(argv[0]).endswith_lower("gcov")) |
| 36 | return gcov_main(argc, argv); |
| 37 | |
| 38 | // Check if we are invoking a specific tool command. |
| 39 | if (argc > 1) { |
| 40 | int (*func)(int, const char **) = nullptr; |
| 41 | |
| 42 | StringRef command = argv[1]; |
| 43 | if (command.equals_lower("show")) |
| 44 | func = show_main; |
| 45 | else if (command.equals_lower("report")) |
| 46 | func = report_main; |
| 47 | else if (command.equals_lower("convert-for-testing")) |
| 48 | func = convert_for_testing_main; |
| 49 | else if (command.equals_lower("gcov")) |
| 50 | func = gcov_main; |
| 51 | |
| 52 | if (func) { |
Patrik Hagglund | 07ccb10 | 2014-09-18 11:52:57 +0000 | [diff] [blame] | 53 | std::string Invocation = std::string(argv[0]) + " " + argv[1]; |
Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [diff] [blame] | 54 | argv[1] = Invocation.c_str(); |
| 55 | return func(argc - 1, argv + 1); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Give a warning and fall back to gcov |
| 60 | errs().changeColor(raw_ostream::RED); |
| 61 | errs() << "warning:"; |
| 62 | // Assume that argv[1] wasn't a command when it stats with a '-' or is a |
| 63 | // filename (i.e. contains a '.') |
| 64 | if (argc > 1 && !StringRef(argv[1]).startswith("-") && |
| 65 | StringRef(argv[1]).find(".") == StringRef::npos) |
| 66 | errs() << " Unrecognized command '" << argv[1] << "'."; |
| 67 | errs() << " Using the gcov compatible mode " |
| 68 | "(this behaviour may be dropped in the future)."; |
| 69 | errs().resetColor(); |
| 70 | errs() << "\n"; |
| 71 | |
Alex Lorenz | 2b5d03a | 2014-07-28 18:03:51 +0000 | [diff] [blame] | 72 | return gcov_main(argc, argv); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 73 | } |