blob: 6eab016273f52073b754d96bdbeff2d4c3ee3e7a [file] [log] [blame]
Dean Michael Berris5a355482016-10-26 04:14:34 +00001//===- 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
19namespace llvm {
20namespace 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//
31struct 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.
36std::function<Error()> dispatch(cl::SubCommand *SC);
37
38} // namespace xray
39} // namespace llvm
40
41#endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H