]> granicus.if.org Git - clang/commitdiff
ccc: Embrace destiny as a clang compiler driver.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 29 Jan 2009 23:54:06 +0000 (23:54 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 29 Jan 2009 23:54:06 +0000 (23:54 +0000)
This redoes the default mode that ccc runs in w.r.t. using clang. Now
ccc defaults to always using clang for any task clang can
handle. However, the following options exist to tweak this behavior:

 -ccc-no-clang: Don't use clang at all for compilation (still used for
  static analysis).

 -ccc-no-clang-cxx: Don't use clang for C++ and Objective-C++ inputs.

 -ccc-no-clang-cpp: Don't use clang as a preprocessor.

 -ccc-clang-archs <archs>: If present, only use clang for the given
  comma separated list of architectures. This only works on Darwin for
  now.

Note that all -ccc options must be first on the command line.

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

tools/ccc/ccclib/Driver.py
tools/ccc/ccclib/ToolChain.py
tools/ccc/ccclib/Tools.py
tools/ccc/ccclib/Types.py
tools/ccc/test/ccc/Xarch.c
tools/ccc/test/ccc/aliases.c
tools/ccc/test/ccc/darwin-hello.m
tools/ccc/test/ccc/darwin-x86-cc1.m
tools/ccc/test/ccc/hello.c
tools/ccc/test/ccc/hello.m
tools/ccc/test/ccc/universal-hello.c

index 6749dae13293d98d344046c6bf86beb613e565cd..bdcdcb731cfe9a269b96632824dcb56f969f40f5 100644 (file)
@@ -28,9 +28,10 @@ class Driver(object):
         self.cccHostBits = self.cccHostMachine = None
         self.cccHostSystem = self.cccHostRelease = None
         self.cccCXX = False
-        self.cccClang = False
         self.cccEcho = False
         self.cccFallback = False
+        self.cccNoClang = self.cccNoClangCXX = self.cccNoClangPreprocessor = False
+        self.cccClangArchs = None
 
         # Certain options suppress the 'no input files' warning.
         self.suppressMissingInputWarning = False
@@ -115,12 +116,10 @@ class Driver(object):
 
         # FIXME: How to handle override of host? ccc specific options?
         # Abuse -b?
-        if self.getenvBool('CCC_CLANG'):
-            self.cccClang = True
-        if self.getenvBool('CCC_ECHO'):
-            self.cccEcho = True
-        if self.getenvBool('CCC_FALLBACK'):
-            self.cccFallback = True
+        arg = os.getenv('CCC_ADD_ARGS')
+        if arg:
+            args = filter(None, map(str.strip, arg.split(',')))
+            argv = args + argv
 
         while argv and argv[0].startswith('-ccc-'):
             fullOpt,argv = argv[0],argv[1:]
@@ -132,12 +131,20 @@ class Driver(object):
                 cccPrintPhases = True
             elif opt == 'cxx':
                 self.cccCXX = True
-            elif opt == 'clang':
-                self.cccClang = True
             elif opt == 'echo':
                 self.cccEcho = True
             elif opt == 'fallback':
                 self.cccFallback = True
+
+            elif opt == 'no-clang':
+                self.cccNoClang = True
+            elif opt == 'no-clang-cxx':
+                self.cccNoClangCXX = True
+            elif opt == 'no-clang-cpp':
+                self.cccNoClangPreprocessor = True
+            elif opt == 'clang-archs':
+                self.cccClangArchs,argv = argv[0].split(','),argv[1:]
+
             elif opt == 'host-bits':
                 self.cccHostBits,argv = argv[0],argv[1:]
             elif opt == 'host-machine':
index 73b0127e1448f7f77fece25019a70c1b12d81d4a..6ce6ebc341fa1de5a474af8785df75a01d85149e 100644 (file)
@@ -54,6 +54,28 @@ class ToolChain(object):
         else:
             return args
 
+    def shouldUseClangCompiler(self, action):
+        # If user requested no clang, or this isn't a "compile" phase,
+        # or this isn't a C family option, then don't use clang.
+        if (self.driver.cccNoClang or 
+            not isinstance(action.phase, (Phases.PreprocessPhase,
+                                          Phases.CompilePhase,
+                                          Phases.SyntaxOnlyPhase,
+                                          Phases.EmitLLVMPhase,
+                                          Phases.PrecompilePhase)) or
+            action.inputs[0].type not in Types.cTypesSet):
+            return False
+
+        if self.driver.cccNoClangPreprocessor:
+            if isinstance(action.phase, Phases.PreprocessPhase):
+                return False
+
+        if self.driver.cccNoClangCXX:
+            if action.inputs[0].type in Types.cxxTypesSet:
+                return False
+
+        return True
+        
 class Darwin_X86_ToolChain(ToolChain):
     def __init__(self, driver, darwinVersion, gccVersion, archName):
         super(Darwin_X86_ToolChain, self).__init__(driver)
@@ -106,20 +128,23 @@ class Darwin_X86_ToolChain(ToolChain):
         major,minor,minorminor = self.darwinVersion
         return '%d.%d.%d' % (10, major-4, minor)
 
+    def shouldUseClangCompiler(self, action):
+        if not super(Darwin_X86_ToolChain, self).shouldUseClangCompiler(action):
+            return False
+        
+        # Only use clang if user didn't override archs, or this is one
+        # of the ones they provided.
+        if (not self.driver.cccClangArchs or 
+            self.archName in self.driver.cccClangArchs):
+            return True
+        
+        return False
+
     def selectTool(self, action):
         assert isinstance(action, Phases.JobAction)
         
-        if self.driver.cccClang and self.archName == 'i386':
-            if (action.inputs[0].type in (Types.CType, Types.CTypeNoPP,
-                                          Types.ObjCType, Types.ObjCTypeNoPP) and
-                (isinstance(action.phase, Phases.CompilePhase) or
-                 isinstance(action.phase, Phases.SyntaxOnlyPhase) or
-                 isinstance(action.phase, Phases.EmitLLVMPhase))):
-                return self.clangTool
-            elif (action.inputs[0].type in (Types.CHeaderType, Types.CHeaderNoPPType,
-                                            Types.ObjCHeaderType, Types.ObjCHeaderNoPPType) and
-                  isinstance(action.phase, Phases.PrecompilePhase)):
-                return self.clangTool
+        if self.shouldUseClangCompiler(action):
+            return self.clangTool
 
         return self.toolMap[action.phase.__class__]
 
@@ -220,17 +245,7 @@ class Generic_GCC_ToolChain(ToolChain):
     def selectTool(self, action):
         assert isinstance(action, Phases.JobAction)
 
-        if self.driver.cccClang:
-            if (action.inputs[0].type in (Types.CType, Types.CTypeNoPP,
-                                          Types.ObjCType, Types.ObjCTypeNoPP) and
-                (isinstance(action.phase, Phases.PreprocessPhase) or
-                 isinstance(action.phase, Phases.CompilePhase) or
-                 isinstance(action.phase, Phases.SyntaxOnlyPhase) or
-                 isinstance(action.phase, Phases.EmitLLVMPhase))):
-                return self.clangTool
-            elif (action.inputs[0].type in (Types.CHeaderType, Types.CHeaderNoPPType,
-                                            Types.ObjCHeaderType, Types.ObjCHeaderNoPPType) and
-                  isinstance(action.phase, Phases.PrecompilePhase)):
-                return self.clangTool
+        if self.shouldUseClangCompiler(action):
+            return self.clangTool
 
         return self.toolMap[action.phase.__class__]
index a24255c652f63fc4520263f66279d2c326d52add..61d6a24d34296c7725df1892963eb57fa12714d6 100644 (file)
@@ -190,6 +190,9 @@ class Clang_CompileTool(Tool):
             cmd_args.append('-emit-llvm-bc')
         elif outputType is Types.AsmTypeNoPP:
             cmd_args.append('-S')
+        elif (inputs[0].type.preprocess and 
+              outputType is inputs[0].type.preprocess):
+            cmd_args.append('-E')
         elif outputType is Types.PCHType:
             # No special option needed, driven by -x. However, we
             # patch the output name to try and not conflict with gcc.
index 4af076791446a3eb1b2a2c6fdf42d8c5bfe2817f..1dd3ed90118bff36ac166dbc46df8ba6e9f75c78 100644 (file)
@@ -146,6 +146,22 @@ kTypeSpecifierMap = {
     'treelang' : TreelangType,
 }
 
+# Set of C family types.
+cTypesSet = set([CType, CTypeNoPP, 
+                 ObjCType, ObjCTypeNoPP,
+                 CXXType, CXXTypeNoPP,
+                 ObjCXXType, ObjCXXTypeNoPP,
+                 CHeaderType, CHeaderNoPPType,
+                 ObjCHeaderType, ObjCHeaderNoPPType,
+                 CXXHeaderType, CXXHeaderNoPPType,
+                 ObjCXXHeaderType, ObjCXXHeaderNoPPType])
+
+# Set of C++ family types.
+cxxTypesSet = set([CXXType, CXXTypeNoPP,
+                   ObjCXXType, ObjCXXTypeNoPP,
+                   CXXHeaderType, CXXHeaderNoPPType,
+                   ObjCXXHeaderType, ObjCXXHeaderNoPPType])
+
 # Check that the type specifier map at least matches what the types
 # believe to be true.
 assert not [name for name,type in kTypeSpecifierMap.items()
index 0c0eee0121941ce625becec70fac0b874a7de888..5c3a1f954dbb5de8788d1b221078259a900665a3 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: xcc -### -fsyntax-only -Xarch_i386 -Wall -Xarch_ppc -Wunused -arch i386 -arch ppc %s &> %t &&
+// RUN: xcc -ccc-no-clang -### -fsyntax-only -Xarch_i386 -Wall -Xarch_ppc -Wunused -arch i386 -arch ppc %s &> %t &&
 // RUN: grep '"-Xarch"' %t | count 0 &&
 // RUN: grep '"-Wall"' %t | count 1 &&
 // RUN: grep 'i686-apple' %t | grep -v '"-m64"' | count 1 &&
index f9b89a14d4b9ff8b7309618eaa738ebce561d918..101c4e7a255ef9b8cd1cdc35b52dd7d7fa4f5d6f 100644 (file)
@@ -1,13 +1,13 @@
-// RUN: xcc -### -S --all-warnings %s &> %t &&
+// RUN: xcc -ccc-no-clang -### -S --all-warnings %s &> %t &&
 // RUN: grep -- '"-Wall"' %t &&
 
-// RUN: xcc -### -S --ansi %s &> %t &&
+// RUN: xcc -ccc-no-clang -### -S --ansi %s &> %t &&
 // RUN: grep -- '"-ansi"' %t &&
 
-// RUN: xcc -### -S --assert foo --assert=foo %s &> %t &&
+// RUN: xcc -ccc-no-clang -### -S --assert foo --assert=foo %s &> %t &&
 // RUN: grep -- '"-A" "foo" "-A" "foo"' %t &&
 
-// RUN: xcc -### -S --classpath foo --classpath=foo %s &> %t &&
+// RUN: xcc -ccc-no-clang -### -S --classpath foo --classpath=foo %s &> %t &&
 // RUN: grep -- '"-fclasspath=foo" "-fclasspath=foo"' %t &&
 
 // RUN: true
index 73289e99cf89a6dca493c304b3d802e111dc9abe..51dea654dcbf12d6606ef59f808cf8dab2a2f2e1 100644 (file)
@@ -1,11 +1,11 @@
 // Check that object files compiled with -mdynamic-no-pic can be
 // linked.
 // 
-// RUN: xcc -ccc-clang -m32 -mdynamic-no-pic %s -c -o %t.o &&
-// RUN: xcc -ccc-clang -m32 %t.o -o %t &&
+// RUN: xcc -m32 -mdynamic-no-pic %s -c -o %t.o &&
+// RUN: xcc -m32 %t.o -o %t &&
 // RUN: %t | grep "Hello, World" &&
-// RUN: xcc -ccc-clang -m64 -mdynamic-no-pic %s -c -o %t.o &&
-// RUN: xcc -ccc-clang -m64 %t.o -o %t &&
+// RUN: xcc -m64 -mdynamic-no-pic %s -c -o %t.o &&
+// RUN: xcc -m64 %t.o -o %t &&
 // RUN: %t | grep "Hello, World" &&
 // RUN: true
 
index 6c097d3a744d4629099fec69e71437ef93ad0e0a..d00f85554fe42729cffe97d44daf87470b20c8aa 100644 (file)
@@ -1,14 +1,14 @@
-// RUN: xcc -ccc-host-bits 32 -ccc-host-machine i386 -ccc-host-system darwin -ccc-host-release 10.5.0 -### -x objective-c -arch i386 -fmessage-length=0 -Wno-trigraphs -fpascal-strings -fasm-blocks -Os -mdynamic-no-pic -DUSER_DEFINE_0 -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2 -IINCLUDE_PATH_0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wno-four-char-constants -Wno-unknown-pragmas -Wno-format-y2k -Wpointer-arith -Wreturn-type -Wwrite-strings -Wswitch -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wint-to-pointer-cast -Wpointer-to-int-cast -Wshorten-64-to-32 -FFRAMEWORK_0 -IINCLUDE_PATH_1 -FFRAMEWORK_1 -include USER_INCLUDE_0 -c %s -o %t.out &> %t.opts &&
+// RUN: xcc -ccc-no-clang -ccc-host-bits 32 -ccc-host-machine i386 -ccc-host-system darwin -ccc-host-release 10.5.0 -### -x objective-c -arch i386 -fmessage-length=0 -Wno-trigraphs -fpascal-strings -fasm-blocks -Os -mdynamic-no-pic -DUSER_DEFINE_0 -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2 -IINCLUDE_PATH_0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wno-four-char-constants -Wno-unknown-pragmas -Wno-format-y2k -Wpointer-arith -Wreturn-type -Wwrite-strings -Wswitch -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wint-to-pointer-cast -Wpointer-to-int-cast -Wshorten-64-to-32 -FFRAMEWORK_0 -IINCLUDE_PATH_1 -FFRAMEWORK_1 -include USER_INCLUDE_0 -c %s -o %t.out &> %t.opts &&
 // RUN: grep ' "/usr/libexec/gcc/i686-apple-darwin10/4.2.1/cc1obj" "-quiet" "-IINCLUDE_PATH_0" "-FFRAMEWORK_0" "-IINCLUDE_PATH_1" "-FFRAMEWORK_1" "-D__DYNAMIC__" "-DUSER_DEFINE_0" "-include" "USER_INCLUDE_0" ".*" "-quiet" "-dumpbase" "darwin-x86-cc1.m" "-mpascal-strings" "-mdynamic-no-pic" "-mmacosx-version-min=10.5" "-mtune=core2" "-auxbase-strip" ".*" "-gdwarf-2" "-Os" "-Wno-trigraphs" "-Wall" "-Wextra" "-Wno-missing-field-initializers" "-Wno-unused-parameter" "-Wno-four-char-constants" "-Wno-unknown-pragmas" "-Wno-format-y2k" "-Wpointer-arith" "-Wreturn-type" "-Wwrite-strings" "-Wswitch" "-Wcast-align" "-Wchar-subscripts" "-Winline" "-Wnested-externs" "-Wint-to-pointer-cast" "-Wpointer-to-int-cast" "-Wshorten-64-to-32" "-fmessage-length=0" "-fasm-blocks" "-fvisibility=hidden" "-o"' %t.opts &&
 // RUN: grep ' "/usr/libexec/gcc/i686-apple-darwin10/4.2.1/as" "-arch" "i386" "-force_cpusubtype_ALL" "-o"' %t.opts &&
 
-// RUN: xcc -ccc-host-bits 32 -ccc-host-machine i386 -ccc-host-system darwin -ccc-host-release 10.5.0 -### -v -E -dM -arch i386 -xobjective-c -c %s &> %t.opts &&
+// RUN: xcc -ccc-no-clang -ccc-host-bits 32 -ccc-host-machine i386 -ccc-host-system darwin -ccc-host-release 10.5.0 -### -v -E -dM -arch i386 -xobjective-c -c %s &> %t.opts &&
 // RUN: grep ' "/usr/libexec/gcc/i686-apple-darwin10/4.2.1/cc1obj" "-E" "-quiet" "-v" "-D__DYNAMIC__" ".*" "-fPIC" "-mmacosx-version-min=10.6.5" "-mtune=core2" "-dM"' %t.opts && 
 
-// RUN: xcc -ccc-host-bits 32 -ccc-host-machine i386 -ccc-host-system darwin -ccc-host-release 10.5.0 -### -m32 -S -x cpp-output %s &> %t.opts &&
+// RUN: xcc -ccc-no-clang -ccc-host-bits 32 -ccc-host-machine i386 -ccc-host-system darwin -ccc-host-release 10.5.0 -### -m32 -S -x cpp-output %s &> %t.opts &&
 // RUN: grep ' "/usr/libexec/gcc/i686-apple-darwin10/4.2.1/cc1" "-fpreprocessed" ".*darwin-x86-cc1.m" "-fPIC" "-quiet" "-dumpbase" "darwin-x86-cc1.m" "-mmacosx-version-min=10.6.5" "-m32" "-mtune=core2" "-auxbase" "darwin-x86-cc1" "-o" ".*"' %t.opts &&
 
-// RUN: xcc -ccc-host-bits 32 -ccc-host-machine i386 -ccc-host-system darwin -ccc-host-release 10.5.0 -### -x objective-c-header %s -o /tmp/x.gch &> %t.opts &&
+// RUN: xcc -ccc-no-clang -ccc-host-bits 32 -ccc-host-machine i386 -ccc-host-system darwin -ccc-host-release 10.5.0 -### -x objective-c-header %s -o /tmp/x.gch &> %t.opts &&
 // RUN: grep ' "/usr/libexec/gcc/i686-apple-darwin10/4.2.1/cc1obj" "-quiet" "-D__DYNAMIC__" ".*darwin-x86-cc1.m" "-fPIC" "-quiet" "-dumpbase" "darwin-x86-cc1.m" "-mmacosx-version-min=10.6.5" "-mtune=core2" "-auxbase" ".*" "-o" "/dev/null" "--output-pch=" "/tmp/x.gch"' %t.opts &&
 
 // RUN: true
index 6b857b519a4bf4b5040b1fc1095186dd49a4f66e..120db1a63038fa062fef3b6c9753406e7c360f7d 100644 (file)
@@ -1,8 +1,8 @@
-// RUN: xcc %s -o %t &&
+// RUN: xcc -ccc-no-clang %s -o %t &&
 // RUN: %t | grep "Hello, World" &&
-// RUN: xcc %s -o %t -pipe &&
+// RUN: xcc -ccc-no-clang %s -o %t -pipe &&
 // RUN: %t | grep "Hello, World" &&
-// RUN: xcc -ccc-clang %s -o %t &&
+// RUN: xcc %s -o %t &&
 // RUN: %t | grep "Hello, World"
 
 int main() {
index 9563fd04fe01ac613f1de3acfeda8ce8fcb21a94..b1bcaeb2516e5e86a5f89384147d4719bee84502 100644 (file)
@@ -1,6 +1,6 @@
-// RUN: xcc %s -o %t &&
+// RUN: xcc -ccc-no-clang %s -o %t &&
 // RUN: %t | grep "Hello, World" &&
-// RUN: xcc -ccc-clang %s -o %t &&
+// RUN: xcc %s -o %t &&
 // RUN: %t | grep "Hello, World"
 
 int main() {
index 7702b38229c2dc91458a548bedf2fbece0d883a0..654c43507a1f20477786db40de0384ad8265511b 100644 (file)
@@ -1,7 +1,7 @@
-// RUN: xcc -arch ppc -arch i386 -arch x86_64 %s -o %t &&
+// RUN: xcc -ccc-no-clang -arch ppc -arch i386 -arch x86_64 %s -o %t &&
 // RUN: %t | grep "Hello, World" &&
 
-// RUN: xcc -pipe -arch ppc -arch i386 -arch x86_64 %s -o %t &&
+// RUN: xcc -ccc-no-clang -pipe -arch ppc -arch i386 -arch x86_64 %s -o %t &&
 // RUN: %t | grep "Hello, World" &&
 
 // Check that multiple archs are handled properly.