llvm-cov.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //===- llvm-cov.cpp - LLVM coverage tool ----------------------------------===//
  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. #include "llvm/ADT/StringRef.h"
  14. #include "llvm/ADT/StringSwitch.h"
  15. #include "llvm/Support/CommandLine.h"
  16. #include "llvm/Support/Path.h"
  17. #include "llvm/Support/Process.h"
  18. #include "llvm/Support/raw_ostream.h"
  19. #include <string>
  20. using namespace llvm;
  21. /// \brief The main entry point for the 'show' subcommand.
  22. int showMain(int argc, const char *argv[]);
  23. /// \brief The main entry point for the 'report' subcommand.
  24. int reportMain(int argc, const char *argv[]);
  25. /// \brief The main entry point for the 'convert-for-testing' subcommand.
  26. int convertForTestingMain(int argc, const char *argv[]);
  27. /// \brief The main entry point for the gcov compatible coverage tool.
  28. int gcovMain(int argc, const char *argv[]);
  29. /// \brief Top level help.
  30. static int helpMain(int argc, const char *argv[]) {
  31. errs() << "Usage: llvm-cov {gcov|report|show} [OPTION]...\n\n"
  32. << "Shows code coverage information.\n\n"
  33. << "Subcommands:\n"
  34. << " gcov: Work with the gcov format.\n"
  35. << " show: Annotate source files using instrprof style coverage.\n"
  36. << " report: Summarize instrprof style coverage information.\n";
  37. return 0;
  38. }
  39. /// \brief Top level version information.
  40. static int versionMain(int argc, const char *argv[]) {
  41. cl::PrintVersionMessage();
  42. return 0;
  43. }
  44. int __cdecl main(int argc, const char **argv) { // HLSL Change - __cdecl
  45. // If argv[0] is or ends with 'gcov', always be gcov compatible
  46. if (sys::path::stem(argv[0]).endswith_lower("gcov"))
  47. return gcovMain(argc, argv);
  48. // Check if we are invoking a specific tool command.
  49. if (argc > 1) {
  50. typedef int (*MainFunction)(int, const char *[]);
  51. MainFunction Func = StringSwitch<MainFunction>(argv[1])
  52. .Case("convert-for-testing", convertForTestingMain)
  53. .Case("gcov", gcovMain)
  54. .Case("report", reportMain)
  55. .Case("show", showMain)
  56. .Cases("-h", "-help", "--help", helpMain)
  57. .Cases("-version", "--version", versionMain)
  58. .Default(nullptr);
  59. if (Func) {
  60. std::string Invocation = std::string(argv[0]) + " " + argv[1];
  61. argv[1] = Invocation.c_str();
  62. return Func(argc - 1, argv + 1);
  63. }
  64. }
  65. if (argc > 1) {
  66. if (sys::Process::StandardErrHasColors())
  67. errs().changeColor(raw_ostream::RED);
  68. errs() << "Unrecognized command: " << argv[1] << ".\n\n";
  69. if (sys::Process::StandardErrHasColors())
  70. errs().resetColor();
  71. }
  72. helpMain(argc, argv);
  73. return 1;
  74. }