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