brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 62a3d52 Raw
42 lines · cpp
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-exception6//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(arg, description, function);22}23 24GenNameParser::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 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(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}42