]> granicus.if.org Git - clang/commitdiff
ccc/Driver: .s defaults to 'assembler-with-cpp' on Darwin.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 20 Mar 2009 23:39:23 +0000 (23:39 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 20 Mar 2009 23:39:23 +0000 (23:39 +0000)
 - <rdar://problem/6669441> ccc doesn't handle assembler-with-cpp
   semantics correctly (but clang supports it)

 - This is sad, because it requires a fairly useless target
   hook. C'est la vie.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67418 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/HostInfo.h
lib/Driver/Driver.cpp
lib/Driver/HostInfo.cpp
test/Driver/phases.c
tools/ccc/ccclib/Driver.py
tools/ccc/ccclib/HostInfo.py

index 10ad2f9fe91dd171aaefc53dbc86c4774df9b166..dbfda14ca24aa5475ac8491e357e4850df3c27d4 100644 (file)
@@ -10,6 +10,7 @@
 #ifndef CLANG_DRIVER_HOSTINFO_H_
 #define CLANG_DRIVER_HOSTINFO_H_
 
+#include "clang/Driver/Types.h"
 #include <string>
 
 namespace clang {
@@ -45,6 +46,10 @@ public:
   /// driver for this host and support -arch, -Xarch, etc.
   virtual bool useDriverDriver() const = 0;
 
+  /// lookupTypeForExtension - Return the default language type to use
+  /// for the given extension.
+  virtual types::ID lookupTypeForExtension(const char *Ext) const = 0;
+
   /// getToolChain - Construct the toolchain to use for this host.
   ///
   /// \param Args - The argument list, which may be used to alter the
index 2c324010dac294f89a94816b839c82531975e51c..40c6e5006368e928c137634e3ff59daa9872f1a6 100644 (file)
@@ -445,9 +445,11 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
           Ty = types::TY_C;
         } else {
           // Otherwise lookup by extension, and fallback to ObjectType
-          // if not found.
+          // if not found. We use a host hook here because Darwin at
+          // least has its own idea of what .s is.
           if (const char *Ext = strrchr(Value, '.'))
-            Ty = types::lookupTypeForExtension(Ext + 1);
+            Ty = Host->lookupTypeForExtension(Ext + 1);
+
           if (Ty == types::TY_INVALID)
             Ty = types::TY_Object;
         }
index 39a688a4f5cdf67a49b1b5002e2c5701b2643d73..8c24a3c707b830ac5351536ef8b72f75b370974e 100644 (file)
@@ -57,6 +57,17 @@ public:
 
   virtual bool useDriverDriver() const;
 
+  virtual types::ID lookupTypeForExtension(const char *Ext) const {
+    types::ID Ty = types::lookupTypeForExtension(Ext);
+
+    // Darwin always preprocesses assembly files (unless -x is used
+    // explicitly).
+    if (Ty == types::TY_PP_Asm)
+      return types::TY_Asm;
+
+    return Ty;
+  }
+
   virtual ToolChain *getToolChain(const ArgList &Args, 
                                   const char *ArchName) const;
 };
@@ -173,6 +184,10 @@ public:
 
   virtual bool useDriverDriver() const;
 
+  virtual types::ID lookupTypeForExtension(const char *Ext) const {
+    return types::lookupTypeForExtension(Ext);
+  }
+
   virtual ToolChain *getToolChain(const ArgList &Args, 
                                   const char *ArchName) const;
 };
index f55cbc6755c1b490587b8593571211a8ef62c1c1..1466d7c3e2872a10365ca3ab2d3cceffc9fcd238 100644 (file)
 // RUN: grep -F '1: preprocessor, {0}, c-header-cpp-output' %t &&
 // RUN: grep -F '2: precompiler, {1}, precompiled-header' %t &&
 
+// Darwin overrides the handling for .s
+// RUN: touch %t.s &&
+// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-phases -c %t.s &> %t &&
+// RUN: grep '0: input, ".*\.s", assembler' %t &&
+// RUN: grep -F '1: assembler, {0}, object' %t &&
+// RUN: clang-driver -ccc-host-triple i386-apple-darwin9 -ccc-print-phases -c %t.s &> %t &&
+// RUN: grep '0: input, ".*\.s", assembler-with-cpp' %t &&
+// RUN: grep -F '1: preprocessor, {0}, assembler' %t &&
+// RUN: grep -F '2: assembler, {1}, object' %t &&
+
 // RUN: true
index 5c978e26383617342ba73e7a3a50115513c235c1..92f7c87ca0a1cc5da56590a3c3d4417bb39eccb4 100644 (file)
@@ -426,7 +426,7 @@ class Driver(object):
                         else:
                             raise Arguments.InvalidArgumentsError("-E or -x required when input is from standard input")
                     elif ext and ext in Types.kTypeSuffixMap:
-                        klass = Types.kTypeSuffixMap[ext]
+                        klass = self.hostInfo.lookupTypeForExtension(ext)
                     else:
                         # FIXME: Its not clear why we shouldn't just
                         # revert to unknown. I think this is more likely a
index 9f61b87502d7990b95bdbf766f3640f0cebf122f..c40a4f7c4d2f37243d0e665b98ec4da11daf331f 100644 (file)
@@ -1,4 +1,5 @@
 import ToolChain
+import Types
 
 class HostInfo(object):
     """HostInfo - Config information about a particular host which may
@@ -14,6 +15,9 @@ class HostInfo(object):
     def useDriverDriver(self):
         abstract
 
+    def lookupTypeForExtension(self, ext):
+        abstract
+
     def getToolChain(self):
         abstract
 
@@ -37,6 +41,12 @@ class DarwinHostInfo(HostInfo):
     def useDriverDriver(self):
         return True
 
+    def lookupTypeForExtension(self, ext):
+        ty = Types.kTypeSuffixMap.get(ext)
+        if ty is Types.AsmTypeNoPP:
+            return Types.AsmType
+        return ty
+
     def getToolChain(self):
         return self.getToolChainForArch(self.getArchName(None))
 
@@ -98,6 +108,9 @@ class UnknownHostInfo(HostInfo):
     def useDriverDriver(self):
         return False
 
+    def lookupTypeForExtension(self, ext):
+        return Types.kTypeSuffixMap.get(ext)
+
     def getToolChain(self):
         return ToolChain.Generic_GCC_ToolChain(self.driver, '')