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