Chris Bieneman | 732e0aa | 2014-10-15 21:54:35 +0000 | [diff] [blame] | 1 | //===- llvm/Support/Options.cpp - Debug options support ---------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Chris Bieneman | 732e0aa | 2014-10-15 21:54:35 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the helper objects for defining debug options using the |
| 10 | // new API built on cl::opt, but not requiring the use of static globals. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Support/Options.h" |
| 15 | #include "llvm/Support/ManagedStatic.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | |
| 19 | OptionRegistry::~OptionRegistry() { |
| 20 | for (auto IT = Options.begin(); IT != Options.end(); ++IT) |
| 21 | delete IT->second; |
| 22 | } |
| 23 | |
| 24 | void OptionRegistry::addOption(void *Key, cl::Option *O) { |
| 25 | assert(Options.find(Key) == Options.end() && |
| 26 | "Argument with this key already registerd"); |
| 27 | Options.insert(std::make_pair(Key, O)); |
| 28 | } |
| 29 | |
| 30 | static ManagedStatic<OptionRegistry> OR; |
| 31 | |
| 32 | OptionRegistry &OptionRegistry::instance() { return *OR; } |