ToolChain.h revision 7433fedce98a58341d0f30c2e12e8d53f3bba575
1//===--- ToolChain.h - Collections of tools for one platform ----*- C++ -*-===// 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#ifndef CLANG_DRIVER_TOOLCHAIN_H_ 11#define CLANG_DRIVER_TOOLCHAIN_H_ 12 13#include "clang/Driver/Util.h" 14#include "clang/Driver/Types.h" 15#include "llvm/ADT/SmallVector.h" 16#include "llvm/ADT/Triple.h" 17#include "llvm/System/Path.h" 18#include <string> 19 20namespace clang { 21namespace driver { 22 class ArgList; 23 class Compilation; 24 class DerivedArgList; 25 class Driver; 26 class HostInfo; 27 class InputArgList; 28 class JobAction; 29 class Tool; 30 31/// ToolChain - Access to tools for a single platform. 32class ToolChain { 33public: 34 typedef llvm::SmallVector<std::string, 4> path_list; 35 36 enum CXXStdlibType { 37 CST_Libcxx, 38 CST_Libstdcxx 39 }; 40 41private: 42 const HostInfo &Host; 43 const llvm::Triple Triple; 44 45 /// The list of toolchain specific path prefixes to search for 46 /// files. 47 path_list FilePaths; 48 49 /// The list of toolchain specific path prefixes to search for 50 /// programs. 51 path_list ProgramPaths; 52 53protected: 54 ToolChain(const HostInfo &Host, const llvm::Triple &_Triple); 55 56public: 57 virtual ~ToolChain(); 58 59 // Accessors 60 61 const Driver &getDriver() const; 62 const llvm::Triple &getTriple() const { return Triple; } 63 64 llvm::Triple::ArchType getArch() const { return Triple.getArch(); } 65 llvm::StringRef getArchName() const { return Triple.getArchName(); } 66 llvm::StringRef getPlatform() const { return Triple.getVendorName(); } 67 llvm::StringRef getOS() const { return Triple.getOSName(); } 68 69 std::string getTripleString() const { 70 return Triple.getTriple(); 71 } 72 73 path_list &getFilePaths() { return FilePaths; } 74 const path_list &getFilePaths() const { return FilePaths; } 75 76 path_list &getProgramPaths() { return ProgramPaths; } 77 const path_list &getProgramPaths() const { return ProgramPaths; } 78 79 // Tool access. 80 81 /// TranslateArgs - Create a new derived argument list for any argument 82 /// translations this ToolChain may wish to perform, or 0 if no tool chain 83 /// specific translations are needed. 84 /// 85 /// \param BoundArch - The bound architecture name, or 0. 86 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args, 87 const char *BoundArch) const { 88 return 0; 89 } 90 91 /// SelectTool - Choose a tool to use to handle the action \arg JA. 92 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const = 0; 93 94 // Helper methods 95 96 std::string GetFilePath(const char *Name) const; 97 std::string GetProgramPath(const char *Name, bool WantFile = false) const; 98 99 // Platform defaults information 100 101 /// HasNativeLTOLinker - Check whether the linker and related tools have 102 /// native LLVM support. 103 virtual bool HasNativeLLVMSupport() const; 104 105 /// LookupTypeForExtension - Return the default language type to use for the 106 /// given extension. 107 virtual types::ID LookupTypeForExtension(const char *Ext) const; 108 109 /// IsBlocksDefault - Does this tool chain enable -fblocks by default. 110 virtual bool IsBlocksDefault() const { return false; } 111 112 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as 113 /// by default. 114 virtual bool IsIntegratedAssemblerDefault() const { return false; } 115 116 /// IsObjCNonFragileABIDefault - Does this tool chain set 117 /// -fobjc-nonfragile-abi by default. 118 virtual bool IsObjCNonFragileABIDefault() const { return false; } 119 120 /// IsObjCLegacyDispatchDefault - Does this tool chain set 121 /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile 122 /// ABI). 123 virtual bool IsObjCLegacyDispatchDefault() const { return false; } 124 125 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the 126 /// mixed dispatch method be used? 127 virtual bool UseObjCMixedDispatch() const { return false; } 128 129 /// GetDefaultStackProtectorLevel - Get the default stack protector level for 130 /// this tool chain (0=off, 1=on, 2=all). 131 virtual unsigned GetDefaultStackProtectorLevel() const { return 0; } 132 133 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables 134 /// by default. 135 virtual bool IsUnwindTablesDefault() const = 0; 136 137 /// GetDefaultRelocationModel - Return the LLVM name of the default 138 /// relocation model for this tool chain. 139 virtual const char *GetDefaultRelocationModel() const = 0; 140 141 /// GetForcedPicModel - Return the LLVM name of the forced PIC model 142 /// for this tool chain, or 0 if this tool chain does not force a 143 /// particular PIC mode. 144 virtual const char *GetForcedPicModel() const = 0; 145 146 /// Does this tool chain support Objective-C garbage collection. 147 virtual bool SupportsObjCGC() const { return false; } 148 149 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf 150 /// compile unit information. 151 virtual bool UseDwarfDebugFlags() const { return false; } 152 153 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. 154 virtual bool UseSjLjExceptions() const { return false; } 155 156 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking 157 /// command line arguments into account. 158 virtual std::string ComputeLLVMTriple(const ArgList &Args) const; 159 160 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this 161 /// target, which may take into account the command line arguments. For 162 /// example, on Darwin the -mmacosx-version-min= command line argument (which 163 /// sets the deployment target) determines the version in the triple passed to 164 /// Clang. 165 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args) const; 166 167 // GetCXXStdlibType - Determine the C++ standard library type to use with the 168 // given compilation arguments. 169 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const; 170 171 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set 172 /// the include paths to use for the given C++ standard library type. 173 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &Args, 174 ArgStringList &CmdArgs) const; 175 176 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use 177 /// for the given C++ standard library type. 178 virtual void AddCXXStdlibLibArgs(const ArgList &Args, 179 ArgStringList &CmdArgs) const; 180 181 /// AddCCKextLibArgs - Add the system specific linker arguments to use 182 /// for kernel extensions (Darwin-specific). 183 virtual void AddCCKextLibArgs(const ArgList &Args, 184 ArgStringList &CmdArgs) const; 185}; 186 187} // end namespace driver 188} // end namespace clang 189 190#endif 191