[PATCH] Rename LinuxTargetInfo to GNUOrAndroidEnvironmentTargetInfo and handle llvm::Triple::Hurd.

Thomas Schwinge thomas at codesourcery.com
Mon Mar 25 09:14:53 PDT 2013


---
 lib/Basic/Targets.cpp |   50 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 16 deletions(-)

diff --git lib/Basic/Targets.cpp lib/Basic/Targets.cpp
index b7cd3dc..ad63fd7 100644
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -308,17 +308,31 @@ public:
     }
 };
 
-// Linux target
+// GNU or Android Environment target
+// FIXME: Perhaps this mixes up too many different things: GNU vs. Android
+// Environment; Linux vs. Hurd Operating System.
 template<typename Target>
-class LinuxTargetInfo : public OSTargetInfo<Target> {
+class GNUOrAndroidEnvironmentTargetInfo : public OSTargetInfo<Target> {
 protected:
   virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                             MacroBuilder &Builder) const {
-    // Linux defines; list based off of gcc output
+    // Based off of gcc output.
     DefineStd(Builder, "unix", Opts);
-    DefineStd(Builder, "linux", Opts);
-    Builder.defineMacro("__gnu_linux__");
     Builder.defineMacro("__ELF__");
+    switch (Triple.getOS()) {
+    case llvm::Triple::Linux:
+      DefineStd(Builder, "linux", Opts);
+      Builder.defineMacro("__gnu_linux__");
+      break;
+    case llvm::Triple::Hurd:
+      //DefineStd(Builder, "MACH", Opts);
+      Builder.defineMacro("__MACH__");
+      Builder.defineMacro("__gnu_hurd__");
+      Builder.defineMacro("__GNU__");
+      break;
+    default:
+      break;
+    }
     if (Triple.getEnvironment() == llvm::Triple::Android)
       Builder.defineMacro("__ANDROID__", "1");
     if (Opts.POSIXThreads)
@@ -327,7 +341,7 @@ protected:
       Builder.defineMacro("_GNU_SOURCE");
   }
 public:
-  LinuxTargetInfo(const std::string& triple)
+  GNUOrAndroidEnvironmentTargetInfo(const std::string& triple)
     : OSTargetInfo<Target>(triple) {
     this->UserLabelPrefix = "";
     this->WIntType = TargetInfo::UnsignedInt;
@@ -4969,6 +4983,9 @@ static TargetInfo *AllocateTarget(const std::string &T) {
   llvm::Triple Triple(T);
   llvm::Triple::OSType os = Triple.getOS();
 
+  // FIXME: Perhaps this should first decide and specialize based upon the
+  // Environment, then Operating System, then Vendor, then Architecture.
+
   switch (Triple.getArch()) {
   default:
     return NULL;
@@ -4991,7 +5008,7 @@ static TargetInfo *AllocateTarget(const std::string &T) {
 
     switch (os) {
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<ARMTargetInfo>(T);
+      return new GNUOrAndroidEnvironmentTargetInfo<ARMTargetInfo>(T);
     case llvm::Triple::FreeBSD:
       return new FreeBSDTargetInfo<ARMTargetInfo>(T);
     case llvm::Triple::NetBSD:
@@ -5014,7 +5031,7 @@ static TargetInfo *AllocateTarget(const std::string &T) {
   case llvm::Triple::mips:
     switch (os) {
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<Mips32EBTargetInfo>(T);
+      return new GNUOrAndroidEnvironmentTargetInfo<Mips32EBTargetInfo>(T);
     case llvm::Triple::RTEMS:
       return new RTEMSTargetInfo<Mips32EBTargetInfo>(T);
     case llvm::Triple::FreeBSD:
@@ -5028,7 +5045,7 @@ static TargetInfo *AllocateTarget(const std::string &T) {
   case llvm::Triple::mipsel:
     switch (os) {
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<Mips32ELTargetInfo>(T);
+      return new GNUOrAndroidEnvironmentTargetInfo<Mips32ELTargetInfo>(T);
     case llvm::Triple::RTEMS:
       return new RTEMSTargetInfo<Mips32ELTargetInfo>(T);
     case llvm::Triple::FreeBSD:
@@ -5042,7 +5059,7 @@ static TargetInfo *AllocateTarget(const std::string &T) {
   case llvm::Triple::mips64:
     switch (os) {
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<Mips64EBTargetInfo>(T);
+      return new GNUOrAndroidEnvironmentTargetInfo<Mips64EBTargetInfo>(T);
     case llvm::Triple::RTEMS:
       return new RTEMSTargetInfo<Mips64EBTargetInfo>(T);
     case llvm::Triple::FreeBSD:
@@ -5058,7 +5075,7 @@ static TargetInfo *AllocateTarget(const std::string &T) {
   case llvm::Triple::mips64el:
     switch (os) {
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<Mips64ELTargetInfo>(T);
+      return new GNUOrAndroidEnvironmentTargetInfo<Mips64ELTargetInfo>(T);
     case llvm::Triple::RTEMS:
       return new RTEMSTargetInfo<Mips64ELTargetInfo>(T);
     case llvm::Triple::FreeBSD:
@@ -5084,7 +5101,7 @@ static TargetInfo *AllocateTarget(const std::string &T) {
       return new DarwinPPC32TargetInfo(T);
     switch (os) {
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<PPC32TargetInfo>(T);
+      return new GNUOrAndroidEnvironmentTargetInfo<PPC32TargetInfo>(T);
     case llvm::Triple::FreeBSD:
       return new FreeBSDTargetInfo<PPC32TargetInfo>(T);
     case llvm::Triple::NetBSD:
@@ -5102,7 +5119,7 @@ static TargetInfo *AllocateTarget(const std::string &T) {
       return new DarwinPPC64TargetInfo(T);
     switch (os) {
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<PPC64TargetInfo>(T);
+      return new GNUOrAndroidEnvironmentTargetInfo<PPC64TargetInfo>(T);
     case llvm::Triple::Lv2:
       return new PS3PPUTargetInfo<PPC64TargetInfo>(T);
     case llvm::Triple::FreeBSD:
@@ -5127,7 +5144,7 @@ static TargetInfo *AllocateTarget(const std::string &T) {
   case llvm::Triple::sparc:
     switch (os) {
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<SparcV8TargetInfo>(T);
+      return new GNUOrAndroidEnvironmentTargetInfo<SparcV8TargetInfo>(T);
     case llvm::Triple::AuroraUX:
       return new AuroraUXSparcV8TargetInfo(T);
     case llvm::Triple::Solaris:
@@ -5153,7 +5170,8 @@ static TargetInfo *AllocateTarget(const std::string &T) {
     case llvm::Triple::AuroraUX:
       return new AuroraUXTargetInfo<X86_32TargetInfo>(T);
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<X86_32TargetInfo>(T);
+    case llvm::Triple::Hurd:
+      return new GNUOrAndroidEnvironmentTargetInfo<X86_32TargetInfo>(T);
     case llvm::Triple::DragonFly:
       return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
     case llvm::Triple::NetBSD:
@@ -5192,7 +5210,7 @@ static TargetInfo *AllocateTarget(const std::string &T) {
     case llvm::Triple::AuroraUX:
       return new AuroraUXTargetInfo<X86_64TargetInfo>(T);
     case llvm::Triple::Linux:
-      return new LinuxTargetInfo<X86_64TargetInfo>(T);
+      return new GNUOrAndroidEnvironmentTargetInfo<X86_64TargetInfo>(T);
     case llvm::Triple::DragonFly:
       return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T);
     case llvm::Triple::NetBSD:
-- 
1.7.9.5




More information about the cfe-commits mailing list