Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1 | //===--- 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 | |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame^] | 12 | #include "clang/Driver/Arg.h" |
| 13 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Driver.h" |
| 15 | #include "clang/Driver/HostInfo.h" |
| 16 | |
| 17 | #include "llvm/ADT/StringExtras.h" |
| 18 | #include "llvm/System/Path.h" |
| 19 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 20 | using namespace clang::driver; |
| 21 | using namespace clang::driver::toolchains; |
| 22 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 23 | /// Darwin_X86 - Darwin tool chain for i386 and x86_64. |
| 24 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 25 | Darwin_X86::Darwin_X86(const HostInfo &Host, const char *Arch, |
| 26 | const char *Platform, const char *OS, |
| 27 | const unsigned (&_DarwinVersion)[3], |
| 28 | const unsigned (&_GCCVersion)[3]) |
| 29 | : ToolChain(Host, Arch, Platform, OS) |
| 30 | { |
| 31 | DarwinVersion[0] = _DarwinVersion[0]; |
| 32 | DarwinVersion[1] = _DarwinVersion[1]; |
| 33 | DarwinVersion[2] = _DarwinVersion[2]; |
| 34 | GCCVersion[0] = _GCCVersion[0]; |
| 35 | GCCVersion[1] = _GCCVersion[1]; |
| 36 | GCCVersion[2] = _GCCVersion[2]; |
| 37 | |
| 38 | ToolChainDir = "i686-apple-darwin"; |
| 39 | ToolChainDir += llvm::utostr(DarwinVersion[0]); |
| 40 | ToolChainDir += "/"; |
| 41 | ToolChainDir += llvm::utostr(GCCVersion[0]); |
| 42 | ToolChainDir += '.'; |
| 43 | ToolChainDir += llvm::utostr(GCCVersion[1]); |
| 44 | ToolChainDir += '.'; |
| 45 | ToolChainDir += llvm::utostr(GCCVersion[2]); |
| 46 | |
| 47 | std::string Path; |
| 48 | if (getArchName() == "x86_64") { |
| 49 | Path = getHost().getDriver().Dir; |
| 50 | Path += "/../lib/gcc/"; |
| 51 | Path += getToolChainDir(); |
| 52 | Path += "/x86_64"; |
| 53 | getFilePaths().push_back(Path); |
| 54 | |
| 55 | Path = "/usr/lib/gcc/"; |
| 56 | Path += getToolChainDir(); |
| 57 | Path += "/x86_64"; |
| 58 | getFilePaths().push_back(Path); |
| 59 | } |
| 60 | |
| 61 | Path = getHost().getDriver().Dir; |
| 62 | Path += "/../lib/gcc/"; |
| 63 | Path += getToolChainDir(); |
| 64 | getFilePaths().push_back(Path); |
| 65 | |
| 66 | Path = "/usr/lib/gcc/"; |
| 67 | Path += getToolChainDir(); |
| 68 | getFilePaths().push_back(Path); |
| 69 | |
| 70 | Path = getHost().getDriver().Dir; |
| 71 | Path += "/../libexec/gcc/"; |
| 72 | Path += getToolChainDir(); |
| 73 | getProgramPaths().push_back(Path); |
| 74 | |
| 75 | Path = "/usr/libexec/gcc/"; |
| 76 | Path += getToolChainDir(); |
| 77 | getProgramPaths().push_back(Path); |
| 78 | |
Daniel Dunbar | 82fa7c5 | 2009-03-24 04:07:10 +0000 | [diff] [blame] | 79 | Path = getHost().getDriver().Dir; |
| 80 | Path += "/../libexec"; |
| 81 | getProgramPaths().push_back(Path); |
| 82 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 83 | getProgramPaths().push_back(getHost().getDriver().Dir); |
| 84 | } |
| 85 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 86 | Darwin_X86::~Darwin_X86() { |
| 87 | // Free tool implementations. |
| 88 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 89 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 90 | delete it->second; |
| 91 | } |
| 92 | |
| 93 | Tool &Darwin_X86::SelectTool(const Compilation &C, |
| 94 | const JobAction &JA) const { |
| 95 | Action::ActionClass Key; |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 96 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 97 | Key = Action::AnalyzeJobClass; |
| 98 | else |
| 99 | Key = JA.getKind(); |
| 100 | |
| 101 | Tool *&T = Tools[Key]; |
| 102 | if (!T) { |
| 103 | switch (Key) { |
| 104 | case Action::InputClass: |
| 105 | case Action::BindArchClass: |
| 106 | assert(0 && "Invalid tool kind."); |
| 107 | case Action::PreprocessJobClass: |
| 108 | T = new tools::gcc::Preprocess(*this); break; |
| 109 | case Action::PrecompileJobClass: |
| 110 | T = new tools::gcc::Precompile(*this); break; |
| 111 | case Action::AnalyzeJobClass: |
| 112 | T = new tools::Clang(*this); break; |
| 113 | case Action::CompileJobClass: |
| 114 | T = new tools::gcc::Compile(*this); break; |
| 115 | case Action::AssembleJobClass: |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 116 | T = new tools::darwin::Assemble(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 117 | case Action::LinkJobClass: |
| 118 | T = new tools::gcc::Link(*this); break; |
| 119 | case Action::LipoJobClass: |
| 120 | T = new tools::darwin::Lipo(*this); break; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return *T; |
| 125 | } |
| 126 | |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame^] | 127 | DerivedArgList *Darwin_X86::TranslateArgs(InputArgList &Args) const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 128 | // FIXME: Implement! |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame^] | 129 | return new DerivedArgList(Args, true); |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | bool Darwin_X86::IsMathErrnoDefault() const { |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | bool Darwin_X86::IsUnwindTablesDefault() const { |
| 137 | // FIXME: Gross; we should probably have some separate target |
| 138 | // definition, possibly even reusing the one in clang. |
| 139 | return getArchName() == "x86_64"; |
| 140 | } |
| 141 | |
| 142 | const char *Darwin_X86::GetDefaultRelocationModel() const { |
| 143 | return "pic"; |
| 144 | } |
| 145 | |
| 146 | const char *Darwin_X86::GetForcedPicModel() const { |
| 147 | if (getArchName() == "x86_64") |
| 148 | return "pic"; |
| 149 | return 0; |
| 150 | } |
| 151 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 152 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 153 | /// all subcommands; this relies on gcc translating the majority of |
| 154 | /// command line options. |
| 155 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 156 | Generic_GCC::Generic_GCC(const HostInfo &Host, const char *Arch, |
| 157 | const char *Platform, const char *OS) |
| 158 | : ToolChain(Host, Arch, Platform, OS) |
| 159 | { |
Daniel Dunbar | 82fa7c5 | 2009-03-24 04:07:10 +0000 | [diff] [blame] | 160 | std::string Path(getHost().getDriver().Dir); |
| 161 | Path += "/../libexec"; |
| 162 | getProgramPaths().push_back(Path); |
| 163 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 164 | getProgramPaths().push_back(getHost().getDriver().Dir); |
| 165 | } |
| 166 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 167 | Generic_GCC::~Generic_GCC() { |
| 168 | // Free tool implementations. |
| 169 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 170 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 171 | delete it->second; |
| 172 | } |
| 173 | |
| 174 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
| 175 | const JobAction &JA) const { |
| 176 | Action::ActionClass Key; |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 177 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 178 | Key = Action::AnalyzeJobClass; |
| 179 | else |
| 180 | Key = JA.getKind(); |
| 181 | |
| 182 | Tool *&T = Tools[Key]; |
| 183 | if (!T) { |
| 184 | switch (Key) { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 185 | case Action::InputClass: |
| 186 | case Action::BindArchClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 187 | assert(0 && "Invalid tool kind."); |
| 188 | case Action::PreprocessJobClass: |
| 189 | T = new tools::gcc::Preprocess(*this); break; |
| 190 | case Action::PrecompileJobClass: |
| 191 | T = new tools::gcc::Precompile(*this); break; |
| 192 | case Action::AnalyzeJobClass: |
| 193 | T = new tools::Clang(*this); break; |
| 194 | case Action::CompileJobClass: |
| 195 | T = new tools::gcc::Compile(*this); break; |
| 196 | case Action::AssembleJobClass: |
| 197 | T = new tools::gcc::Assemble(*this); break; |
| 198 | case Action::LinkJobClass: |
| 199 | T = new tools::gcc::Link(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 200 | |
| 201 | // This is a bit ungeneric, but the only platform using a driver |
| 202 | // driver is Darwin. |
| 203 | case Action::LipoJobClass: |
| 204 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
| 208 | return *T; |
| 209 | } |
| 210 | |
| 211 | bool Generic_GCC::IsMathErrnoDefault() const { |
| 212 | return true; |
| 213 | } |
| 214 | |
| 215 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 216 | // FIXME: Gross; we should probably have some separate target |
| 217 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 218 | return getArchName() == "x86_64"; |
| 219 | } |
| 220 | |
| 221 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 222 | return "static"; |
| 223 | } |
| 224 | |
| 225 | const char *Generic_GCC::GetForcedPicModel() const { |
| 226 | return 0; |
| 227 | } |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame^] | 228 | |
| 229 | DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args) const { |
| 230 | return new DerivedArgList(Args, true); |
| 231 | } |