xray-registry.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Implement a simple subcommand registry.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef TOOLS_LLVM_XRAY_XRAY_REGISTRY_H
  13. #define TOOLS_LLVM_XRAY_XRAY_REGISTRY_H
  14. #include "llvm/Support/CommandLine.h"
  15. #include "llvm/Support/Error.h"
  16. namespace llvm {
  17. namespace xray {
  18. // Use |CommandRegistration| as a global initialiser that registers a function
  19. // and associates it with |SC|. This requires that a command has not been
  20. // registered to a given |SC|.
  21. //
  22. // Usage:
  23. //
  24. // // At namespace scope.
  25. // static CommandRegistration Unused(&MySubCommand, [] { ... });
  26. //
  27. struct CommandRegistration {
  28. CommandRegistration(cl::SubCommand *SC, std::function<Error()> Command);
  29. };
  30. // Requires that |SC| is not null and has an associated function to it.
  31. std::function<Error()> dispatch(cl::SubCommand *SC);
  32. } // namespace xray
  33. } // namespace llvm
  34. #endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H