aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Basic/Targets.cpp (renamed from Driver/Targets.cpp)30
-rw-r--r--Driver/TranslationUnit.cpp10
-rw-r--r--Driver/clang.cpp5
-rw-r--r--Driver/clang.h6
-rw-r--r--include/clang/Basic/TargetInfo.h18
5 files changed, 40 insertions, 29 deletions
diff --git a/Driver/Targets.cpp b/Basic/Targets.cpp
index 6e810efd3c..ed29c9000a 100644
--- a/Driver/Targets.cpp
+++ b/Basic/Targets.cpp
@@ -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;
diff --git a/Driver/TranslationUnit.cpp b/Driver/TranslationUnit.cpp
index 6f35a32371..f5c6cfff20 100644
--- a/Driver/TranslationUnit.cpp
+++ b/Driver/TranslationUnit.cpp
@@ -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
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index b526bb157f..316b93a64d 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -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",
diff --git a/Driver/clang.h b/Driver/clang.h
index c4bbb84658..079794d480 100644
--- a/Driver/clang.h
+++ b/Driver/clang.h
@@ -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);
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h
index 30c6e05ee3..68bf0fd1ae 100644
--- a/include/clang/Basic/TargetInfo.h
+++ b/include/clang/Basic/TargetInfo.h
@@ -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.