blob: 98303e7be15c0bc286da9f3b85f5c6d68145776b [file] [log] [blame]
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +00001//===- llvm-xray.cc - XRay Tool Main Program ------------------------------===//
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// 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"
21#include "llvm/Support/FileSystem.h"
22#include "llvm/Support/raw_ostream.h"
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000023
24using namespace llvm;
25using namespace llvm::xray;
26
27int main(int argc, char *argv[]) {
28 cl::ParseCommandLineOptions(argc, argv,
29 "XRay Tools\n\n"
30 " This program consolidates multiple XRay trace "
31 "processing tools for convenient access.\n");
32 for (auto *SC : cl::getRegisteredSubcommands()) {
Dean Michael Berrisf4543012017-03-29 04:55:45 +000033 if (*SC) {
34 // If no subcommand was provided, we need to explicitly check if this is
35 // the top-level subcommand.
36 if (SC == &*cl::TopLevelSubCommand) {
37 cl::PrintHelpMessage(false, true);
38 return 0;
39 }
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000040 if (auto C = dispatch(SC)) {
41 ExitOnError("llvm-xray: ")(C());
42 return 0;
43 }
Dean Michael Berrisf4543012017-03-29 04:55:45 +000044 }
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000045 }
46
Dean Michael Berrisf4543012017-03-29 04:55:45 +000047 // If all else fails, we still print the usage message.
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000048 cl::PrintHelpMessage(false, true);
49}