Add associateTargetInfo API

Consolidates duplicate logic behind a convenience API on the
CompilerInstance class both to set the target and return whether the target
was set successfully.
Index: include/clang/Frontend/CompilerInstance.h
===================================================================
--- include/clang/Frontend/CompilerInstance.h	(revision 308857)
+++ include/clang/Frontend/CompilerInstance.h	(working copy)
@@ -800,6 +800,8 @@
 
   void setExternalSemaSource(IntrusiveRefCntPtr<ExternalSemaSource> ESS);
 
+  bool associateTargetInfo();
+
   MemoryBufferCache &getPCMCache() const { return *PCMCache; }
 };
 
Index: lib/Frontend/ASTUnit.cpp
===================================================================
--- lib/Frontend/ASTUnit.cpp	(revision 308857)
+++ lib/Frontend/ASTUnit.cpp	(working copy)
@@ -1038,9 +1038,7 @@
   Clang->setDiagnostics(&getDiagnostics());
   
   // Create the target instance.
-  Clang->setTarget(TargetInfo::CreateTargetInfo(
-      Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
-  if (!Clang->hasTarget())
+  if (!Clang->associateTargetInfo())
     return true;
 
   // Inform the target of the language options.
@@ -1467,9 +1465,7 @@
   Clang->setDiagnostics(&AST->getDiagnostics());
   
   // Create the target instance.
-  Clang->setTarget(TargetInfo::CreateTargetInfo(
-      Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
-  if (!Clang->hasTarget())
+  if (!Clang->associateTargetInfo())
     return nullptr;
 
   // Inform the target of the language options.
@@ -2085,9 +2081,7 @@
   ProcessWarningOptions(Diag, Inv.getDiagnosticOpts());
 
   // Create the target instance.
-  Clang->setTarget(TargetInfo::CreateTargetInfo(
-      Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
-  if (!Clang->hasTarget()) {
+  if (!Clang->associateTargetInfo()) {
     Clang->setInvocation(nullptr);
     return;
   }
Index: lib/Frontend/ChainedIncludesSource.cpp
===================================================================
--- lib/Frontend/ChainedIncludesSource.cpp	(revision 308857)
+++ lib/Frontend/ChainedIncludesSource.cpp	(working copy)
@@ -149,8 +149,7 @@
         new CompilerInstance(CI.getPCHContainerOperations()));
     Clang->setInvocation(std::move(CInvok));
     Clang->setDiagnostics(Diags.get());
-    Clang->setTarget(TargetInfo::CreateTargetInfo(
-        Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
+    Clang->associateTargetInfo();
     Clang->createFileManager();
     Clang->createSourceManager(Clang->getFileManager());
     Clang->createPreprocessor(TU_Prefix);
Index: lib/Frontend/CompilerInstance.cpp
===================================================================
--- lib/Frontend/CompilerInstance.cpp	(revision 308857)
+++ lib/Frontend/CompilerInstance.cpp	(working copy)
@@ -931,9 +931,7 @@
   raw_ostream &OS = llvm::errs();
 
   // Create the target instance.
-  setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
-                                         getInvocation().TargetOpts));
-  if (!hasTarget())
+  if (!associateTargetInfo())
     return false;
 
   // Create TargetInfo for the other side of CUDA and OpenMP compilation.
@@ -2056,3 +2054,10 @@
     IntrusiveRefCntPtr<ExternalSemaSource> ESS) {
   ExternalSemaSrc = std::move(ESS);
 }
+
+bool CompilerInstance::associateTargetInfo()
+{
+  setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
+                                         getInvocation().TargetOpts));
+  return hasTarget();
+}
Index: lib/Frontend/PrecompiledPreamble.cpp
===================================================================
--- lib/Frontend/PrecompiledPreamble.cpp	(revision 308857)
+++ lib/Frontend/PrecompiledPreamble.cpp	(working copy)
@@ -247,9 +247,7 @@
   Clang->setDiagnostics(&Diagnostics);
 
   // Create the target instance.
-  Clang->setTarget(TargetInfo::CreateTargetInfo(
-      Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
-  if (!Clang->hasTarget())
+  if (!Clang->associateTargetInfo())
     return BuildPreambleError::CouldntCreateTargetInfo;
 
   // Inform the target of the language options.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to