[clang] [clang-tools-extra] [lld] [llvm] [llvm] Add subcommand support for OptTable (PR #155026)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 5 14:52:57 PDT 2025
================
@@ -323,6 +345,39 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
OS << "\n};\n";
OS << "#endif // OPTTABLE_PREFIXES_TABLE_CODE\n\n";
+ // Dump command IDs.
+ OS << "/////////";
+ OS << "// Command IDs\n\n";
+ OS << "#ifdef OPTTABLE_COMMAND_IDS_TABLE_CODE\n";
+ OS << "static constexpr unsigned OptionCommandIDsTable[] = {\n";
+ {
+ // Ensure the first command set is always empty.
+ assert(!CommandIDs.empty() &&
+ "We should always emit an empty set of commands");
+ assert(CommandIDs.begin()->first.empty() &&
+ "First command set should always be empty");
+ llvm::ListSeparator Sep(",\n");
+ unsigned CurIndex = 0;
+ for (auto &[Command, CommandIndex] : CommandIDs) {
+ // First emit the number of command strings in this list of commands.
+ OS << Sep << " " << Command.size() << " /* commands */";
+ CommandIndex = CurIndex;
+ assert((CurIndex == 0 || !Command.empty()) &&
+ "Only first command set should be empty!");
+ for (const auto &CommandKey : Command) {
+ auto It = llvm::find_if(Commands, [&](const Record *R) {
----------------
PiJoules wrote:
We can use `std::find_if` directly. I think `llvm::find_if` just calls it.
https://github.com/llvm/llvm-project/pull/155026
More information about the llvm-commits
mailing list