| 1 | //===- RemarkUtilRegistry.h: Implement a command registry. ----------------===// |
| 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_REMARKUTIL_REGISTRY_H |
| 13 | #define |
| 14 | |
| 15 | #include "llvm/Support/CommandLine.h" |
| 16 | #include "llvm/Support/Error.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | namespace remarkutil { |
| 20 | |
| 21 | // Use |CommandRegistration| as a global initialiser that registers a function |
| 22 | // and associates it with |SC|. This requires that a command has not been |
| 23 | // registered to a given |SC|. |
| 24 | // |
| 25 | // Usage: |
| 26 | // |
| 27 | // // At namespace scope. |
| 28 | // static CommandRegistration Unused(&MySubCommand, [] { ... }); |
| 29 | // |
| 30 | struct CommandRegistration { |
| 31 | CommandRegistration(cl::SubCommand *SC, std::function<Error()> Command); |
| 32 | }; |
| 33 | |
| 34 | // Requires that |SC| is not null and has an associated function to it. |
| 35 | std::function<Error()> dispatch(cl::SubCommand *SC); |
| 36 | |
| 37 | } // namespace remarkutil |
| 38 | } // namespace llvm |
| 39 | |
| 40 | #endif // TOOLS_LLVM_REMARKUTIL_REGISTRY_H |
| 41 | |