diff --git a/clang/tools/ccc/ccclib/Driver.py b/clang/tools/ccc/ccclib/Driver.py index 392737ff409a..53a4c22dc262 100644 --- a/clang/tools/ccc/ccclib/Driver.py +++ b/clang/tools/ccc/ccclib/Driver.py @@ -92,6 +92,7 @@ class Driver(object): raise ValueError,"Invalid ccc option: %r" % cccPrintOptions self.hostInfo = HostInfo.getHostInfo(self) + self.toolChain = self.hostInfo.getToolChain() args = self.parser.parseArgs(argv) @@ -550,15 +551,6 @@ class Driver(object): if hasNoIntegratedCPP: self.claim(hasNoIntegratedCPP) - toolMap = { - Phases.PreprocessPhase : Tools.GCC_PreprocessTool(), - Phases.CompilePhase : Tools.GCC_CompileTool(), - Phases.PrecompilePhase : Tools.GCC_PrecompileTool(), - Phases.AssemblePhase : Tools.DarwinAssemblerTool(), - Phases.LinkPhase : Tools.Collect2Tool(), - Phases.LipoPhase : Tools.LipoTool(), - } - class InputInfo: def __init__(self, source, type, baseInput): self.source = source @@ -596,7 +588,7 @@ class Driver(object): canAcceptPipe, atTopLevel, phase.arch) assert isinstance(phase, Phases.JobAction) - tool = toolMap[phase.phase.__class__] + tool = self.toolChain.selectTool(phase) # See if we should use an integrated CPP. We only use an # integrated cpp when we have exactly one input, since this is diff --git a/clang/tools/ccc/ccclib/HostInfo.py b/clang/tools/ccc/ccclib/HostInfo.py index 507ac69cd5c5..5f681495e133 100644 --- a/clang/tools/ccc/ccclib/HostInfo.py +++ b/clang/tools/ccc/ccclib/HostInfo.py @@ -1,10 +1,12 @@ +import ToolChain + class HostInfo(object): """HostInfo - Config information about a particular host which may interact with driver behavior. This can be very different from the target(s) of a particular driver invocation.""" - def __init__(self): - pass + def __init__(self, driver): + self.driver = driver def getArchName(self): abstract @@ -18,6 +20,9 @@ class DarwinHostInfo(HostInfo): def useDriverDriver(self): return True + def getToolChain(self): + return ToolChain.Darwin_ToolChain(self.driver) + class DarwinPPCHostInfo(DarwinHostInfo): def getArchName(self): return 'ppc' @@ -39,14 +44,14 @@ def getDarwinHostInfo(driver): bits = driver.getHostBits() if machine == 'i386': if bits == '32': - return DarwinX86HostInfo() + return DarwinX86HostInfo(driver) if bits == '64': - return DarwinX86_64HostInfo() + return DarwinX86_64HostInfo(driver) elif machine == 'ppc': if bits == '32': - return DarwinPPCHostInfo() + return DarwinPPCHostInfo(driver) if bits == '64': - return DarwinPPC_64HostInfo() + return DarwinPPC_64HostInfo(driver) raise RuntimeError,'Unrecognized Darwin platform: %r:%r' % (machine, bits) @@ -59,8 +64,11 @@ class UnknownHostInfo(HostInfo): def useDriverDriver(self): return False + def getToolChain(self): + return ToolChain.Generic_GCC_ToolChain(self.driver) + def getUnknownHostInfo(driver): - return UnknownHostInfo() + return UnknownHostInfo(driver) #### @@ -76,4 +84,4 @@ def getHostInfo(driver): return handler(driver) driver.warning('Unknown host %r, using generic host information.' % system) - return UnknownHostInfo() + return UnknownHostInfo(driver) diff --git a/clang/tools/ccc/ccclib/ToolChain.py b/clang/tools/ccc/ccclib/ToolChain.py new file mode 100644 index 000000000000..46146b5eae42 --- /dev/null +++ b/clang/tools/ccc/ccclib/ToolChain.py @@ -0,0 +1,50 @@ +import Phases +import Tools + +### + +class ToolChain(object): + """ToolChain - Provide mappings of Actions to Tools.""" + + def __init__(self, driver): + self.driver = driver + + def selectTool(self, action): + """selectTool - Return a Tool instance to use for handling + some particular action.""" + abstract + +class Darwin_ToolChain(ToolChain): + def __init__(self, driver): + super(Darwin_ToolChain, self).__init__(driver) + self.toolMap = { + Phases.PreprocessPhase : Tools.GCC_PreprocessTool(), + Phases.CompilePhase : Tools.GCC_CompileTool(), + Phases.PrecompilePhase : Tools.GCC_PrecompileTool(), + Phases.AssemblePhase : Tools.DarwinAssembleTool(), + Phases.LinkPhase : Tools.Collect2Tool(), + Phases.LipoPhase : Tools.LipoTool(), + } + + def selectTool(self, action): + assert isinstance(action, Phases.JobAction) + return self.toolMap[action.phase.__class__] + +class Generic_GCC_ToolChain(ToolChain): + """Generic_GCC_ToolChain - A tool chain using the 'gcc' command to + perform all subcommands; this relies on gcc translating the + options appropriately.""" + + def __init__(self, driver): + super(Generic_GCC_ToolChain, self).__init__(driver) + self.toolMap = { + Phases.PreprocessPhase : Tools.GCC_PreprocessTool(), + Phases.CompilePhase : Tools.GCC_CompileTool(), + Phases.PrecompilePhase : Tools.GCC_PrecompileTool(), + Phases.AssemblePhase : Tools.GCC_AssembleTool(), + Phases.LinkPhase : Tools.GCC_LinkTool(), + } + + def selectTool(self, action): + assert isinstance(action, Phases.JobAction) + return self.toolMap[action.phase.__class__]