/// \brief Exposes information about the current target.
///
class TargetInfo : public RefCountedBase<TargetInfo> {
- IntrusiveRefCntPtr<TargetOptions> TargetOpts;
+ std::shared_ptr<TargetOptions> TargetOpts;
llvm::Triple Triple;
protected:
// Target values set by the ctor of the actual target implementation. Default
/// \param Opts - The options to use to initialize the target. The target may
/// modify the options to canonicalize the target feature information to match
/// what the backend expects.
- static TargetInfo* CreateTargetInfo(DiagnosticsEngine &Diags,
- TargetOptions *Opts);
+ static TargetInfo *
+ CreateTargetInfo(DiagnosticsEngine &Diags,
+ const std::shared_ptr<TargetOptions> &Opts);
virtual ~TargetInfo();
return *TargetOpts;
}
- void setTargetOpts(TargetOptions *TargetOpts) {
- this->TargetOpts = TargetOpts;
- }
-
///===---- Target Data Type Query Methods -------------------------------===//
enum IntType {
NoInt = 0,
#ifndef LLVM_CLANG_FRONTEND_TARGETOPTIONS_H
#define LLVM_CLANG_FRONTEND_TARGETOPTIONS_H
-#include "clang/Basic/LLVM.h"
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include <string>
#include <vector>
namespace clang {
/// \brief Options for controlling the target.
-class TargetOptions : public RefCountedBase<TargetOptions> {
+class TargetOptions {
public:
/// If given, the name of the target triple to compile for. If not given the
/// target will be selected to match the host.
IntrusiveRefCntPtr<TargetInfo> Target;
IntrusiveRefCntPtr<Preprocessor> PP;
IntrusiveRefCntPtr<ASTContext> Ctx;
- IntrusiveRefCntPtr<TargetOptions> TargetOpts;
+ std::shared_ptr<TargetOptions> TargetOpts;
IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts;
IntrusiveRefCntPtr<ASTReader> Reader;
bool HadModuleLoaderFatalFailure;
std::shared_ptr<LangOptions> LangOpts;
/// Options controlling the target.
- IntrusiveRefCntPtr<TargetOptions> TargetOpts;
+ std::shared_ptr<TargetOptions> TargetOpts;
/// Options controlling the diagnostic engine.
IntrusiveRefCntPtr<DiagnosticOptions> DiagnosticOpts;
/// CreateTargetInfo - Return the target info object for the specified target
/// triple.
-TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
- TargetOptions *Opts) {
+TargetInfo *
+TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
+ const std::shared_ptr<TargetOptions> &Opts) {
llvm::Triple Triple(Opts->Triple);
// Construct the target
Diags.Report(diag::err_target_unknown_triple) << Triple.str();
return nullptr;
}
- Target->setTargetOpts(Opts);
+ Target->TargetOpts = Opts;
// Set the target CPU if specified.
if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
Preprocessor &PP;
ASTContext &Context;
LangOptions &LangOpt;
- IntrusiveRefCntPtr<TargetOptions> &TargetOpts;
+ std::shared_ptr<TargetOptions> &TargetOpts;
IntrusiveRefCntPtr<TargetInfo> &Target;
unsigned &Counter;
bool InitializedLanguage;
public:
- ASTInfoCollector(Preprocessor &PP, ASTContext &Context, LangOptions &LangOpt,
- IntrusiveRefCntPtr<TargetOptions> &TargetOpts,
- IntrusiveRefCntPtr<TargetInfo> &Target,
- unsigned &Counter)
- : PP(PP), Context(Context), LangOpt(LangOpt),
- TargetOpts(TargetOpts), Target(Target),
- Counter(Counter),
- InitializedLanguage(false) {}
+ ASTInfoCollector(Preprocessor &PP, ASTContext &Context, LangOptions &LangOpt,
+ std::shared_ptr<TargetOptions> &TargetOpts,
+ IntrusiveRefCntPtr<TargetInfo> &Target, unsigned &Counter)
+ : PP(PP), Context(Context), LangOpt(LangOpt), TargetOpts(TargetOpts),
+ Target(Target), Counter(Counter), InitializedLanguage(false) {}
bool ReadLanguageOptions(const LangOptions &LangOpts,
bool Complain) override {
// If we've already initialized the target, don't do it again.
if (Target)
return false;
-
- this->TargetOpts = new TargetOptions(TargetOpts);
- Target = TargetInfo::CreateTargetInfo(PP.getDiagnostics(),
- &*this->TargetOpts);
+
+ this->TargetOpts = std::make_shared<TargetOptions>(TargetOpts);
+ Target =
+ TargetInfo::CreateTargetInfo(PP.getDiagnostics(), this->TargetOpts);
updated();
return false;
Clang->setDiagnostics(&getDiagnostics());
// Create the target instance.
- Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
- &Clang->getTargetOpts()));
+ Clang->setTarget(TargetInfo::CreateTargetInfo(
+ Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
if (!Clang->hasTarget()) {
delete OverrideMainBuffer;
return true;
Clang->setDiagnostics(&getDiagnostics());
// Create the target instance.
- Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
- &Clang->getTargetOpts()));
+ Clang->setTarget(TargetInfo::CreateTargetInfo(
+ Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
if (!Clang->hasTarget()) {
llvm::sys::fs::remove(FrontendOpts.OutputFile);
Preamble.clear();
Clang->setDiagnostics(&AST->getDiagnostics());
// Create the target instance.
- Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
- &Clang->getTargetOpts()));
+ Clang->setTarget(TargetInfo::CreateTargetInfo(
+ Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
if (!Clang->hasTarget())
return nullptr;
ProcessWarningOptions(Diag, CCInvocation->getDiagnosticOpts());
// Create the target instance.
- Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
- &Clang->getTargetOpts()));
+ Clang->setTarget(TargetInfo::CreateTargetInfo(
+ Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
if (!Clang->hasTarget()) {
Clang->setInvocation(nullptr);
return;
std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
Clang->setInvocation(CInvok.release());
Clang->setDiagnostics(Diags.get());
- Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
- &Clang->getTargetOpts()));
+ Clang->setTarget(TargetInfo::CreateTargetInfo(
+ Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
Clang->createFileManager();
Clang->createSourceManager(Clang->getFileManager());
Clang->createPreprocessor(TU_Prefix);
raw_ostream &OS = llvm::errs();
// Create the target instance.
- setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), &getTargetOpts()));
+ setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
+ getInvocation().TargetOpts));
if (!hasTarget())
return false;
SourceMgr(Diags, FileMgr),
TargetOpts(new TargetOptions) {
TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
- Target = TargetInfo::CreateTargetInfo(Diags, &*TargetOpts);
+ Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
}
FileSystemOptions FileMgrOpts;
DiagnosticsEngine Diags;
SourceManager SourceMgr;
LangOptions LangOpts;
- IntrusiveRefCntPtr<TargetOptions> TargetOpts;
+ std::shared_ptr<TargetOptions> TargetOpts;
IntrusiveRefCntPtr<TargetInfo> Target;
};
TargetOpts(new TargetOptions)
{
TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
- Target = TargetInfo::CreateTargetInfo(Diags, &*TargetOpts);
+ Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
}
std::vector<Token> CheckLex(StringRef Source,
DiagnosticsEngine Diags;
SourceManager SourceMgr;
LangOptions LangOpts;
- IntrusiveRefCntPtr<TargetOptions> TargetOpts;
+ std::shared_ptr<TargetOptions> TargetOpts;
IntrusiveRefCntPtr<TargetInfo> Target;
};
class PPCallbacksTest : public ::testing::Test {
protected:
PPCallbacksTest()
- : FileMgr(FileMgrOpts),
- DiagID(new DiagnosticIDs()),
- DiagOpts(new DiagnosticOptions()),
- Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
- SourceMgr(Diags, FileMgr) {
- TargetOpts = new TargetOptions();
+ : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+ DiagOpts(new DiagnosticOptions()),
+ Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
+ SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions()) {
TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
- Target = TargetInfo::CreateTargetInfo(Diags, &*TargetOpts);
+ Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
}
FileSystemOptions FileMgrOpts;
DiagnosticsEngine Diags;
SourceManager SourceMgr;
LangOptions LangOpts;
- IntrusiveRefCntPtr<TargetOptions> TargetOpts;
+ std::shared_ptr<TargetOptions> TargetOpts;
IntrusiveRefCntPtr<TargetInfo> Target;
// Register a header path as a known file and add its location
TargetOpts(new TargetOptions)
{
TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
- Target = TargetInfo::CreateTargetInfo(Diags, &*TargetOpts);
+ Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
}
FileSystemOptions FileMgrOpts;
DiagnosticsEngine Diags;
SourceManager SourceMgr;
LangOptions LangOpts;
- IntrusiveRefCntPtr<TargetOptions> TargetOpts;
+ std::shared_ptr<TargetOptions> TargetOpts;
IntrusiveRefCntPtr<TargetInfo> Target;
};