ccc: Embrace destiny as a clang compiler driver.
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
diff --git a/tools/ccc/ccclib/ToolChain.py b/tools/ccc/ccclib/ToolChain.py
index 73b0127e..6ce6ebc 100644
--- a/tools/ccc/ccclib/ToolChain.py
+++ b/tools/ccc/ccclib/ToolChain.py
@@ -54,6 +54,28 @@
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 @@
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 @@
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__]