1 //===- xray-registry.h - Define registry mechanism for commands. ----------===//
3 // 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
7 //===----------------------------------------------------------------------===//
9 // Implement a simple subcommand registry.
11 //===----------------------------------------------------------------------===//
12 #ifndef TOOLS_LLVM_XRAY_XRAY_REGISTRY_H
13 #define TOOLS_LLVM_XRAY_XRAY_REGISTRY_H
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/Error.h"
21 // Use |CommandRegistration| as a global initialiser that registers a function
22 // and associates it with |SC|. This requires that a command has not been
23 // registered to a given |SC|.
27 // // At namespace scope.
28 // static CommandRegistration Unused(&MySubCommand, [] { ... });
30 struct CommandRegistration
{
31 CommandRegistration(cl::SubCommand
*SC
, std::function
<Error()> Command
);
34 // Requires that |SC| is not null and has an associated function to it.
35 std::function
<Error()> dispatch(cl::SubCommand
*SC
);
40 #endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H