1311116Sdim//===- xray-registry.h - Define registry mechanism for commands. ----------===// 2311116Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6311116Sdim// 7311116Sdim//===----------------------------------------------------------------------===// 8311116Sdim// 9311116Sdim// Implement a simple subcommand registry. 10311116Sdim// 11311116Sdim//===----------------------------------------------------------------------===// 12311116Sdim#ifndef TOOLS_LLVM_XRAY_XRAY_REGISTRY_H 13311116Sdim#define TOOLS_LLVM_XRAY_XRAY_REGISTRY_H 14311116Sdim 15311116Sdim#include "llvm/Support/CommandLine.h" 16311116Sdim#include "llvm/Support/Error.h" 17311116Sdim 18311116Sdimnamespace llvm { 19311116Sdimnamespace xray { 20311116Sdim 21311116Sdim// Use |CommandRegistration| as a global initialiser that registers a function 22311116Sdim// and associates it with |SC|. This requires that a command has not been 23311116Sdim// registered to a given |SC|. 24311116Sdim// 25311116Sdim// Usage: 26311116Sdim// 27311116Sdim// // At namespace scope. 28311116Sdim// static CommandRegistration Unused(&MySubCommand, [] { ... }); 29311116Sdim// 30311116Sdimstruct CommandRegistration { 31311116Sdim CommandRegistration(cl::SubCommand *SC, std::function<Error()> Command); 32311116Sdim}; 33311116Sdim 34311116Sdim// Requires that |SC| is not null and has an associated function to it. 35311116Sdimstd::function<Error()> dispatch(cl::SubCommand *SC); 36311116Sdim 37311116Sdim} // namespace xray 38311116Sdim} // namespace llvm 39311116Sdim 40311116Sdim#endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H 41