blob: e74628f5025f669fbf15d8ca73a1f3bc2d40a7f8 [file] [log] [blame]
Dean Michael Berrisf4f861b2018-05-02 00:43:17 +00001//===- llvm-xray.cpp: XRay Tool Main Program ------------------------------===//
Dean Michael Berris5a355482016-10-26 04:14:34 +00002//
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// This file implements the main entry point for the suite of XRay tools. All
11// additional functionality are implemented as subcommands.
12//
13//===----------------------------------------------------------------------===//
14//
15// Basic usage:
16//
17// llvm-xray [options] <subcommand> [subcommand-specific options]
18//
19#include "xray-registry.h"
20#include "llvm/Support/CommandLine.h"
Dean Michael Berris5a355482016-10-26 04:14:34 +000021#include "llvm/Support/raw_ostream.h"
Dean Michael Berris5a355482016-10-26 04:14:34 +000022
23using namespace llvm;
24using namespace llvm::xray;
25
26int main(int argc, char *argv[]) {
27 cl::ParseCommandLineOptions(argc, argv,
28 "XRay Tools\n\n"
29 " This program consolidates multiple XRay trace "
30 "processing tools for convenient access.\n");
31 for (auto *SC : cl::getRegisteredSubcommands()) {
Dean Michael Berris89854502017-03-29 04:55:45 +000032 if (*SC) {
33 // If no subcommand was provided, we need to explicitly check if this is
34 // the top-level subcommand.
35 if (SC == &*cl::TopLevelSubCommand) {
36 cl::PrintHelpMessage(false, true);
37 return 0;
38 }
Dean Michael Berris5a355482016-10-26 04:14:34 +000039 if (auto C = dispatch(SC)) {
40 ExitOnError("llvm-xray: ")(C());
41 return 0;
42 }
Dean Michael Berris89854502017-03-29 04:55:45 +000043 }
Dean Michael Berris5a355482016-10-26 04:14:34 +000044 }
45
Dean Michael Berris89854502017-03-29 04:55:45 +000046 // If all else fails, we still print the usage message.
Dean Michael Berris5a355482016-10-26 04:14:34 +000047 cl::PrintHelpMessage(false, true);
Rafael Espindola14fde142017-09-07 23:30:48 +000048 return 0;
Dean Michael Berris5a355482016-10-26 04:14:34 +000049}