ToolChain.h revision 398c610b16728b4398214367dd0effd9d2e61340
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. 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 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by 117 /// default. 118 virtual bool IsStrictAliasingDefault() const { return true; } 119 120 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable 121 /// -fobjc-default-synthesize-properties by default. 122 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; } 123 124 /// IsObjCNonFragileABIDefault - Does this tool chain set 125 /// -fobjc-nonfragile-abi by default. 126 virtual bool IsObjCNonFragileABIDefault() const { return false; } 127 128 /// IsObjCLegacyDispatchDefault - Does this tool chain set 129 /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile 130 /// ABI). 131 virtual bool IsObjCLegacyDispatchDefault() const { return false; } 132 133 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the 134 /// mixed dispatch method be used? 135 virtual bool UseObjCMixedDispatch() const { return false; } 136 137 /// GetDefaultStackProtectorLevel - Get the default stack protector level for 138 /// this tool chain (0=off, 1=on, 2=all). 139 virtual unsigned GetDefaultStackProtectorLevel() const { return 0; } 140 141 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables 142 /// by default. 143 virtual bool IsUnwindTablesDefault() const = 0; 144 145 /// GetDefaultRelocationModel - Return the LLVM name of the default 146 /// relocation model for this tool chain. 147 virtual const char *GetDefaultRelocationModel() const = 0; 148 149 /// GetForcedPicModel - Return the LLVM name of the forced PIC model 150 /// for this tool chain, or 0 if this tool chain does not force a 151 /// particular PIC mode. 152 virtual const char *GetForcedPicModel() const = 0; 153 154 /// Does this tool chain support Objective-C garbage collection. 155 virtual bool SupportsObjCGC() const { return false; } 156 157 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf 158 /// compile unit information. 159 virtual bool UseDwarfDebugFlags() const { return false; } 160 161 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. 162 virtual bool UseSjLjExceptions() const { return false; } 163 164 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking 165 /// command line arguments into account. 166 virtual std::string ComputeLLVMTriple(const ArgList &Args) const; 167 168 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this 169 /// target, which may take into account the command line arguments. For 170 /// example, on Darwin the -mmacosx-version-min= command line argument (which 171 /// sets the deployment target) determines the version in the triple passed to 172 /// Clang. 173 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args) const; 174 175 // GetCXXStdlibType - Determine the C++ standard library type to use with the 176 // given compilation arguments. 177 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const; 178 179 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set 180 /// the include paths to use for the given C++ standard library type. 181 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &Args, 182 ArgStringList &CmdArgs) const; 183 184 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use 185 /// for the given C++ standard library type. 186 virtual void AddCXXStdlibLibArgs(const ArgList &Args, 187 ArgStringList &CmdArgs) const; 188 189 /// AddCCKextLibArgs - Add the system specific linker arguments to use 190 /// for kernel extensions (Darwin-specific). 191 virtual void AddCCKextLibArgs(const ArgList &Args, 192 ArgStringList &CmdArgs) const; 193}; 194 195} // end namespace driver 196} // end namespace clang 197 198#endif 199