MLIR  17.0.0git
GenInfo.cpp
Go to the documentation of this file.
1 //===- GenInfo.cpp - Generator info -----------------------------*- C++ -*-===//
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 
10 
12 #include "llvm/Support/CommandLine.h"
13 #include "llvm/Support/ManagedStatic.h"
14 
15 using namespace mlir;
16 
17 static llvm::ManagedStatic<std::vector<GenInfo>> generatorRegistry;
18 
19 GenRegistration::GenRegistration(StringRef arg, StringRef description,
20  const GenFunction &function) {
21  generatorRegistry->emplace_back(arg, description, function);
22 }
23 
24 GenNameParser::GenNameParser(llvm::cl::Option &opt)
25  : llvm::cl::parser<const GenInfo *>(opt) {
26  for (const auto &kv : *generatorRegistry) {
27  addLiteralOption(kv.getGenArgument(), &kv, kv.getGenDescription());
28  }
29 }
30 
31 void GenNameParser::printOptionInfo(const llvm::cl::Option &o,
32  size_t globalWidth) const {
33  GenNameParser *tp = const_cast<GenNameParser *>(this);
34  llvm::array_pod_sort(tp->Values.begin(), tp->Values.end(),
35  [](const GenNameParser::OptionInfo *vT1,
36  const GenNameParser::OptionInfo *vT2) {
37  return vT1->Name.compare(vT2->Name);
38  });
39  using llvm::cl::parser;
40  parser<const GenInfo *>::printOptionInfo(o, globalWidth);
41 }
static llvm::ManagedStatic< std::vector< GenInfo > > generatorRegistry
Definition: GenInfo.cpp:17
Structure to group information about a generator (argument to invoke via mlir-tblgen,...
Definition: GenInfo.h:29
Include the generated interface declarations.
Definition: CallGraph.h:229
Include the generated interface declarations.
std::function< bool(const llvm::RecordKeeper &recordKeeper, raw_ostream &os)> GenFunction
Generator function to invoke.
Definition: GenInfo.h:25
Adds command line option for each registered generator.
Definition: GenNameParser.h:23
GenNameParser(llvm::cl::Option &opt)
Definition: GenInfo.cpp:24
void printOptionInfo(const llvm::cl::Option &o, size_t globalWidth) const override
Definition: GenInfo.cpp:31
GenRegistration(StringRef arg, StringRef description, const GenFunction &function)
Definition: GenInfo.cpp:19