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 | |
| 12 | using namespace clang::driver; |
| 13 | using namespace clang::driver::toolchains; |
| 14 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 15 | /// Darwin_X86 - Darwin tool chain for i386 and x86_64. |
| 16 | |
| 17 | Darwin_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 | |
| 24 | Tool &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 Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame^] | 47 | T = new tools::darwin::Assemble(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 48 | 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 | |
| 58 | ArgList *Darwin_X86::TranslateArgs(ArgList &Args) const { |
| 59 | // FIXME: Implement! |
| 60 | return &Args; |
| 61 | } |
| 62 | |
| 63 | bool Darwin_X86::IsMathErrnoDefault() const { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | bool 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 | |
| 73 | const char *Darwin_X86::GetDefaultRelocationModel() const { |
| 74 | return "pic"; |
| 75 | } |
| 76 | |
| 77 | const char *Darwin_X86::GetForcedPicModel() const { |
| 78 | if (getArchName() == "x86_64") |
| 79 | return "pic"; |
| 80 | return 0; |
| 81 | } |
| 82 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 83 | /// 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 | |
| 87 | Generic_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 | |
| 94 | Tool &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 Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 105 | case Action::InputClass: |
| 106 | case Action::BindArchClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 107 | 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 Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 120 | |
| 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 Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
| 128 | return *T; |
| 129 | } |
| 130 | |
| 131 | bool Generic_GCC::IsMathErrnoDefault() const { |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 136 | // FIXME: Gross; we should probably have some separate target |
| 137 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 138 | return getArchName() == "x86_64"; |
| 139 | } |
| 140 | |
| 141 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 142 | return "static"; |
| 143 | } |
| 144 | |
| 145 | const char *Generic_GCC::GetForcedPicModel() const { |
| 146 | return 0; |
| 147 | } |