1193323Sed//=== RegistryParser.h - Linker-supported plugin registries -----*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// Defines a command-line parser for a registry. 11193323Sed// 12193323Sed//===----------------------------------------------------------------------===// 13193323Sed 14249423Sdim#ifndef LLVM_SUPPORT_REGISTRYPARSER_H 15249423Sdim#define LLVM_SUPPORT_REGISTRYPARSER_H 16193323Sed 17193323Sed#include "llvm/Support/CommandLine.h" 18193323Sed#include "llvm/Support/Registry.h" 19193323Sed 20193323Sednamespace llvm { 21193323Sed 22193323Sed /// A command-line parser for a registry. Use like such: 23193323Sed /// 24193323Sed /// static cl::opt<Registry<Collector>::entry, false, 25193323Sed /// RegistryParser<Collector> > 26193323Sed /// GCOpt("gc", cl::desc("Garbage collector to use."), 27193323Sed /// cl::value_desc()); 28193323Sed /// 29193323Sed /// To make use of the value: 30193323Sed /// 31193323Sed /// Collector *TheCollector = GCOpt->instantiate(); 32193323Sed /// 33193323Sed template <typename T, typename U = RegistryTraits<T> > 34193323Sed class RegistryParser : 35193323Sed public cl::parser<const typename U::entry*>, 36193323Sed public Registry<T, U>::listener { 37193323Sed typedef U traits; 38193323Sed typedef typename U::entry entry; 39193323Sed typedef typename Registry<T, U>::listener listener; 40193323Sed 41193323Sed protected: 42193323Sed void registered(const entry &E) { 43193323Sed addLiteralOption(traits::nameof(E), &E, traits::descof(E)); 44193323Sed } 45193323Sed 46193323Sed public: 47193323Sed void initialize(cl::Option &O) { 48193323Sed listener::init(); 49193323Sed cl::parser<const typename U::entry*>::initialize(O); 50193323Sed } 51193323Sed }; 52193323Sed 53193323Sed} 54193323Sed 55249423Sdim#endif // LLVM_SUPPORT_REGISTRYPARSER_H 56