[cfe-commits] r55091 - in /cfe/trunk/lib/Basic: TargetInfo.cpp Targets.cpp

Eli Friedman eli.friedman at gmail.com
Wed Aug 20 17:13:15 PDT 2008


Author: efriedma
Date: Wed Aug 20 19:13:15 2008
New Revision: 55091

URL: http://llvm.org/viewvc/llvm-project?rev=55091&view=rev
Log:
First cut at OS detection, taking advantage of the new generic targets.  
This approach allows adding OS-specific targets/defines/etc. without 
completely breaking unknown subtargets.  No new subtargets yet, although 
I plan to add x86-Linux soon.  Others can add targets that they use as 
needed; adding a new subtarget takes very little code.

Also does some fixups for description strings; a lot of them were 
unspecified.  I think all the ones I added are correct, but 
they're unverified; corrections are welcome.


Modified:
    cfe/trunk/lib/Basic/TargetInfo.cpp
    cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=55091&r1=55090&r2=55091&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Wed Aug 20 19:13:15 2008
@@ -37,8 +37,8 @@
   FloatFormat = &llvm::APFloat::IEEEsingle;
   DoubleFormat = &llvm::APFloat::IEEEdouble;
   LongDoubleFormat = &llvm::APFloat::IEEEdouble;
-  DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:\
-32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128";
+  DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
+                      "i64:64:64-f32:32:32-f64:64:64";
 }
 
 // Out of line virtual dtor for TargetInfo.

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=55091&r1=55090&r2=55091&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Aug 20 19:13:15 2008
@@ -458,7 +458,10 @@
 namespace {
 class PPC32TargetInfo : public PPCTargetInfo {
 public:
-  PPC32TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {}
+  PPC32TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
+    DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
+                        "i64:64:64-f32:32:32-f64:64:64-v128:128:128";
+  }
   virtual void getTargetDefines(std::vector<char> &Defines) const {
     getPowerPCDefines(Defines, false);
   }
@@ -470,6 +473,8 @@
 public:
   PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
     LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
+    DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
+                        "i64:64:64-f32:32:32-f64:64:64-v128:128:128";
   }
   virtual void getTargetDefines(std::vector<char> &Defines) const {
     getPowerPCDefines(Defines, true);
@@ -612,6 +617,9 @@
     DoubleAlign = LongLongAlign = 32;
     LongDoubleWidth = 96;
     LongDoubleAlign = 32;
+    DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
+                        "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
+                        "a0:0:64-f80:32:32";
   }
   virtual const char *getVAListDeclaration() const {
     return "typedef char* __builtin_va_list;";
@@ -629,6 +637,9 @@
   DarwinI386TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) {
     LongDoubleWidth = 128;
     LongDoubleAlign = 128;
+    DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
+                        "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
+                        "a0:0:64-f80:128:128";
   }
   virtual void getTargetDefines(std::vector<char> &Defines) const {
     X86_32TargetInfo::getTargetDefines(Defines);
@@ -645,6 +656,9 @@
     LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
     LongDoubleWidth = 128;
     LongDoubleAlign = 128;
+    DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
+                        "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
+                        "a0:0:64-f80:128:128";
   }
   virtual const char *getVAListDeclaration() const {
     return "typedef struct __va_list_tag {"
@@ -679,6 +693,8 @@
 public:
   ARMTargetInfo(const std::string& triple) : TargetInfo(triple) {
     // FIXME: Are the defaults correct for ARM?
+    DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
+                        "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:64";
   }
   virtual void getTargetDefines(std::vector<char> &Defines) const {
     getARMDefines(Defines);
@@ -746,6 +762,8 @@
 public:
   SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
     // FIXME: Support Sparc quad-precision long double?
+    DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
+                        "i64:64:64-f32:32:32-f64:64:64-v64:64:64";
   }
   virtual void getTargetDefines(std::vector<char> &Defines) const {
     // FIXME: This is missing a lot of important defines; some of the
@@ -846,26 +864,53 @@
 /// CreateTargetInfo - Return the target info object for the specified target
 /// triple.
 TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
-  if (T.find("ppc-") == 0 || T.find("powerpc-") == 0)
-    return new DarwinPPCTargetInfo(T);
-
-  if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0)
-    return new DarwinPPC64TargetInfo(T);
-
-  if (T.find("armv6-") == 0 || T.find("arm-") == 0)
-    return new DarwinARMTargetInfo(T);
-
-  if (T.find("sparc-") == 0)
-    return new SolarisSparcV8TargetInfo(T); // ugly hack
-
-  if (T.find("x86_64-") == 0)
-    return new DarwinX86_64TargetInfo(T);
+  // OS detection; this isn't really anywhere near complete.
+  // Additions and corrections are welcome.
+  bool isDarwin = T.find("-darwin") != std::string::npos;
+  bool isSolaris = T.find("-solaris") != std::string::npos;
+  bool isLinux = T.find("-linux") != std::string::npos;
+  bool isWindows = T.find("-windows") != std::string::npos ||
+                   T.find("-win32") != std::string::npos ||
+                   T.find("-mingw") != std::string::npos;
+
+  if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) {
+    if (isDarwin)
+      return new DarwinPPCTargetInfo(T);
+    return new PPC32TargetInfo(T);
+  }
+
+  if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) {
+    if (isDarwin)
+      return new DarwinPPC64TargetInfo(T);
+    return new PPC64TargetInfo(T);
+  }
+
+  if (T.find("armv6-") == 0 || T.find("arm-") == 0) {
+    if (isDarwin)
+      return new DarwinARMTargetInfo(T);
+    return new ARMTargetInfo(T);
+  }
+
+  if (T.find("sparc-") == 0) {
+    if (isSolaris)
+      return new SolarisSparcV8TargetInfo(T);
+    return new SparcV8TargetInfo(T);
+  }
+
+  if (T.find("x86_64-") == 0) {
+    if (isDarwin)
+      return new DarwinX86_64TargetInfo(T);
+    return new X86_64TargetInfo(T);
+  }
 
   if (T.find("pic16-") == 0)
     return new PIC16TargetInfo(T);
 
-  if (IsX86(T))
-    return new DarwinI386TargetInfo(T);
+  if (IsX86(T)) {
+    if (isDarwin)
+      return new DarwinI386TargetInfo(T);
+    return new X86_32TargetInfo(T);
+  }
 
   return NULL;
 }





More information about the cfe-commits mailing list