1193326Sed//===--- ToolChain.h - Collections of tools for one platform ----*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed 10193326Sed#ifndef CLANG_DRIVER_TOOLCHAIN_H_ 11193326Sed#define CLANG_DRIVER_TOOLCHAIN_H_ 12193326Sed 13252723Sdim#include "clang/Driver/Action.h" 14252723Sdim#include "clang/Driver/Types.h" 15218893Sdim#include "clang/Driver/Util.h" 16252723Sdim#include "llvm/ADT/OwningPtr.h" 17193326Sed#include "llvm/ADT/SmallVector.h" 18193326Sed#include "llvm/ADT/Triple.h" 19218893Sdim#include "llvm/Support/Path.h" 20193326Sed#include <string> 21193326Sed 22263509Sdimnamespace llvm { 23263509Sdimnamespace opt { 24263509Sdim class ArgList; 25263509Sdim class DerivedArgList; 26263509Sdim class InputArgList; 27263509Sdim} 28263509Sdim} 29263509Sdim 30193326Sednamespace clang { 31245431Sdim class ObjCRuntime; 32245431Sdim 33193326Sednamespace driver { 34193326Sed class Compilation; 35201361Srdivacky class Driver; 36193326Sed class JobAction; 37263509Sdim class SanitizerArgs; 38193326Sed class Tool; 39193326Sed 40193326Sed/// ToolChain - Access to tools for a single platform. 41193326Sedclass ToolChain { 42193326Sedpublic: 43226890Sdim typedef SmallVector<std::string, 4> path_list; 44193326Sed 45218893Sdim enum CXXStdlibType { 46218893Sdim CST_Libcxx, 47218893Sdim CST_Libstdcxx 48218893Sdim }; 49218893Sdim 50235633Sdim enum RuntimeLibType { 51235633Sdim RLT_CompilerRT, 52235633Sdim RLT_Libgcc 53235633Sdim }; 54235633Sdim 55193326Sedprivate: 56235633Sdim const Driver &D; 57193326Sed const llvm::Triple Triple; 58263509Sdim const llvm::opt::ArgList &Args; 59193326Sed 60193326Sed /// The list of toolchain specific path prefixes to search for 61193326Sed /// files. 62193326Sed path_list FilePaths; 63193326Sed 64193326Sed /// The list of toolchain specific path prefixes to search for 65193326Sed /// programs. 66193326Sed path_list ProgramPaths; 67193326Sed 68252723Sdim mutable OwningPtr<Tool> Clang; 69252723Sdim mutable OwningPtr<Tool> Assemble; 70252723Sdim mutable OwningPtr<Tool> Link; 71252723Sdim Tool *getClang() const; 72252723Sdim Tool *getAssemble() const; 73252723Sdim Tool *getLink() const; 74252723Sdim Tool *getClangAs() const; 75252723Sdim 76263509Sdim mutable OwningPtr<SanitizerArgs> SanitizerArguments; 77263509Sdim 78193326Sedprotected: 79263509Sdim ToolChain(const Driver &D, const llvm::Triple &T, 80263509Sdim const llvm::opt::ArgList &Args); 81193326Sed 82252723Sdim virtual Tool *buildAssembler() const; 83252723Sdim virtual Tool *buildLinker() const; 84252723Sdim virtual Tool *getTool(Action::ActionClass AC) const; 85252723Sdim 86235633Sdim /// \name Utilities for implementing subclasses. 87235633Sdim ///@{ 88263509Sdim static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, 89263509Sdim llvm::opt::ArgStringList &CC1Args, 90235633Sdim const Twine &Path); 91263509Sdim static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, 92263509Sdim llvm::opt::ArgStringList &CC1Args, 93235633Sdim const Twine &Path); 94263509Sdim static void 95263509Sdim addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, 96263509Sdim llvm::opt::ArgStringList &CC1Args, 97263509Sdim const Twine &Path); 98263509Sdim static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, 99263509Sdim llvm::opt::ArgStringList &CC1Args, 100235633Sdim ArrayRef<StringRef> Paths); 101235633Sdim ///@} 102235633Sdim 103193326Sedpublic: 104193326Sed virtual ~ToolChain(); 105193326Sed 106193326Sed // Accessors 107193326Sed 108201361Srdivacky const Driver &getDriver() const; 109194613Sed const llvm::Triple &getTriple() const { return Triple; } 110194613Sed 111212904Sdim llvm::Triple::ArchType getArch() const { return Triple.getArch(); } 112226890Sdim StringRef getArchName() const { return Triple.getArchName(); } 113226890Sdim StringRef getPlatform() const { return Triple.getVendorName(); } 114226890Sdim StringRef getOS() const { return Triple.getOSName(); } 115193326Sed 116245431Sdim /// \brief Provide the default architecture name (as expected by -arch) for 117245431Sdim /// this toolchain. Note t 118245431Sdim std::string getDefaultUniversalArchName() const; 119245431Sdim 120193326Sed std::string getTripleString() const { 121193326Sed return Triple.getTriple(); 122193326Sed } 123193326Sed 124193326Sed path_list &getFilePaths() { return FilePaths; } 125193326Sed const path_list &getFilePaths() const { return FilePaths; } 126193326Sed 127193326Sed path_list &getProgramPaths() { return ProgramPaths; } 128193326Sed const path_list &getProgramPaths() const { return ProgramPaths; } 129193326Sed 130263509Sdim const SanitizerArgs& getSanitizerArgs() const; 131263509Sdim 132193326Sed // Tool access. 133193326Sed 134198092Srdivacky /// TranslateArgs - Create a new derived argument list for any argument 135210299Sed /// translations this ToolChain may wish to perform, or 0 if no tool chain 136210299Sed /// specific translations are needed. 137198092Srdivacky /// 138198092Srdivacky /// \param BoundArch - The bound architecture name, or 0. 139263509Sdim virtual llvm::opt::DerivedArgList * 140263509Sdim TranslateArgs(const llvm::opt::DerivedArgList &Args, 141263509Sdim const char *BoundArch) const { 142210299Sed return 0; 143210299Sed } 144193326Sed 145252723Sdim /// Choose a tool to use to handle the action \p JA. 146252723Sdim Tool *SelectTool(const JobAction &JA) const; 147193326Sed 148193326Sed // Helper methods 149193326Sed 150210299Sed std::string GetFilePath(const char *Name) const; 151245431Sdim std::string GetProgramPath(const char *Name) const; 152193326Sed 153263509Sdim /// \brief Dispatch to the specific toolchain for verbose printing. 154263509Sdim /// 155263509Sdim /// This is used when handling the verbose option to print detailed, 156263509Sdim /// toolchain-specific information useful for understanding the behavior of 157263509Sdim /// the driver on a specific platform. 158263509Sdim virtual void printVerboseInfo(raw_ostream &OS) const {}; 159263509Sdim 160193326Sed // Platform defaults information 161193326Sed 162218893Sdim /// HasNativeLTOLinker - Check whether the linker and related tools have 163218893Sdim /// native LLVM support. 164218893Sdim virtual bool HasNativeLLVMSupport() const; 165218893Sdim 166212904Sdim /// LookupTypeForExtension - Return the default language type to use for the 167212904Sdim /// given extension. 168212904Sdim virtual types::ID LookupTypeForExtension(const char *Ext) const; 169212904Sdim 170199482Srdivacky /// IsBlocksDefault - Does this tool chain enable -fblocks by default. 171199482Srdivacky virtual bool IsBlocksDefault() const { return false; } 172199482Srdivacky 173203955Srdivacky /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as 174203955Srdivacky /// by default. 175203955Srdivacky virtual bool IsIntegratedAssemblerDefault() const { return false; } 176203955Srdivacky 177252723Sdim /// \brief Check if the toolchain should use the integrated assembler. 178252723Sdim bool useIntegratedAs() const; 179252723Sdim 180245431Sdim /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default. 181245431Sdim virtual bool IsMathErrnoDefault() const { return true; } 182245431Sdim 183245431Sdim /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable 184245431Sdim /// -fencode-extended-block-signature by default. 185245431Sdim virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; } 186218893Sdim 187199482Srdivacky /// IsObjCNonFragileABIDefault - Does this tool chain set 188199482Srdivacky /// -fobjc-nonfragile-abi by default. 189199482Srdivacky virtual bool IsObjCNonFragileABIDefault() const { return false; } 190199482Srdivacky 191207619Srdivacky /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the 192207619Srdivacky /// mixed dispatch method be used? 193207619Srdivacky virtual bool UseObjCMixedDispatch() const { return false; } 194207619Srdivacky 195199482Srdivacky /// GetDefaultStackProtectorLevel - Get the default stack protector level for 196199482Srdivacky /// this tool chain (0=off, 1=on, 2=all). 197226890Sdim virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const { 198226890Sdim return 0; 199226890Sdim } 200199482Srdivacky 201235633Sdim /// GetDefaultRuntimeLibType - Get the default runtime library variant to use. 202235633Sdim virtual RuntimeLibType GetDefaultRuntimeLibType() const { 203235633Sdim return ToolChain::RLT_Libgcc; 204235633Sdim } 205235633Sdim 206193326Sed /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables 207193326Sed /// by default. 208245431Sdim virtual bool IsUnwindTablesDefault() const; 209193326Sed 210245431Sdim /// \brief Test whether this toolchain defaults to PIC. 211245431Sdim virtual bool isPICDefault() const = 0; 212193326Sed 213252723Sdim /// \brief Test whether this toolchain defaults to PIE. 214252723Sdim virtual bool isPIEDefault() const = 0; 215252723Sdim 216252723Sdim /// \brief Tests whether this toolchain forces its default for PIC, PIE or 217252723Sdim /// non-PIC. If this returns true, any PIC related flags should be ignored 218252723Sdim /// and instead the results of \c isPICDefault() and \c isPIEDefault() are 219252723Sdim /// used exclusively. 220245431Sdim virtual bool isPICDefaultForced() const = 0; 221201361Srdivacky 222221345Sdim /// SupportsProfiling - Does this tool chain support -pg. 223221345Sdim virtual bool SupportsProfiling() const { return true; } 224221345Sdim 225207619Srdivacky /// Does this tool chain support Objective-C garbage collection. 226223017Sdim virtual bool SupportsObjCGC() const { return true; } 227207619Srdivacky 228245431Sdim /// Complain if this tool chain doesn't support Objective-C ARC. 229245431Sdim virtual void CheckObjCARC() const {} 230235633Sdim 231201361Srdivacky /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf 232201361Srdivacky /// compile unit information. 233201361Srdivacky virtual bool UseDwarfDebugFlags() const { return false; } 234203955Srdivacky 235203955Srdivacky /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. 236203955Srdivacky virtual bool UseSjLjExceptions() const { return false; } 237212904Sdim 238212904Sdim /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking 239212904Sdim /// command line arguments into account. 240263509Sdim virtual std::string 241263509Sdim ComputeLLVMTriple(const llvm::opt::ArgList &Args, 242263509Sdim types::ID InputType = types::TY_INVALID) const; 243212904Sdim 244212904Sdim /// ComputeEffectiveClangTriple - Return the Clang triple to use for this 245212904Sdim /// target, which may take into account the command line arguments. For 246212904Sdim /// example, on Darwin the -mmacosx-version-min= command line argument (which 247212904Sdim /// sets the deployment target) determines the version in the triple passed to 248212904Sdim /// Clang. 249263509Sdim virtual std::string ComputeEffectiveClangTriple( 250263509Sdim const llvm::opt::ArgList &Args, 251263509Sdim types::ID InputType = types::TY_INVALID) const; 252218893Sdim 253245431Sdim /// getDefaultObjCRuntime - Return the default Objective-C runtime 254245431Sdim /// for this platform. 255224145Sdim /// 256226890Sdim /// FIXME: this really belongs on some sort of DeploymentTarget abstraction 257245431Sdim virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const; 258224145Sdim 259226890Sdim /// hasBlocksRuntime - Given that the user is compiling with 260226890Sdim /// -fblocks, does this tool chain guarantee the existence of a 261226890Sdim /// blocks runtime? 262226890Sdim /// 263226890Sdim /// FIXME: this really belongs on some sort of DeploymentTarget abstraction 264226890Sdim virtual bool hasBlocksRuntime() const { return true; } 265226890Sdim 266229042Sdim /// \brief Add the clang cc1 arguments for system include paths. 267229042Sdim /// 268229042Sdim /// This routine is responsible for adding the necessary cc1 arguments to 269229042Sdim /// include headers from standard system header directories. 270263509Sdim virtual void 271263509Sdim AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, 272263509Sdim llvm::opt::ArgStringList &CC1Args) const; 273229042Sdim 274252723Sdim /// \brief Add options that need to be passed to cc1 for this target. 275263509Sdim virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, 276263509Sdim llvm::opt::ArgStringList &CC1Args) const; 277245431Sdim 278235633Sdim // GetRuntimeLibType - Determine the runtime library type to use with the 279235633Sdim // given compilation arguments. 280263509Sdim virtual RuntimeLibType 281263509Sdim GetRuntimeLibType(const llvm::opt::ArgList &Args) const; 282235633Sdim 283218893Sdim // GetCXXStdlibType - Determine the C++ standard library type to use with the 284218893Sdim // given compilation arguments. 285263509Sdim virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const; 286218893Sdim 287218893Sdim /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set 288218893Sdim /// the include paths to use for the given C++ standard library type. 289263509Sdim virtual void 290263509Sdim AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, 291263509Sdim llvm::opt::ArgStringList &CC1Args) const; 292218893Sdim 293218893Sdim /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use 294218893Sdim /// for the given C++ standard library type. 295263509Sdim virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, 296263509Sdim llvm::opt::ArgStringList &CmdArgs) const; 297218893Sdim 298218893Sdim /// AddCCKextLibArgs - Add the system specific linker arguments to use 299218893Sdim /// for kernel extensions (Darwin-specific). 300263509Sdim virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args, 301263509Sdim llvm::opt::ArgStringList &CmdArgs) const; 302245431Sdim 303245431Sdim /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets 304245431Sdim /// global flags for unsafe floating point math, add it and return true. 305245431Sdim /// 306266759Sdim /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags. 307263509Sdim virtual bool 308263509Sdim AddFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args, 309263509Sdim llvm::opt::ArgStringList &CmdArgs) const; 310193326Sed}; 311193326Sed 312193326Sed} // end namespace driver 313193326Sed} // end namespace clang 314193326Sed 315193326Sed#endif 316