]> granicus.if.org Git - clang/commitdiff
Moved construction of TargetInfo objects out of the Driver
authorTed Kremenek <kremenek@apple.com>
Wed, 12 Dec 2007 18:05:32 +0000 (18:05 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 12 Dec 2007 18:05:32 +0000 (18:05 +0000)
and into the "Basic" library. TargetInfo objects are now
constructed from triples by calling the static method
TargetInfo::CreateTargetInfo.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44940 91177308-0d34-0410-b5e6-96231b3b80d8

Basic/Targets.cpp [moved from Driver/Targets.cpp with 97% similarity]
Driver/TranslationUnit.cpp
Driver/clang.cpp
Driver/clang.h
include/clang/Basic/TargetInfo.h

similarity index 97%
rename from Driver/Targets.cpp
rename to Basic/Targets.cpp
index 6e810efd3c37e5f39d1663d0457d8ec44e2bc100..ed29c9000a1ca43f6f22011f51b28735e6e90c14 100644 (file)
@@ -7,19 +7,16 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements the -arch command line option and creates a TargetInfo
-// that represents them.
+// This file implements construction of a TargetInfo object from a 
+// target triple.
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang.h"
 #include "clang/AST/Builtins.h"
 #include "clang/AST/TargetBuiltins.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/TargetInfo.h"
-
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/CommandLine.h"
 
 using namespace clang;
 
@@ -702,14 +699,13 @@ static TargetInfoImpl *CreateTarget(const std::string& T) {
 
 /// CreateTargetInfo - Return the set of target info objects as specified by
 /// the -arch command line option.
-TargetInfo *clang::CreateTargetInfo(SourceManager& SrcMgr,
-                                    const std::vector<std::string>& triples, 
-                                    Diagnostic *Diags) {
+TargetInfo* TargetInfo::CreateTargetInfo(SourceManager& SrcMgr,
+                                         const std::string* TriplesStart,
+                                         const std::string* TriplesEnd,
+                                         Diagnostic *Diags) {
 
-  assert (!triples.empty() && "No target triple.");
-  
   // Create the primary target and target info.
-  TargetInfoImpl* PrimaryTarget = CreateTarget(triples[0]);
+  TargetInfoImpl* PrimaryTarget = CreateTarget(*TriplesStart);
 
   if (!PrimaryTarget)
     return NULL;
@@ -717,16 +713,18 @@ TargetInfo *clang::CreateTargetInfo(SourceManager& SrcMgr,
   TargetInfo *TI = new TargetInfo(SrcMgr, PrimaryTarget, Diags);
   
   // Add all secondary targets.
-  for (unsigned i = 1, e = triples.size(); i != e; ++i) {
-    TargetInfoImpl* SecondaryTarget = CreateTarget(triples[i]);
+  for (const std::string* I=TriplesStart+1; I != TriplesEnd; ++I) {
+    TargetInfoImpl* SecondaryTarget = CreateTarget(*I);
 
     if (!SecondaryTarget) {
-      fprintf (stderr, "Warning: secondary target '%s' unrecognized.\n",
-               triples[i].c_str());
+      fprintf (stderr,
+               "Warning: secondary target '%s' unrecognized.\n", 
+               I->c_str());
+
       continue;
     }
 
-    TI->AddSecondaryTarget(CreateTarget(triples[i]));
+    TI->AddSecondaryTarget(SecondaryTarget);
   }
   
   return TI;
index 6f35a32371a5ca05ee550726441301ca419d259b..f5c6cfff20b019ab456d7d2e4b1fb62f0054b616 100644 (file)
@@ -189,14 +189,14 @@ TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr,
   // Read the LangOptions.
   TU->LangOpts.Read(Dezr);
   
-  { 
-    // Read the TargetInfo.
+  { // Read the TargetInfo.
     llvm::SerializedPtrID PtrID = Dezr.ReadPtrID();
     char* triple = Dezr.ReadCStr(NULL,0,true);
-    std::vector<std::string> triples;
-    triples.push_back(triple);
+    std::string Triple(triple);
+    Dezr.RegisterPtr(PtrID,TargetInfo::CreateTargetInfo(SrcMgr,
+                                                        &Triple,
+                                                        &Triple+1));
     delete [] triple;
-    Dezr.RegisterPtr(PtrID,CreateTargetInfo(SrcMgr,triples,NULL));
   }
   
   // For Selectors, we must read the identifier table first because the
index b526bb157fd833d8fa479d013adc9871126e4dde..316b93a64dca682d09171f562724105deeff6480 100644 (file)
@@ -1019,7 +1019,10 @@ int main(int argc, char **argv) {
     // Create triples, and create the TargetInfo.
     std::vector<std::string> triples;
     CreateTargetTriples(triples);
-    Target = CreateTargetInfo(SourceMgr,triples,&Diags);
+    Target = TargetInfo::CreateTargetInfo(SourceMgr,
+                                          &triples[0],
+                                          &triples[0]+triples.size(),
+                                          &Diags);
       
     if (Target == 0) {
       fprintf(stderr, "Sorry, I don't know what target this is: %s\n",
index c4bbb84658a8dfdf6e24be407e0e5c390ba61520..079794d480ed85a5edb35c6139dfbd2952b3144c 100644 (file)
@@ -35,12 +35,6 @@ void DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP,
 /// implements the -parse-print-callbacks option.
 MinimalAction *CreatePrintParserActionsAction(IdentifierTable &);
 
-/// CreateTargetInfo - Return the set of target info objects as specified by
-/// the -arch command line option.
-TargetInfo *CreateTargetInfo(SourceManager& SrcMgr,
-                             const std::vector<std::string>& triples,
-                             Diagnostic *Diags);
-
 /// EmitLLVMFromASTs - Implement -emit-llvm, which generates llvm IR from C.
 void EmitLLVMFromASTs(Preprocessor &PP, unsigned MainFileID,
                       bool PrintStats);
index 30c6e05ee33a644cb8d22ee7d4746a80bf730622..68bf0fd1aeef6aeebdd0d0c9680c810aeda0adea 100644 (file)
@@ -64,8 +64,11 @@ class TargetInfo {
 
   /// These are all caches for target values.
   unsigned WCharWidth, WCharAlign;
+
+  //==----------------------------------------------------------------==/
+  //                  TargetInfo Construction.
+  //==----------------------------------------------------------------==/  
   
-public:
   TargetInfo(SourceManager& SMgr, const TargetInfoImpl *Primary,
              Diagnostic *D = 0) : SrcMgr(SMgr) {
     PrimaryTarget = Primary;
@@ -75,6 +78,19 @@ public:
     // Initialize Cache values to uncomputed.
     WCharWidth = 0;
   }
+
+public:  
+  /// CreateTargetInfo - Create a TargetInfo object from a group of
+  ///  target triples.  The first target triple is considered the primary
+  ///  target.
+  static TargetInfo* CreateTargetInfo(SourceManager& SrcMgr,
+                                      const std::string* TriplesBeg,
+                                      const std::string* TripledEnd,
+                                      Diagnostic* Diags = NULL);
+
+  //==----------------------------------------------------------------==/
+  //                       Accessors.
+  //==----------------------------------------------------------------==/  
   
   /// isNonPortable - Return true if the current translation unit has used a
   /// target property that is non-portable across the secondary targets.