blob: 3165a8f395e10cdc23a49461eaeb1f1dcb1bf686 [file] [log] [blame]
Daniel Dunbar39176082009-03-20 00:20:03 +00001//===--- ToolChains.cpp - ToolChain Implementations ---------------------*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "ToolChains.h"
11
12using namespace clang::driver;
13using namespace clang::driver::toolchains;
14
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000015/// Darwin_X86 - Darwin tool chain for i386 and x86_64.
16
17Darwin_X86::~Darwin_X86() {
18 // Free tool implementations.
19 for (llvm::DenseMap<unsigned, Tool*>::iterator
20 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
21 delete it->second;
22}
23
24Tool &Darwin_X86::SelectTool(const Compilation &C,
25 const JobAction &JA) const {
26 Action::ActionClass Key;
27 if (ShouldUseClangCompiler(C, JA))
28 Key = Action::AnalyzeJobClass;
29 else
30 Key = JA.getKind();
31
32 Tool *&T = Tools[Key];
33 if (!T) {
34 switch (Key) {
35 case Action::InputClass:
36 case Action::BindArchClass:
37 assert(0 && "Invalid tool kind.");
38 case Action::PreprocessJobClass:
39 T = new tools::gcc::Preprocess(*this); break;
40 case Action::PrecompileJobClass:
41 T = new tools::gcc::Precompile(*this); break;
42 case Action::AnalyzeJobClass:
43 T = new tools::Clang(*this); break;
44 case Action::CompileJobClass:
45 T = new tools::gcc::Compile(*this); break;
46 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +000047 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000048 case Action::LinkJobClass:
49 T = new tools::gcc::Link(*this); break;
50 case Action::LipoJobClass:
51 T = new tools::darwin::Lipo(*this); break;
52 }
53 }
54
55 return *T;
56}
57
58ArgList *Darwin_X86::TranslateArgs(ArgList &Args) const {
59 // FIXME: Implement!
60 return &Args;
61}
62
63bool Darwin_X86::IsMathErrnoDefault() const {
64 return false;
65}
66
67bool Darwin_X86::IsUnwindTablesDefault() const {
68 // FIXME: Gross; we should probably have some separate target
69 // definition, possibly even reusing the one in clang.
70 return getArchName() == "x86_64";
71}
72
73const char *Darwin_X86::GetDefaultRelocationModel() const {
74 return "pic";
75}
76
77const char *Darwin_X86::GetForcedPicModel() const {
78 if (getArchName() == "x86_64")
79 return "pic";
80 return 0;
81}
82
Daniel Dunbar39176082009-03-20 00:20:03 +000083/// Generic_GCC - A tool chain using the 'gcc' command to perform
84/// all subcommands; this relies on gcc translating the majority of
85/// command line options.
86
87Generic_GCC::~Generic_GCC() {
88 // Free tool implementations.
89 for (llvm::DenseMap<unsigned, Tool*>::iterator
90 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
91 delete it->second;
92}
93
94Tool &Generic_GCC::SelectTool(const Compilation &C,
95 const JobAction &JA) const {
96 Action::ActionClass Key;
97 if (ShouldUseClangCompiler(C, JA))
98 Key = Action::AnalyzeJobClass;
99 else
100 Key = JA.getKind();
101
102 Tool *&T = Tools[Key];
103 if (!T) {
104 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000105 case Action::InputClass:
106 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000107 assert(0 && "Invalid tool kind.");
108 case Action::PreprocessJobClass:
109 T = new tools::gcc::Preprocess(*this); break;
110 case Action::PrecompileJobClass:
111 T = new tools::gcc::Precompile(*this); break;
112 case Action::AnalyzeJobClass:
113 T = new tools::Clang(*this); break;
114 case Action::CompileJobClass:
115 T = new tools::gcc::Compile(*this); break;
116 case Action::AssembleJobClass:
117 T = new tools::gcc::Assemble(*this); break;
118 case Action::LinkJobClass:
119 T = new tools::gcc::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000120
121 // This is a bit ungeneric, but the only platform using a driver
122 // driver is Darwin.
123 case Action::LipoJobClass:
124 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000125 }
126 }
127
128 return *T;
129}
130
131bool Generic_GCC::IsMathErrnoDefault() const {
132 return true;
133}
134
135bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000136 // FIXME: Gross; we should probably have some separate target
137 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000138 return getArchName() == "x86_64";
139}
140
141const char *Generic_GCC::GetDefaultRelocationModel() const {
142 return "static";
143}
144
145const char *Generic_GCC::GetForcedPicModel() const {
146 return 0;
147}