39 lines · c
1//===- xray-registry.h - Define registry mechanism for commands. ----------===//2//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-exception6//7//===----------------------------------------------------------------------===//8//9// Implement a simple subcommand registry.10//11//===----------------------------------------------------------------------===//12#ifndef TOOLS_LLVM_XRAY_XRAY_REGISTRY_H13#define TOOLS_LLVM_XRAY_XRAY_REGISTRY_H14 15#include "llvm/Support/CommandLine.h"16#include "llvm/Support/Error.h"17 18namespace llvm::xray {19 20// Use |CommandRegistration| as a global initialiser that registers a function21// and associates it with |SC|. This requires that a command has not been22// registered to a given |SC|.23//24// Usage:25//26// // At namespace scope.27// static CommandRegistration Unused(&MySubCommand, [] { ... });28//29struct CommandRegistration {30 CommandRegistration(cl::SubCommand *SC, std::function<Error()> Command);31};32 33// Requires that |SC| is not null and has an associated function to it.34std::function<Error()> dispatch(cl::SubCommand *SC);35 36} // namespace llvm::xray37 38#endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H39