//
//===----------------------------------------------------------------------===//
//
-// 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;
/// 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;
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;
// 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
// 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",
/// 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);
/// 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;
// 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.