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
9#include "mlir/TableGen/GenInfo.h"
10
11#include "mlir/TableGen/GenNameParser.h"
12#include "llvm/Support/CommandLine.h"
13#include "llvm/Support/ManagedStatic.h"
14
15using namespace mlir;
16
17static llvm::ManagedStatic<std::vector<GenInfo>> generatorRegistry;
18
19GenRegistration::GenRegistration(StringRef arg, StringRef description,
20 const GenFunction &function) {
21 generatorRegistry->emplace_back(args&: arg, args&: description, args: function);
22}
23
24GenNameParser::GenNameParser(llvm::cl::Option &opt)
25 : llvm::cl::parser<const GenInfo *>(opt) {
26 for (const auto &kv : *generatorRegistry) {
27 addLiteralOption(Name: kv.getGenArgument(), V: &kv, HelpStr: kv.getGenDescription());
28 }
29}
30
31void GenNameParser::printOptionInfo(const llvm::cl::Option &o,
32 size_t globalWidth) const {
33 GenNameParser *tp = const_cast<GenNameParser *>(this);
34 llvm::array_pod_sort(Start: tp->Values.begin(), End: tp->Values.end(),
35 Compare: [](const GenNameParser::OptionInfo *vT1,
36 const GenNameParser::OptionInfo *vT2) {
37 return vT1->Name.compare(RHS: vT2->Name);
38 });
39 using llvm::cl::parser;
40 parser<const GenInfo *>::printOptionInfo(O: o, GlobalWidth: globalWidth);
41}
42

source code of mlir/lib/TableGen/GenInfo.cpp