mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
29 lines
729 B
C++
29 lines
729 B
C++
#pragma once
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "revng/Support/IRHelpers.h"
|
|
|
|
/// Temporarily change the value of a llvm::cl option
|
|
template<typename T>
|
|
struct TemporaryLLVMOption {
|
|
public:
|
|
TemporaryLLVMOption(const char *Name, const T &Value) :
|
|
Name(Name), Options(llvm::cl::getRegisteredOptions()) {
|
|
OldValue = Opt(Options, Name)->getValue();
|
|
Opt(Options, Name)->setInitialValue(Value);
|
|
}
|
|
|
|
~TemporaryLLVMOption() { Opt(Options, Name)->setInitialValue(OldValue); }
|
|
|
|
private:
|
|
T OldValue;
|
|
const char *Name;
|
|
llvm::StringMap<llvm::cl::Option *> &Options;
|
|
static constexpr const auto &Opt = getOption<T>;
|
|
};
|