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