xref: /llvm-project/llvm/tools/llvm-xray/llvm-xray.cpp (revision f7872cdce1102a5c12633dad462a1d9763a578d3)
1a0e3ae4cSDean Michael Berris //===- llvm-xray.cpp: XRay Tool Main Program ------------------------------===//
2a0e3ae4cSDean Michael Berris //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a0e3ae4cSDean Michael Berris //
7a0e3ae4cSDean Michael Berris //===----------------------------------------------------------------------===//
8a0e3ae4cSDean Michael Berris //
9a0e3ae4cSDean Michael Berris // This file implements the main entry point for the suite of XRay tools. All
10a0e3ae4cSDean Michael Berris // additional functionality are implemented as subcommands.
11a0e3ae4cSDean Michael Berris //
12a0e3ae4cSDean Michael Berris //===----------------------------------------------------------------------===//
13a0e3ae4cSDean Michael Berris //
14a0e3ae4cSDean Michael Berris // Basic usage:
15a0e3ae4cSDean Michael Berris //
16a0e3ae4cSDean Michael Berris //   llvm-xray [options] <subcommand> [subcommand-specific options]
17a0e3ae4cSDean Michael Berris //
18a0e3ae4cSDean Michael Berris #include "xray-registry.h"
19a0e3ae4cSDean Michael Berris #include "llvm/Support/CommandLine.h"
20a0e3ae4cSDean Michael Berris #include "llvm/Support/raw_ostream.h"
21a0e3ae4cSDean Michael Berris 
22a0e3ae4cSDean Michael Berris using namespace llvm;
23a0e3ae4cSDean Michael Berris using namespace llvm::xray;
24a0e3ae4cSDean Michael Berris 
main(int argc,char * argv[])25a0e3ae4cSDean Michael Berris int main(int argc, char *argv[]) {
26a0e3ae4cSDean Michael Berris   cl::ParseCommandLineOptions(argc, argv,
27a0e3ae4cSDean Michael Berris                               "XRay Tools\n\n"
28a0e3ae4cSDean Michael Berris                               "  This program consolidates multiple XRay trace "
29a0e3ae4cSDean Michael Berris                               "processing tools for convenient access.\n");
30a0e3ae4cSDean Michael Berris   for (auto *SC : cl::getRegisteredSubcommands()) {
31a0e3ae4cSDean Michael Berris     if (*SC) {
32a0e3ae4cSDean Michael Berris       // If no subcommand was provided, we need to explicitly check if this is
33a0e3ae4cSDean Michael Berris       // the top-level subcommand.
34*f7872cdcSNicolai Hähnle       if (SC == &cl::SubCommand::getTopLevel()) {
35a0e3ae4cSDean Michael Berris         cl::PrintHelpMessage(false, true);
36a0e3ae4cSDean Michael Berris         return 0;
37a0e3ae4cSDean Michael Berris       }
38a0e3ae4cSDean Michael Berris       if (auto C = dispatch(SC)) {
39a0e3ae4cSDean Michael Berris         ExitOnError("llvm-xray: ")(C());
40a0e3ae4cSDean Michael Berris         return 0;
41a0e3ae4cSDean Michael Berris       }
42a0e3ae4cSDean Michael Berris     }
43a0e3ae4cSDean Michael Berris   }
44a0e3ae4cSDean Michael Berris 
45a0e3ae4cSDean Michael Berris   // If all else fails, we still print the usage message.
46a0e3ae4cSDean Michael Berris   cl::PrintHelpMessage(false, true);
47a0e3ae4cSDean Michael Berris   return 0;
48a0e3ae4cSDean Michael Berris }
49