1c92bfb5aSDean Michael Berris //===- xray-registry.h - Define registry mechanism for commands. ----------===// 2c92bfb5aSDean Michael Berris // 3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6c92bfb5aSDean Michael Berris // 7c92bfb5aSDean Michael Berris //===----------------------------------------------------------------------===// 8c92bfb5aSDean Michael Berris // 9c92bfb5aSDean Michael Berris // Implement a simple subcommand registry. 10c92bfb5aSDean Michael Berris // 11c92bfb5aSDean Michael Berris //===----------------------------------------------------------------------===// 12c92bfb5aSDean Michael Berris #ifndef TOOLS_LLVM_XRAY_XRAY_REGISTRY_H 13c92bfb5aSDean Michael Berris #define TOOLS_LLVM_XRAY_XRAY_REGISTRY_H 14c92bfb5aSDean Michael Berris 15c92bfb5aSDean Michael Berris #include "llvm/Support/CommandLine.h" 16c92bfb5aSDean Michael Berris #include "llvm/Support/Error.h" 17c92bfb5aSDean Michael Berris 18c92bfb5aSDean Michael Berris namespace llvm { 19c92bfb5aSDean Michael Berris namespace xray { 20c92bfb5aSDean Michael Berris 21c92bfb5aSDean Michael Berris // Use |CommandRegistration| as a global initialiser that registers a function 22c92bfb5aSDean Michael Berris // and associates it with |SC|. This requires that a command has not been 23c92bfb5aSDean Michael Berris // registered to a given |SC|. 24c92bfb5aSDean Michael Berris // 25c92bfb5aSDean Michael Berris // Usage: 26c92bfb5aSDean Michael Berris // 27c92bfb5aSDean Michael Berris // // At namespace scope. 28c92bfb5aSDean Michael Berris // static CommandRegistration Unused(&MySubCommand, [] { ... }); 29c92bfb5aSDean Michael Berris // 30c92bfb5aSDean Michael Berris struct CommandRegistration { 31c92bfb5aSDean Michael Berris CommandRegistration(cl::SubCommand *SC, std::function<Error()> Command); 32c92bfb5aSDean Michael Berris }; 33c92bfb5aSDean Michael Berris 34c92bfb5aSDean Michael Berris // Requires that |SC| is not null and has an associated function to it. 35c92bfb5aSDean Michael Berris std::function<Error()> dispatch(cl::SubCommand *SC); 36c92bfb5aSDean Michael Berris 37c92bfb5aSDean Michael Berris } // namespace xray 38c92bfb5aSDean Michael Berris } // namespace llvm 39c92bfb5aSDean Michael Berris 40c92bfb5aSDean Michael Berris #endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H 41