blob: 9ee653e97b2ddfa58e2673333c92af6a823abf36 [file] [log] [blame]
Dean Michael Berrisa0e3ae42018-05-02 00:43:17 +00001//===- llvm-xray.cpp: XRay Tool Main Program ------------------------------===//
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +00006//
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"
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000020#include "llvm/Support/raw_ostream.h"
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000021
22using namespace llvm;
23using namespace llvm::xray;
24
25int main(int argc, char *argv[]) {
26 cl::ParseCommandLineOptions(argc, argv,
27 "XRay Tools\n\n"
28 " This program consolidates multiple XRay trace "
29 "processing tools for convenient access.\n");
30 for (auto *SC : cl::getRegisteredSubcommands()) {
Dean Michael Berrisf4543012017-03-29 04:55:45 +000031 if (*SC) {
32 // If no subcommand was provided, we need to explicitly check if this is
33 // the top-level subcommand.
34 if (SC == &*cl::TopLevelSubCommand) {
35 cl::PrintHelpMessage(false, true);
36 return 0;
37 }
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000038 if (auto C = dispatch(SC)) {
39 ExitOnError("llvm-xray: ")(C());
40 return 0;
41 }
Dean Michael Berrisf4543012017-03-29 04:55:45 +000042 }
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000043 }
44
Dean Michael Berrisf4543012017-03-29 04:55:45 +000045 // If all else fails, we still print the usage message.
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000046 cl::PrintHelpMessage(false, true);
Rafael Espindola39c150e2017-09-07 23:30:48 +000047 return 0;
Dean Michael Berrisc92bfb52016-10-26 04:14:34 +000048}