ToolChain.h revision 88491fc6dfc7ebbd856d57a9acb49fb83077d6c8
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/Support/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 ObjCRuntime; 30 class Tool; 31 32/// ToolChain - Access to tools for a single platform. 33class ToolChain { 34public: 35 typedef SmallVector<std::string, 4> path_list; 36 37 enum CXXStdlibType { 38 CST_Libcxx, 39 CST_Libstdcxx 40 }; 41 42private: 43 const HostInfo &Host; 44 const llvm::Triple Triple; 45 46 /// The list of toolchain specific path prefixes to search for 47 /// files. 48 path_list FilePaths; 49 50 /// The list of toolchain specific path prefixes to search for 51 /// programs. 52 path_list ProgramPaths; 53 54protected: 55 ToolChain(const HostInfo &Host, const llvm::Triple &_Triple); 56 57public: 58 virtual ~ToolChain(); 59 60 // Accessors 61 62 const Driver &getDriver() const; 63 const llvm::Triple &getTriple() const { return Triple; } 64 65 llvm::Triple::ArchType getArch() const { return Triple.getArch(); } 66 StringRef getArchName() const { return Triple.getArchName(); } 67 StringRef getPlatform() const { return Triple.getVendorName(); } 68 StringRef getOS() const { return Triple.getOSName(); } 69 70 std::string getTripleString() const { 71 return Triple.getTriple(); 72 } 73 74 path_list &getFilePaths() { return FilePaths; } 75 const path_list &getFilePaths() const { return FilePaths; } 76 77 path_list &getProgramPaths() { return ProgramPaths; } 78 const path_list &getProgramPaths() const { return ProgramPaths; } 79 80 // Tool access. 81 82 /// TranslateArgs - Create a new derived argument list for any argument 83 /// translations this ToolChain may wish to perform, or 0 if no tool chain 84 /// specific translations are needed. 85 /// 86 /// \param BoundArch - The bound architecture name, or 0. 87 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args, 88 const char *BoundArch) const { 89 return 0; 90 } 91 92 /// SelectTool - Choose a tool to use to handle the action \arg JA with the 93 /// given \arg Inputs. 94 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 95 const ActionList &Inputs) const = 0; 96 97 // Helper methods 98 99 std::string GetFilePath(const char *Name) const; 100 std::string GetProgramPath(const char *Name, bool WantFile = false) const; 101 102 // Platform defaults information 103 104 /// HasNativeLTOLinker - Check whether the linker and related tools have 105 /// native LLVM support. 106 virtual bool HasNativeLLVMSupport() const; 107 108 /// LookupTypeForExtension - Return the default language type to use for the 109 /// given extension. 110 virtual types::ID LookupTypeForExtension(const char *Ext) const; 111 112 /// IsBlocksDefault - Does this tool chain enable -fblocks by default. 113 virtual bool IsBlocksDefault() const { return false; } 114 115 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as 116 /// by default. 117 virtual bool IsIntegratedAssemblerDefault() const { return false; } 118 119 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by 120 /// default. 121 virtual bool IsStrictAliasingDefault() const { return true; } 122 123 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable 124 /// -fobjc-default-synthesize-properties by default. 125 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; } 126 127 /// IsObjCNonFragileABIDefault - Does this tool chain set 128 /// -fobjc-nonfragile-abi by default. 129 virtual bool IsObjCNonFragileABIDefault() const { return false; } 130 131 /// IsObjCLegacyDispatchDefault - Does this tool chain set 132 /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile 133 /// ABI). 134 virtual bool IsObjCLegacyDispatchDefault() const { return true; } 135 136 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the 137 /// mixed dispatch method be used? 138 virtual bool UseObjCMixedDispatch() const { return false; } 139 140 /// GetDefaultStackProtectorLevel - Get the default stack protector level for 141 /// this tool chain (0=off, 1=on, 2=all). 142 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const { 143 return 0; 144 } 145 146 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables 147 /// by default. 148 virtual bool IsUnwindTablesDefault() const = 0; 149 150 /// GetDefaultRelocationModel - Return the LLVM name of the default 151 /// relocation model for this tool chain. 152 virtual const char *GetDefaultRelocationModel() const = 0; 153 154 /// GetForcedPicModel - Return the LLVM name of the forced PIC model 155 /// for this tool chain, or 0 if this tool chain does not force a 156 /// particular PIC mode. 157 virtual const char *GetForcedPicModel() const = 0; 158 159 /// SupportsProfiling - Does this tool chain support -pg. 160 virtual bool SupportsProfiling() const { return true; } 161 162 /// Does this tool chain support Objective-C garbage collection. 163 virtual bool SupportsObjCGC() const { return true; } 164 165 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf 166 /// compile unit information. 167 virtual bool UseDwarfDebugFlags() const { return false; } 168 169 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. 170 virtual bool UseSjLjExceptions() const { return false; } 171 172 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking 173 /// command line arguments into account. 174 virtual std::string ComputeLLVMTriple(const ArgList &Args, 175 types::ID InputType = types::TY_INVALID) const; 176 177 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this 178 /// target, which may take into account the command line arguments. For 179 /// example, on Darwin the -mmacosx-version-min= command line argument (which 180 /// sets the deployment target) determines the version in the triple passed to 181 /// Clang. 182 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args, 183 types::ID InputType = types::TY_INVALID) const; 184 185 /// configureObjCRuntime - Configure the known properties of the 186 /// Objective-C runtime for this platform. 187 /// 188 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction 189 virtual void configureObjCRuntime(ObjCRuntime &runtime) const; 190 191 /// hasBlocksRuntime - Given that the user is compiling with 192 /// -fblocks, does this tool chain guarantee the existence of a 193 /// blocks runtime? 194 /// 195 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction 196 virtual bool hasBlocksRuntime() const { return true; } 197 198 /// \brief Add the clang cc1 arguments for system include paths. 199 /// 200 /// This routine is responsible for adding the necessary cc1 arguments to 201 /// include headers from standard system header directories. 202 virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs, 203 ArgStringList &CC1Args) const; 204 205 // GetCXXStdlibType - Determine the C++ standard library type to use with the 206 // given compilation arguments. 207 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const; 208 209 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set 210 /// the include paths to use for the given C++ standard library type. 211 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &Args, 212 ArgStringList &CmdArgs, 213 bool ObjCXXAutoRefCount) const; 214 215 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use 216 /// for the given C++ standard library type. 217 virtual void AddCXXStdlibLibArgs(const ArgList &Args, 218 ArgStringList &CmdArgs) const; 219 220 /// AddCCKextLibArgs - Add the system specific linker arguments to use 221 /// for kernel extensions (Darwin-specific). 222 virtual void AddCCKextLibArgs(const ArgList &Args, 223 ArgStringList &CmdArgs) const; 224}; 225 226} // end namespace driver 227} // end namespace clang 228 229#endif 230