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