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 20 namespace clang { 21 namespace 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. 33 class ToolChain { 34 public: 35 typedef llvm::SmallVector<std::string, 4> path_list; 36 37 enum CXXStdlibType { 38 CST_Libcxx, 39 CST_Libstdcxx 40 }; 41 42 private: 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 54 protected: 55 ToolChain(const HostInfo &Host, const llvm::Triple &_Triple); 56 57 public: 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 llvm::StringRef getArchName() const { return Triple.getArchName(); } 67 llvm::StringRef getPlatform() const { return Triple.getVendorName(); } 68 llvm::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 false; } 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() const { return 0; } 143 144 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables 145 /// by default. 146 virtual bool IsUnwindTablesDefault() const = 0; 147 148 /// GetDefaultRelocationModel - Return the LLVM name of the default 149 /// relocation model for this tool chain. 150 virtual const char *GetDefaultRelocationModel() const = 0; 151 152 /// GetForcedPicModel - Return the LLVM name of the forced PIC model 153 /// for this tool chain, or 0 if this tool chain does not force a 154 /// particular PIC mode. 155 virtual const char *GetForcedPicModel() const = 0; 156 157 /// SupportsProfiling - Does this tool chain support -pg. 158 virtual bool SupportsProfiling() const { return true; } 159 160 /// Does this tool chain support Objective-C garbage collection. 161 virtual bool SupportsObjCGC() const { return true; } 162 163 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf 164 /// compile unit information. 165 virtual bool UseDwarfDebugFlags() const { return false; } 166 167 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. 168 virtual bool UseSjLjExceptions() const { return false; } 169 170 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking 171 /// command line arguments into account. 172 virtual std::string ComputeLLVMTriple(const ArgList &Args) const; 173 174 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this 175 /// target, which may take into account the command line arguments. For 176 /// example, on Darwin the -mmacosx-version-min= command line argument (which 177 /// sets the deployment target) determines the version in the triple passed to 178 /// Clang. 179 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args) const; 180 181 /// configureObjCRuntime - Configure the known properties of the 182 /// Objective-C runtime for this platform. 183 /// 184 /// FIXME: this doesn't really belong here. 185 virtual void configureObjCRuntime(ObjCRuntime &runtime) const; 186 187 // GetCXXStdlibType - Determine the C++ standard library type to use with the 188 // given compilation arguments. 189 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const; 190 191 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set 192 /// the include paths to use for the given C++ standard library type. 193 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &Args, 194 ArgStringList &CmdArgs, 195 bool ObjCXXAutoRefCount) const; 196 197 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use 198 /// for the given C++ standard library type. 199 virtual void AddCXXStdlibLibArgs(const ArgList &Args, 200 ArgStringList &CmdArgs) const; 201 202 /// AddCCKextLibArgs - Add the system specific linker arguments to use 203 /// for kernel extensions (Darwin-specific). 204 virtual void AddCCKextLibArgs(const ArgList &Args, 205 ArgStringList &CmdArgs) const; 206 }; 207 208 } // end namespace driver 209 } // end namespace clang 210 211 #endif 212