Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 1 | //===--- ToolChain.cpp - Collections of tools for one platform ----------*-===// |
| 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 "clang/Driver/ToolChain.h" |
| 11 | |
| 12 | #include "clang/Driver/Action.h" |
| 13 | #include "clang/Driver/Driver.h" |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame^] | 14 | #include "clang/Driver/HostInfo.h" |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace clang::driver; |
| 17 | |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame^] | 18 | ToolChain::ToolChain(const HostInfo &_Host, const char *_Arch, |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 19 | const char *_Platform, const char *_OS) |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame^] | 20 | : Host(_Host), Arch(_Arch), Platform(_Platform), OS(_OS) { |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | ToolChain::~ToolChain() { |
| 24 | } |
| 25 | |
| 26 | llvm::sys::Path ToolChain::GetFilePath(const Compilation &C, |
| 27 | const char *Name) const { |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame^] | 28 | return Host.getDriver().GetFilePath(Name, this); |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 29 | |
| 30 | } |
| 31 | |
| 32 | llvm::sys::Path ToolChain::GetProgramPath(const Compilation &C, |
| 33 | const char *Name) const { |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame^] | 34 | return Host.getDriver().GetProgramPath(Name, this); |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | bool ToolChain::ShouldUseClangCompiler(const Compilation &C, |
| 38 | const JobAction &JA) const { |
| 39 | // Check if user requested no clang, or clang doesn't understand |
| 40 | // this type (we only handle single inputs for now). |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame^] | 41 | if (Host.getDriver().CCCNoClang || JA.size() != 1 || |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 42 | !types::isAcceptedByClang((*JA.begin())->getType())) |
| 43 | return false; |
| 44 | |
| 45 | // Otherwise make sure this is an action clang undertands. |
| 46 | if (isa<PreprocessJobAction>(JA)) { |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame^] | 47 | if (Host.getDriver().CCCNoClangCPP) |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 48 | return false; |
| 49 | } else if (!isa<PrecompileJobAction>(JA) && !isa<CompileJobAction>(JA)) |
| 50 | return false; |
| 51 | |
| 52 | // Avoid CXX if the user requested. |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame^] | 53 | if (Host.getDriver().CCCNoClangCXX && types::isCXX((*JA.begin())->getType())) |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 54 | return false; |
| 55 | |
| 56 | // Finally, don't use clang if this isn't one of the user specified |
| 57 | // archs to build. |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame^] | 58 | if (!Host.getDriver().CCCClangArchs.empty() && |
| 59 | Host.getDriver().CCCClangArchs.count(getArchName())) |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 60 | return false; |
| 61 | |
| 62 | return true; |
| 63 | } |