[cfe-commits] r44560 - in /cfe/trunk/Driver: Targets.cpp clang.cpp

Ted Kremenek kremenek at apple.com
Mon Dec 3 15:23:21 PST 2007


Author: kremenek
Date: Mon Dec  3 17:23:21 2007
New Revision: 44560

URL: http://llvm.org/viewvc/llvm-project?rev=44560&view=rev
Log:
For target processing, on non-Darwin systems instead of using the host triple,
we default to "i386-apple-darwin".  This is an interim solution.

Removed processing of "linux" triples from Targets.cpp, since we don't have
any sensical Linux target support (yet).

Cleaned up error processing of targets; added better diagnostics.

Modified:
    cfe/trunk/Driver/Targets.cpp
    cfe/trunk/Driver/clang.cpp

Modified: cfe/trunk/Driver/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Targets.cpp?rev=44560&r1=44559&r2=44560&view=diff

==============================================================================
--- cfe/trunk/Driver/Targets.cpp (original)
+++ cfe/trunk/Driver/Targets.cpp Mon Dec  3 17:23:21 2007
@@ -18,8 +18,6 @@
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/CommandLine.h"
-#include <algorithm>
-#include <cctype>
 
 using namespace clang;
 
@@ -688,17 +686,8 @@
     else if (T.find("bogusW16W16-") == 0) // For testing portability.
       return new LinuxTargetInfo(T);
   }
-  else { 
-    // Make a copy of the triple that is all lowercase.
-    std::string T_lower(T);    
-    std::transform(T_lower.begin(), T_lower.end(),
-                   T_lower.begin(), (int(*)(int)) std::tolower);
 
-    if (T_lower.find("linux") != std::string::npos && IsX86(T))
-      return new LinuxTargetInfo(T);
-  }
-  
-  assert (false && "Unknown target!");
+  return NULL;
 }
 
 /// CreateTargetInfo - Return the set of target info objects as specified by
@@ -709,11 +698,25 @@
   assert (!triples.empty() && "No target triple.");
   
   // Create the primary target and target info.
-  TargetInfo *TI = new TargetInfo(CreateTarget(triples[0]), &Diags);
+  TargetInfoImpl* PrimaryTarget = CreateTarget(triples[0]);
+
+  if (!PrimaryTarget)
+    return NULL;
+  
+  TargetInfo *TI = new TargetInfo(PrimaryTarget, &Diags);
   
   // Add all secondary targets.
-  for (unsigned i = 1, e = triples.size(); i != e; ++i)
+  for (unsigned i = 1, e = triples.size(); i != e; ++i) {
+    TargetInfoImpl* SecondaryTarget = CreateTarget(triples[i]);
+
+    if (!SecondaryTarget) {
+      fprintf (stderr, "Warning: secondary target '%s' unrecognized.\n",
+               triples[i].c_str());
+      continue;
+    }
+
     TI->AddSecondaryTarget(CreateTarget(triples[i]));
+  }
   
   return TI;
 }

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=44560&r1=44559&r2=44560&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Mon Dec  3 17:23:21 2007
@@ -424,8 +424,14 @@
   
   // Initialize base triple.  If a -triple option has been specified, use
   // that triple.  Otherwise, default to the host triple.
-  if (TargetTriple.getValue().empty())
-    base_triple = LLVM_HOSTTRIPLE;
+  if (TargetTriple.getValue().empty()) {
+    // HACK: For non-darwin systems, we don't have any real target support
+    //  yet.  For these systems, set the target to darwin.
+    if (!strstr("darwin",LLVM_HOSTTRIPLE))
+      base_triple = "i386-apple-darwin";
+    else
+      base_triple = LLVM_HOSTTRIPLE;
+  }
   else
     base_triple = TargetTriple.getValue();
   
@@ -991,12 +997,13 @@
     std::vector<std::string> triples;
     CreateTargetTriples(triples);
     Target = CreateTargetInfo(triples,Diags);
-  }
   
-  if (Target == 0) {
-    fprintf(stderr,
-            "Sorry, don't know what target this is, please use -arch.\n");
-    exit(1);
+    if (Target == 0) {
+      fprintf(stderr, "Sorry, I don't know what target this is: %s\n",
+              triples[0].c_str());
+      fprintf(stderr, "Please use -triple or -arch.\n");
+      exit(1);
+    }
   }
   
   // Process the -I options and set them in the HeaderInfo.





More information about the cfe-commits mailing list