ToolChain.h revision f85e193739c953358c865005855253af4f68a497
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 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 with the 92 /// given \arg Inputs. 93 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 94 const ActionList &Inputs) const = 0; 95 96 // Helper methods 97 98 std::string GetFilePath(const char *Name) const; 99 std::string GetProgramPath(const char *Name, bool WantFile = false) const; 100 101 // Platform defaults information 102 103 /// HasNativeLTOLinker - Check whether the linker and related tools have 104 /// native LLVM support. 105 virtual bool HasNativeLLVMSupport() const; 106 107 /// LookupTypeForExtension - Return the default language type to use for the 108 /// given extension. 109 virtual types::ID LookupTypeForExtension(const char *Ext) const; 110 111 /// IsBlocksDefault - Does this tool chain enable -fblocks by default. 112 virtual bool IsBlocksDefault() const { return false; } 113 114 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as 115 /// by default. 116 virtual bool IsIntegratedAssemblerDefault() const { return false; } 117 118 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by 119 /// default. 120 virtual bool IsStrictAliasingDefault() const { return true; } 121 122 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable 123 /// -fobjc-default-synthesize-properties by default. 124 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; } 125 126 /// IsObjCNonFragileABIDefault - Does this tool chain set 127 /// -fobjc-nonfragile-abi by default. 128 virtual bool IsObjCNonFragileABIDefault() const { return false; } 129 130 /// IsObjCLegacyDispatchDefault - Does this tool chain set 131 /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile 132 /// ABI). 133 virtual bool IsObjCLegacyDispatchDefault() const { return false; } 134 135 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the 136 /// mixed dispatch method be used? 137 virtual bool UseObjCMixedDispatch() const { return false; } 138 139 /// GetDefaultStackProtectorLevel - Get the default stack protector level for 140 /// this tool chain (0=off, 1=on, 2=all). 141 virtual unsigned GetDefaultStackProtectorLevel() const { return 0; } 142 143 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables 144 /// by default. 145 virtual bool IsUnwindTablesDefault() const = 0; 146 147 /// GetDefaultRelocationModel - Return the LLVM name of the default 148 /// relocation model for this tool chain. 149 virtual const char *GetDefaultRelocationModel() const = 0; 150 151 /// GetForcedPicModel - Return the LLVM name of the forced PIC model 152 /// for this tool chain, or 0 if this tool chain does not force a 153 /// particular PIC mode. 154 virtual const char *GetForcedPicModel() const = 0; 155 156 /// SupportsProfiling - Does this tool chain support -pg. 157 virtual bool SupportsProfiling() const { return true; } 158 159 /// Does this tool chain support Objective-C garbage collection. 160 virtual bool SupportsObjCGC() const { return true; } 161 162 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf 163 /// compile unit information. 164 virtual bool UseDwarfDebugFlags() const { return false; } 165 166 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. 167 virtual bool UseSjLjExceptions() const { return false; } 168 169 /// HasARCRuntime - Does this tool chain provide a specialized ARC runtime. 170 virtual bool HasARCRuntime() 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) const; 175 176 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this 177 /// target, which may take into account the command line arguments. For 178 /// example, on Darwin the -mmacosx-version-min= command line argument (which 179 /// sets the deployment target) determines the version in the triple passed to 180 /// Clang. 181 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args) const; 182 183 // GetCXXStdlibType - Determine the C++ standard library type to use with the 184 // given compilation arguments. 185 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const; 186 187 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set 188 /// the include paths to use for the given C++ standard library type. 189 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &Args, 190 ArgStringList &CmdArgs, 191 bool ObjCXXAutoRefCount) const; 192 193 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use 194 /// for the given C++ standard library type. 195 virtual void AddCXXStdlibLibArgs(const ArgList &Args, 196 ArgStringList &CmdArgs) const; 197 198 /// AddCCKextLibArgs - Add the system specific linker arguments to use 199 /// for kernel extensions (Darwin-specific). 200 virtual void AddCCKextLibArgs(const ArgList &Args, 201 ArgStringList &CmdArgs) const; 202}; 203 204} // end namespace driver 205} // end namespace clang 206 207#endif 208