Dean Michael Berris | f4f861b | 2018-05-02 00:43:17 +0000 | [diff] [blame] | 1 | //===- llvm-xray.cpp: XRay Tool Main Program ------------------------------===// |
Dean Michael Berris | 5a35548 | 2016-10-26 04:14:34 +0000 | [diff] [blame] | 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" |
Dean Michael Berris | 5a35548 | 2016-10-26 04:14:34 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Dean Michael Berris | 5a35548 | 2016-10-26 04:14:34 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace llvm; |
| 24 | using namespace llvm::xray; |
| 25 | |
| 26 | int 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 Berris | 8985450 | 2017-03-29 04:55:45 +0000 | [diff] [blame] | 32 | 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 Berris | 5a35548 | 2016-10-26 04:14:34 +0000 | [diff] [blame] | 39 | if (auto C = dispatch(SC)) { |
| 40 | ExitOnError("llvm-xray: ")(C()); |
| 41 | return 0; |
| 42 | } |
Dean Michael Berris | 8985450 | 2017-03-29 04:55:45 +0000 | [diff] [blame] | 43 | } |
Dean Michael Berris | 5a35548 | 2016-10-26 04:14:34 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Dean Michael Berris | 8985450 | 2017-03-29 04:55:45 +0000 | [diff] [blame] | 46 | // If all else fails, we still print the usage message. |
Dean Michael Berris | 5a35548 | 2016-10-26 04:14:34 +0000 | [diff] [blame] | 47 | cl::PrintHelpMessage(false, true); |
Rafael Espindola | 14fde14 | 2017-09-07 23:30:48 +0000 | [diff] [blame] | 48 | return 0; |
Dean Michael Berris | 5a35548 | 2016-10-26 04:14:34 +0000 | [diff] [blame] | 49 | } |