blob: 2447b67052564ef234befba0a4cc80e2284bcfe1 [file] [log] [blame]
Daniel Dunbar43124722009-01-10 02:07:54 +00001import Phases
2import Tools
3
4###
5
6class ToolChain(object):
7 """ToolChain - Provide mappings of Actions to Tools."""
8
9 def __init__(self, driver):
10 self.driver = driver
11
12 def selectTool(self, action):
13 """selectTool - Return a Tool instance to use for handling
14 some particular action."""
15 abstract
16
Daniel Dunbar9c257c32009-01-12 04:21:12 +000017class Darwin_X86_ToolChain(ToolChain):
18 def __init__(self, driver, darwinVersion, gccVersion):
19 super(Darwin_X86_ToolChain, self).__init__(driver)
Daniel Dunbar9cb22532009-01-12 07:45:49 +000020 assert isinstance(darwinVersion, tuple) and len(darwinVersion) == 3
21 assert isinstance(gccVersion, tuple) and len(gccVersion) == 3
22 self.darwinVersion = darwinVersion
23 self.gccVersion = gccVersion
24
Daniel Dunbar43124722009-01-10 02:07:54 +000025 self.toolMap = {
26 Phases.PreprocessPhase : Tools.GCC_PreprocessTool(),
27 Phases.CompilePhase : Tools.GCC_CompileTool(),
28 Phases.PrecompilePhase : Tools.GCC_PrecompileTool(),
Daniel Dunbar9cb22532009-01-12 07:45:49 +000029 Phases.AssemblePhase : Tools.Darwin_AssembleTool(self),
30 Phases.LinkPhase : Tools.Darwin_X86_LinkTool(self),
Daniel Dunbar43124722009-01-10 02:07:54 +000031 Phases.LipoPhase : Tools.LipoTool(),
32 }
33
Daniel Dunbar9cb22532009-01-12 07:45:49 +000034 def getToolChainDir(self):
35 return 'i686-apple-darwin%d/%s' % (self.darwinVersion[0],
36 '.'.join(map(str,self.gccVersion)))
37
38 def getProgramPath(self, name):
39 # FIXME: Implement proper search.
40 return '/usr/libexec/gcc/%s/%s' % (self.getToolChainDir(), name)
41
Daniel Dunbar43124722009-01-10 02:07:54 +000042 def selectTool(self, action):
43 assert isinstance(action, Phases.JobAction)
44 return self.toolMap[action.phase.__class__]
45
46class Generic_GCC_ToolChain(ToolChain):
47 """Generic_GCC_ToolChain - A tool chain using the 'gcc' command to
48 perform all subcommands; this relies on gcc translating the
49 options appropriately."""
50
51 def __init__(self, driver):
52 super(Generic_GCC_ToolChain, self).__init__(driver)
53 self.toolMap = {
54 Phases.PreprocessPhase : Tools.GCC_PreprocessTool(),
55 Phases.CompilePhase : Tools.GCC_CompileTool(),
56 Phases.PrecompilePhase : Tools.GCC_PrecompileTool(),
57 Phases.AssemblePhase : Tools.GCC_AssembleTool(),
58 Phases.LinkPhase : Tools.GCC_LinkTool(),
59 }
60
61 def selectTool(self, action):
62 assert isinstance(action, Phases.JobAction)
63 return self.toolMap[action.phase.__class__]