mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-12 18:02:43 +00:00
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. llvm-svn: 62021
This commit is contained in:
parent
eacf5b174d
commit
cb8d7e131c
@ -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
|
||||
|
@ -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)
|
||||
|
50
clang/tools/ccc/ccclib/ToolChain.py
Normal file
50
clang/tools/ccc/ccclib/ToolChain.py
Normal file
@ -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__]
|
Loading…
Reference in New Issue
Block a user