llvm-xray.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===- llvm-xray.cpp: XRay Tool Main Program ------------------------------===//
  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. // This file implements the main entry point for the suite of XRay tools. All
  10. // additional functionality are implemented as subcommands.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Basic usage:
  15. //
  16. // llvm-xray [options] <subcommand> [subcommand-specific options]
  17. //
  18. #include "xray-registry.h"
  19. #include "llvm/Support/CommandLine.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. using namespace llvm;
  22. using namespace llvm::xray;
  23. int main(int argc, char *argv[]) {
  24. cl::ParseCommandLineOptions(argc, argv,
  25. "XRay Tools\n\n"
  26. " This program consolidates multiple XRay trace "
  27. "processing tools for convenient access.\n");
  28. for (auto *SC : cl::getRegisteredSubcommands()) {
  29. if (*SC) {
  30. // If no subcommand was provided, we need to explicitly check if this is
  31. // the top-level subcommand.
  32. if (SC == &*cl::TopLevelSubCommand) {
  33. cl::PrintHelpMessage(false, true);
  34. return 0;
  35. }
  36. if (auto C = dispatch(SC)) {
  37. ExitOnError("llvm-xray: ")(C());
  38. return 0;
  39. }
  40. }
  41. }
  42. // If all else fails, we still print the usage message.
  43. cl::PrintHelpMessage(false, true);
  44. return 0;
  45. }