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" |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 15 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 16 | #include "clang/Driver/HostInfo.h" |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Option.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 18 | |
| 19 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 21 | #include "llvm/System/Path.h" |
| 22 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 23 | using namespace clang::driver; |
| 24 | using namespace clang::driver::toolchains; |
| 25 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 26 | /// Darwin_X86 - Darwin tool chain for i386 and x86_64. |
| 27 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 28 | Darwin_X86::Darwin_X86(const HostInfo &Host, const char *Arch, |
| 29 | const char *Platform, const char *OS, |
| 30 | const unsigned (&_DarwinVersion)[3], |
| 31 | const unsigned (&_GCCVersion)[3]) |
| 32 | : ToolChain(Host, Arch, Platform, OS) |
| 33 | { |
| 34 | DarwinVersion[0] = _DarwinVersion[0]; |
| 35 | DarwinVersion[1] = _DarwinVersion[1]; |
| 36 | DarwinVersion[2] = _DarwinVersion[2]; |
| 37 | GCCVersion[0] = _GCCVersion[0]; |
| 38 | GCCVersion[1] = _GCCVersion[1]; |
| 39 | GCCVersion[2] = _GCCVersion[2]; |
| 40 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 41 | llvm::raw_string_ostream(MacosxVersionMin) |
| 42 | << "10." << DarwinVersion[0] - 4 << '.' << DarwinVersion[1]; |
| 43 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 44 | ToolChainDir = "i686-apple-darwin"; |
| 45 | ToolChainDir += llvm::utostr(DarwinVersion[0]); |
| 46 | ToolChainDir += "/"; |
| 47 | ToolChainDir += llvm::utostr(GCCVersion[0]); |
| 48 | ToolChainDir += '.'; |
| 49 | ToolChainDir += llvm::utostr(GCCVersion[1]); |
| 50 | ToolChainDir += '.'; |
| 51 | ToolChainDir += llvm::utostr(GCCVersion[2]); |
| 52 | |
| 53 | std::string Path; |
| 54 | if (getArchName() == "x86_64") { |
| 55 | Path = getHost().getDriver().Dir; |
| 56 | Path += "/../lib/gcc/"; |
| 57 | Path += getToolChainDir(); |
| 58 | Path += "/x86_64"; |
| 59 | getFilePaths().push_back(Path); |
| 60 | |
| 61 | Path = "/usr/lib/gcc/"; |
| 62 | Path += getToolChainDir(); |
| 63 | Path += "/x86_64"; |
| 64 | getFilePaths().push_back(Path); |
| 65 | } |
| 66 | |
| 67 | Path = getHost().getDriver().Dir; |
| 68 | Path += "/../lib/gcc/"; |
| 69 | Path += getToolChainDir(); |
| 70 | getFilePaths().push_back(Path); |
| 71 | |
| 72 | Path = "/usr/lib/gcc/"; |
| 73 | Path += getToolChainDir(); |
| 74 | getFilePaths().push_back(Path); |
| 75 | |
| 76 | Path = getHost().getDriver().Dir; |
| 77 | Path += "/../libexec/gcc/"; |
| 78 | Path += getToolChainDir(); |
| 79 | getProgramPaths().push_back(Path); |
| 80 | |
| 81 | Path = "/usr/libexec/gcc/"; |
| 82 | Path += getToolChainDir(); |
| 83 | getProgramPaths().push_back(Path); |
| 84 | |
Daniel Dunbar | 82fa7c5 | 2009-03-24 04:07:10 +0000 | [diff] [blame] | 85 | Path = getHost().getDriver().Dir; |
| 86 | Path += "/../libexec"; |
| 87 | getProgramPaths().push_back(Path); |
| 88 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 89 | getProgramPaths().push_back(getHost().getDriver().Dir); |
| 90 | } |
| 91 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 92 | Darwin_X86::~Darwin_X86() { |
| 93 | // Free tool implementations. |
| 94 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 95 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 96 | delete it->second; |
| 97 | } |
| 98 | |
| 99 | Tool &Darwin_X86::SelectTool(const Compilation &C, |
| 100 | const JobAction &JA) const { |
| 101 | Action::ActionClass Key; |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 102 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 103 | Key = Action::AnalyzeJobClass; |
| 104 | else |
| 105 | Key = JA.getKind(); |
| 106 | |
| 107 | Tool *&T = Tools[Key]; |
| 108 | if (!T) { |
| 109 | switch (Key) { |
| 110 | case Action::InputClass: |
| 111 | case Action::BindArchClass: |
| 112 | assert(0 && "Invalid tool kind."); |
| 113 | case Action::PreprocessJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 114 | T = new tools::darwin::Preprocess(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 115 | case Action::AnalyzeJobClass: |
| 116 | T = new tools::Clang(*this); break; |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 117 | case Action::PrecompileJobClass: |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 118 | case Action::CompileJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 119 | T = new tools::darwin::Compile(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 120 | case Action::AssembleJobClass: |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 121 | T = new tools::darwin::Assemble(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 122 | case Action::LinkJobClass: |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 123 | T = new tools::darwin::Link(*this, MacosxVersionMin.c_str()); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 124 | case Action::LipoJobClass: |
| 125 | T = new tools::darwin::Lipo(*this); break; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return *T; |
| 130 | } |
| 131 | |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 132 | DerivedArgList *Darwin_X86::TranslateArgs(InputArgList &Args) const { |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 133 | DerivedArgList *DAL = new DerivedArgList(Args, false); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 134 | const OptTable &Opts = getHost().getDriver().getOpts(); |
| 135 | |
| 136 | // FIXME: We really want to get out of the tool chain level argument |
| 137 | // translation business, as it makes the driver functionality much |
| 138 | // more opaque. For now, we follow gcc closely solely for the |
| 139 | // purpose of easily achieving feature parity & testability. Once we |
| 140 | // have something that works, we should reevaluate each translation |
| 141 | // and try to push it down into tool specific logic. |
| 142 | |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame^] | 143 | Arg *OSXVersion = |
| 144 | Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false); |
| 145 | Arg *iPhoneVersion = |
| 146 | Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false); |
| 147 | if (OSXVersion && iPhoneVersion) { |
| 148 | getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 149 | << OSXVersion->getAsString(Args) |
| 150 | << iPhoneVersion->getAsString(Args); |
| 151 | } else if (!OSXVersion && !iPhoneVersion) { |
| 152 | // Chose the default version based on the arch. |
| 153 | // |
| 154 | // FIXME: This will need to be fixed when we merge in arm support. |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 155 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 156 | DAL->append(DAL->MakeJoinedArg(0, O, MacosxVersionMin.c_str())); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 157 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 158 | |
| 159 | for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 160 | Arg *A = *it; |
| 161 | |
| 162 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 163 | // FIXME: Canonicalize name. |
| 164 | if (getArchName() != A->getValue(Args, 0)) |
| 165 | continue; |
| 166 | |
| 167 | // FIXME: The arg is leaked here, and we should have a nicer |
| 168 | // interface for this. |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 169 | unsigned Prev, Index = Prev = A->getIndex() + 1; |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 170 | Arg *XarchArg = Opts.ParseOneArg(Args, Index); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 171 | |
| 172 | // If the argument parsing failed or more than one argument was |
| 173 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 174 | // extra arguments. Emit an error and ignore. |
| 175 | // |
| 176 | // We also want to disallow any options which would alter the |
| 177 | // driver behavior; that isn't going to work in our model. We |
| 178 | // use isDriverOption() as an approximation, although things |
| 179 | // like -O4 are going to slip through. |
| 180 | if (!XarchArg || Index > Prev + 1 || |
| 181 | XarchArg->getOption().isDriverOption()) { |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 182 | getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument) |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 183 | << A->getAsString(Args); |
| 184 | continue; |
| 185 | } |
| 186 | |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 187 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 188 | A = XarchArg; |
| 189 | } |
| 190 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 191 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 192 | // gcc translates options twice, which means that self-expanding |
| 193 | // options add duplicates. |
| 194 | options::ID id = A->getOption().getId(); |
| 195 | switch (id) { |
| 196 | default: |
| 197 | DAL->append(A); |
| 198 | break; |
| 199 | |
| 200 | case options::OPT_mkernel: |
| 201 | case options::OPT_fapple_kext: |
| 202 | DAL->append(A); |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 203 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
| 204 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 205 | break; |
| 206 | |
| 207 | case options::OPT_dependency_file: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 208 | DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF), |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 209 | A->getValue(Args))); |
| 210 | break; |
| 211 | |
| 212 | case options::OPT_gfull: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 213 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); |
| 214 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 215 | Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols))); |
| 216 | break; |
| 217 | |
| 218 | case options::OPT_gused: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 219 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); |
| 220 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 221 | Opts.getOption(options::OPT_feliminate_unused_debug_symbols))); |
| 222 | break; |
| 223 | |
| 224 | case options::OPT_fterminated_vtables: |
| 225 | case options::OPT_findirect_virtual_calls: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 226 | DAL->append(DAL->MakeFlagArg(A, |
| 227 | Opts.getOption(options::OPT_fapple_kext))); |
| 228 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 229 | break; |
| 230 | |
| 231 | case options::OPT_shared: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 232 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 233 | break; |
| 234 | |
| 235 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 236 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 237 | Opts.getOption(options::OPT_mconstant_cfstrings))); |
| 238 | break; |
| 239 | |
| 240 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 241 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 242 | Opts.getOption(options::OPT_mno_constant_cfstrings))); |
| 243 | break; |
| 244 | |
| 245 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 246 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 247 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings))); |
| 248 | break; |
| 249 | |
| 250 | case options::OPT_Wno_nonportable_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 251 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 252 | Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings))); |
| 253 | break; |
| 254 | |
| 255 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 256 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 257 | Opts.getOption(options::OPT_mpascal_strings))); |
| 258 | break; |
| 259 | |
| 260 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 261 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 262 | Opts.getOption(options::OPT_mno_pascal_strings))); |
| 263 | break; |
| 264 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 267 | // FIXME: Actually, gcc always adds this, but it is filtered for |
| 268 | // duplicates somewhere. This also changes the order of things, so |
| 269 | // look it up. |
| 270 | if (getArchName() == "x86_64") |
| 271 | if (!Args.hasArg(options::OPT_m64, false)) |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 272 | DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 273 | |
| 274 | if (!Args.hasArg(options::OPT_mtune_EQ, false)) |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 275 | DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 276 | "core2")); |
| 277 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 278 | return DAL; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | bool Darwin_X86::IsMathErrnoDefault() const { |
| 282 | return false; |
| 283 | } |
| 284 | |
| 285 | bool Darwin_X86::IsUnwindTablesDefault() const { |
| 286 | // FIXME: Gross; we should probably have some separate target |
| 287 | // definition, possibly even reusing the one in clang. |
| 288 | return getArchName() == "x86_64"; |
| 289 | } |
| 290 | |
| 291 | const char *Darwin_X86::GetDefaultRelocationModel() const { |
| 292 | return "pic"; |
| 293 | } |
| 294 | |
| 295 | const char *Darwin_X86::GetForcedPicModel() const { |
| 296 | if (getArchName() == "x86_64") |
| 297 | return "pic"; |
| 298 | return 0; |
| 299 | } |
| 300 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 301 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 302 | /// all subcommands; this relies on gcc translating the majority of |
| 303 | /// command line options. |
| 304 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 305 | Generic_GCC::Generic_GCC(const HostInfo &Host, const char *Arch, |
| 306 | const char *Platform, const char *OS) |
| 307 | : ToolChain(Host, Arch, Platform, OS) |
| 308 | { |
Daniel Dunbar | 82fa7c5 | 2009-03-24 04:07:10 +0000 | [diff] [blame] | 309 | std::string Path(getHost().getDriver().Dir); |
| 310 | Path += "/../libexec"; |
| 311 | getProgramPaths().push_back(Path); |
| 312 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 313 | getProgramPaths().push_back(getHost().getDriver().Dir); |
| 314 | } |
| 315 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 316 | Generic_GCC::~Generic_GCC() { |
| 317 | // Free tool implementations. |
| 318 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 319 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 320 | delete it->second; |
| 321 | } |
| 322 | |
| 323 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
| 324 | const JobAction &JA) const { |
| 325 | Action::ActionClass Key; |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 326 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 327 | Key = Action::AnalyzeJobClass; |
| 328 | else |
| 329 | Key = JA.getKind(); |
| 330 | |
| 331 | Tool *&T = Tools[Key]; |
| 332 | if (!T) { |
| 333 | switch (Key) { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 334 | case Action::InputClass: |
| 335 | case Action::BindArchClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 336 | assert(0 && "Invalid tool kind."); |
| 337 | case Action::PreprocessJobClass: |
| 338 | T = new tools::gcc::Preprocess(*this); break; |
| 339 | case Action::PrecompileJobClass: |
| 340 | T = new tools::gcc::Precompile(*this); break; |
| 341 | case Action::AnalyzeJobClass: |
| 342 | T = new tools::Clang(*this); break; |
| 343 | case Action::CompileJobClass: |
| 344 | T = new tools::gcc::Compile(*this); break; |
| 345 | case Action::AssembleJobClass: |
| 346 | T = new tools::gcc::Assemble(*this); break; |
| 347 | case Action::LinkJobClass: |
| 348 | T = new tools::gcc::Link(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 349 | |
| 350 | // This is a bit ungeneric, but the only platform using a driver |
| 351 | // driver is Darwin. |
| 352 | case Action::LipoJobClass: |
| 353 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
| 357 | return *T; |
| 358 | } |
| 359 | |
| 360 | bool Generic_GCC::IsMathErrnoDefault() const { |
| 361 | return true; |
| 362 | } |
| 363 | |
| 364 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 365 | // FIXME: Gross; we should probably have some separate target |
| 366 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 367 | return getArchName() == "x86_64"; |
| 368 | } |
| 369 | |
| 370 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 371 | return "static"; |
| 372 | } |
| 373 | |
| 374 | const char *Generic_GCC::GetForcedPicModel() const { |
| 375 | return 0; |
| 376 | } |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 377 | |
| 378 | DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args) const { |
| 379 | return new DerivedArgList(Args, true); |
| 380 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 381 | |
| 382 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 383 | |
| 384 | FreeBSD::FreeBSD(const HostInfo &Host, const char *Arch, |
| 385 | const char *Platform, const char *OS, bool Lib32) |
| 386 | : Generic_GCC(Host, Arch, Platform, OS) { |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 387 | if (Lib32) { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 388 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 389 | getFilePaths().push_back("/usr/lib32"); |
| 390 | } else { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 391 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 392 | getFilePaths().push_back("/usr/lib"); |
| 393 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 397 | Action::ActionClass Key; |
| 398 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
| 399 | Key = Action::AnalyzeJobClass; |
| 400 | else |
| 401 | Key = JA.getKind(); |
| 402 | |
| 403 | Tool *&T = Tools[Key]; |
| 404 | if (!T) { |
| 405 | switch (Key) { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 406 | case Action::AssembleJobClass: |
| 407 | T = new tools::freebsd::Assemble(*this); break; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 408 | case Action::LinkJobClass: |
| 409 | T = new tools::freebsd::Link(*this); break; |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 410 | default: |
| 411 | T = &Generic_GCC::SelectTool(C, JA); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | return *T; |
| 416 | } |