blob: ea2528bfffc197b1156e521666bf11f0322dce37 [file] [log] [blame]
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +00001//===--- 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 Dunbarfa0cda42009-03-17 21:21:26 +000014#include "clang/Driver/HostInfo.h"
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000015
16using namespace clang::driver;
17
Daniel Dunbarfa0cda42009-03-17 21:21:26 +000018ToolChain::ToolChain(const HostInfo &_Host, const char *_Arch,
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000019 const char *_Platform, const char *_OS)
Daniel Dunbarfa0cda42009-03-17 21:21:26 +000020 : Host(_Host), Arch(_Arch), Platform(_Platform), OS(_OS) {
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000021}
22
23ToolChain::~ToolChain() {
24}
25
26llvm::sys::Path ToolChain::GetFilePath(const Compilation &C,
27 const char *Name) const {
Daniel Dunbarfa0cda42009-03-17 21:21:26 +000028 return Host.getDriver().GetFilePath(Name, this);
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000029
30}
31
32llvm::sys::Path ToolChain::GetProgramPath(const Compilation &C,
33 const char *Name) const {
Daniel Dunbarfa0cda42009-03-17 21:21:26 +000034 return Host.getDriver().GetProgramPath(Name, this);
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000035}
36
37bool 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 Dunbarfa0cda42009-03-17 21:21:26 +000041 if (Host.getDriver().CCCNoClang || JA.size() != 1 ||
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000042 !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 Dunbarfa0cda42009-03-17 21:21:26 +000047 if (Host.getDriver().CCCNoClangCPP)
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000048 return false;
49 } else if (!isa<PrecompileJobAction>(JA) && !isa<CompileJobAction>(JA))
50 return false;
51
52 // Avoid CXX if the user requested.
Daniel Dunbarfa0cda42009-03-17 21:21:26 +000053 if (Host.getDriver().CCCNoClangCXX && types::isCXX((*JA.begin())->getType()))
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000054 return false;
55
56 // Finally, don't use clang if this isn't one of the user specified
57 // archs to build.
Daniel Dunbarfa0cda42009-03-17 21:21:26 +000058 if (!Host.getDriver().CCCClangArchs.empty() &&
59 Host.getDriver().CCCClangArchs.count(getArchName()))
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000060 return false;
61
62 return true;
63}