]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-xray/xray-registry.h
Merge ^/head r320398 through r320572.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-xray / xray-registry.h
1 //===- xray-registry.h - Define registry mechanism for commands. ----------===//
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 // Implement a simple subcommand registry.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef TOOLS_LLVM_XRAY_XRAY_REGISTRY_H
14 #define TOOLS_LLVM_XRAY_XRAY_REGISTRY_H
15
16 #include "llvm/Support/CommandLine.h"
17 #include "llvm/Support/Error.h"
18
19 namespace llvm {
20 namespace xray {
21
22 // Use |CommandRegistration| as a global initialiser that registers a function
23 // and associates it with |SC|. This requires that a command has not been
24 // registered to a given |SC|.
25 //
26 // Usage:
27 //
28 //   // At namespace scope.
29 //   static CommandRegistration Unused(&MySubCommand, [] { ... });
30 //
31 struct CommandRegistration {
32   CommandRegistration(cl::SubCommand *SC, std::function<Error()> Command);
33 };
34
35 // Requires that |SC| is not null and has an associated function to it.
36 std::function<Error()> dispatch(cl::SubCommand *SC);
37
38 } // namespace xray
39 } // namespace llvm
40
41 #endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H