[cfe-commits] r62021 - in /cfe/trunk/tools/ccc/ccclib: Driver.py HostInfo.py ToolChain.py
Daniel Dunbar
daniel at zuster.org
Fri Jan 9 18:07:54 PST 2009
Author: ddunbar
Date: Fri Jan 9 20:07:54 2009
New Revision: 62021
URL: http://llvm.org/viewvc/llvm-project?rev=62021&view=rev
Log:
ccc: Introduce ToolChains for mapping Actions to Tools which can
perform them.
- A ToolChain is a coherent set of tools use in a compilation
process. The idea is that a ToolChain holds roughly the information
(specs, search paths, etc.) that is in a single gcc binary.
- The default ToolChain is selected by the host and will generally
correspond to what the default system compiler would do. However,
this can be over-riden for a variety of purposes, for example the
by the driver driver or for testing.
Added:
cfe/trunk/tools/ccc/ccclib/ToolChain.py
Modified:
cfe/trunk/tools/ccc/ccclib/Driver.py
cfe/trunk/tools/ccc/ccclib/HostInfo.py
Modified: cfe/trunk/tools/ccc/ccclib/Driver.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/ccc/ccclib/Driver.py?rev=62021&r1=62020&r2=62021&view=diff
==============================================================================
--- cfe/trunk/tools/ccc/ccclib/Driver.py (original)
+++ cfe/trunk/tools/ccc/ccclib/Driver.py Fri Jan 9 20:07:54 2009
@@ -92,6 +92,7 @@
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 @@
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 @@
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
Modified: cfe/trunk/tools/ccc/ccclib/HostInfo.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/ccc/ccclib/HostInfo.py?rev=62021&r1=62020&r2=62021&view=diff
==============================================================================
--- cfe/trunk/tools/ccc/ccclib/HostInfo.py (original)
+++ cfe/trunk/tools/ccc/ccclib/HostInfo.py Fri Jan 9 20:07:54 2009
@@ -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 @@
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 @@
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 @@
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 @@
return handler(driver)
driver.warning('Unknown host %r, using generic host information.' % system)
- return UnknownHostInfo()
+ return UnknownHostInfo(driver)
Added: cfe/trunk/tools/ccc/ccclib/ToolChain.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/ccc/ccclib/ToolChain.py?rev=62021&view=auto
==============================================================================
--- cfe/trunk/tools/ccc/ccclib/ToolChain.py (added)
+++ cfe/trunk/tools/ccc/ccclib/ToolChain.py Fri Jan 9 20:07:54 2009
@@ -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__]
More information about the cfe-commits
mailing list