comparison include/llvm/Support/Options.h @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
comparison
equal deleted inserted replaced
146:3fc4d5c3e21e 148:63bd29f05246
1 //===- llvm/Support/Options.h - Debug options support -----------*- C++ -*-===// 1 //===- llvm/Support/Options.h - Debug options support -----------*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // 4 // See https://llvm.org/LICENSE.txt for license information.
5 // This file is distributed under the University of Illinois Open Source 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // License. See LICENSE.TXT for details.
7 // 6 //
8 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
9 /// \file 8 /// \file
10 /// This file declares helper objects for defining debug options that can be 9 /// This file declares helper objects for defining debug options that can be
11 /// configured via the command line. The new API currently builds on the cl::opt 10 /// configured via the command line. The new API currently builds on the cl::opt
54 template <typename ValT, typename Base, ValT(Base::*Mem)> 53 template <typename ValT, typename Base, ValT(Base::*Mem)>
55 char OptionKey<ValT, Base, Mem>::ID = 0; 54 char OptionKey<ValT, Base, Mem>::ID = 0;
56 55
57 } // namespace detail 56 } // namespace detail
58 57
59 /// \brief Singleton class used to register debug options. 58 /// Singleton class used to register debug options.
60 /// 59 ///
61 /// The OptionRegistry is responsible for managing lifetimes of the options and 60 /// The OptionRegistry is responsible for managing lifetimes of the options and
62 /// provides interfaces for option registration and reading values from options. 61 /// provides interfaces for option registration and reading values from options.
63 /// This object is a singleton, only one instance should ever exist so that all 62 /// This object is a singleton, only one instance should ever exist so that all
64 /// options are registered in the same place. 63 /// options are registered in the same place.
65 class OptionRegistry { 64 class OptionRegistry {
66 private: 65 private:
67 DenseMap<void *, cl::Option *> Options; 66 DenseMap<void *, cl::Option *> Options;
68 67
69 /// \brief Adds a cl::Option to the registry. 68 /// Adds a cl::Option to the registry.
70 /// 69 ///
71 /// \param Key unique key for option 70 /// \param Key unique key for option
72 /// \param O option to map to \p Key 71 /// \param O option to map to \p Key
73 /// 72 ///
74 /// Allocated cl::Options are owned by the OptionRegistry and are deallocated 73 /// Allocated cl::Options are owned by the OptionRegistry and are deallocated
77 76
78 public: 77 public:
79 ~OptionRegistry(); 78 ~OptionRegistry();
80 OptionRegistry() {} 79 OptionRegistry() {}
81 80
82 /// \brief Returns a reference to the singleton instance. 81 /// Returns a reference to the singleton instance.
83 static OptionRegistry &instance(); 82 static OptionRegistry &instance();
84 83
85 /// \brief Registers an option with the OptionRegistry singleton. 84 /// Registers an option with the OptionRegistry singleton.
86 /// 85 ///
87 /// \tparam ValT type of the option's data 86 /// \tparam ValT type of the option's data
88 /// \tparam Base class used to key the option 87 /// \tparam Base class used to key the option
89 /// \tparam Mem member of \p Base used for keying the option 88 /// \tparam Mem member of \p Base used for keying the option
90 /// 89 ///
98 cl::opt<ValT> *Option = new cl::opt<ValT>(ArgStr, cl::desc(Desc), 97 cl::opt<ValT> *Option = new cl::opt<ValT>(ArgStr, cl::desc(Desc),
99 cl::Hidden, cl::init(InitValue)); 98 cl::Hidden, cl::init(InitValue));
100 instance().addOption(&detail::OptionKey<ValT, Base, Mem>::ID, Option); 99 instance().addOption(&detail::OptionKey<ValT, Base, Mem>::ID, Option);
101 } 100 }
102 101
103 /// \brief Returns the value of the option. 102 /// Returns the value of the option.
104 /// 103 ///
105 /// \tparam ValT type of the option's data 104 /// \tparam ValT type of the option's data
106 /// \tparam Base class used to key the option 105 /// \tparam Base class used to key the option
107 /// \tparam Mem member of \p Base used for keying the option 106 /// \tparam Mem member of \p Base used for keying the option
108 /// 107 ///