blob: 698b1bfecc67647002a0889f47eed612b69b42fb [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 Dunbardff9f502009-01-12 18:51:02 +000042 def getMacosxVersionMin(self):
43 major,minor,minorminor = self.darwinVersion
44 return '%d.%d.%d' % (10, major-4, minor)
45
Daniel Dunbar43124722009-01-10 02:07:54 +000046 def selectTool(self, action):
47 assert isinstance(action, Phases.JobAction)
48 return self.toolMap[action.phase.__class__]
49
50class Generic_GCC_ToolChain(ToolChain):
51 """Generic_GCC_ToolChain - A tool chain using the 'gcc' command to
52 perform all subcommands; this relies on gcc translating the
53 options appropriately."""
54
55 def __init__(self, driver):
56 super(Generic_GCC_ToolChain, self).__init__(driver)
57 self.toolMap = {
58 Phases.PreprocessPhase : Tools.GCC_PreprocessTool(),
59 Phases.CompilePhase : Tools.GCC_CompileTool(),
60 Phases.PrecompilePhase : Tools.GCC_PrecompileTool(),
61 Phases.AssemblePhase : Tools.GCC_AssembleTool(),
62 Phases.LinkPhase : Tools.GCC_LinkTool(),
63 }
64
65 def selectTool(self, action):
66 assert isinstance(action, Phases.JobAction)
67 return self.toolMap[action.phase.__class__]