clang API Documentation
00001 //===--- ToolChain.h - Collections of tools for one platform ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef CLANG_DRIVER_TOOLCHAIN_H_ 00011 #define CLANG_DRIVER_TOOLCHAIN_H_ 00012 00013 #include "clang/Driver/Util.h" 00014 #include "clang/Driver/Types.h" 00015 #include "llvm/ADT/SmallVector.h" 00016 #include "llvm/ADT/Triple.h" 00017 #include "llvm/Support/Path.h" 00018 #include <string> 00019 00020 namespace clang { 00021 namespace driver { 00022 class ArgList; 00023 class Compilation; 00024 class DerivedArgList; 00025 class Driver; 00026 class InputArgList; 00027 class JobAction; 00028 class ObjCRuntime; 00029 class Tool; 00030 00031 /// ToolChain - Access to tools for a single platform. 00032 class ToolChain { 00033 public: 00034 typedef SmallVector<std::string, 4> path_list; 00035 00036 enum CXXStdlibType { 00037 CST_Libcxx, 00038 CST_Libstdcxx 00039 }; 00040 00041 enum RuntimeLibType { 00042 RLT_CompilerRT, 00043 RLT_Libgcc 00044 }; 00045 00046 private: 00047 const Driver &D; 00048 const llvm::Triple Triple; 00049 00050 /// The list of toolchain specific path prefixes to search for 00051 /// files. 00052 path_list FilePaths; 00053 00054 /// The list of toolchain specific path prefixes to search for 00055 /// programs. 00056 path_list ProgramPaths; 00057 00058 protected: 00059 ToolChain(const Driver &D, const llvm::Triple &T); 00060 00061 /// \name Utilities for implementing subclasses. 00062 ///@{ 00063 static void addSystemInclude(const ArgList &DriverArgs, 00064 ArgStringList &CC1Args, 00065 const Twine &Path); 00066 static void addExternCSystemInclude(const ArgList &DriverArgs, 00067 ArgStringList &CC1Args, 00068 const Twine &Path); 00069 static void addSystemIncludes(const ArgList &DriverArgs, 00070 ArgStringList &CC1Args, 00071 ArrayRef<StringRef> Paths); 00072 ///@} 00073 00074 public: 00075 virtual ~ToolChain(); 00076 00077 // Accessors 00078 00079 const Driver &getDriver() const; 00080 const llvm::Triple &getTriple() const { return Triple; } 00081 00082 llvm::Triple::ArchType getArch() const { return Triple.getArch(); } 00083 StringRef getArchName() const { return Triple.getArchName(); } 00084 StringRef getPlatform() const { return Triple.getVendorName(); } 00085 StringRef getOS() const { return Triple.getOSName(); } 00086 00087 std::string getTripleString() const { 00088 return Triple.getTriple(); 00089 } 00090 00091 path_list &getFilePaths() { return FilePaths; } 00092 const path_list &getFilePaths() const { return FilePaths; } 00093 00094 path_list &getProgramPaths() { return ProgramPaths; } 00095 const path_list &getProgramPaths() const { return ProgramPaths; } 00096 00097 // Tool access. 00098 00099 /// TranslateArgs - Create a new derived argument list for any argument 00100 /// translations this ToolChain may wish to perform, or 0 if no tool chain 00101 /// specific translations are needed. 00102 /// 00103 /// \param BoundArch - The bound architecture name, or 0. 00104 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args, 00105 const char *BoundArch) const { 00106 return 0; 00107 } 00108 00109 /// SelectTool - Choose a tool to use to handle the action \arg JA with the 00110 /// given \arg Inputs. 00111 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 00112 const ActionList &Inputs) const = 0; 00113 00114 // Helper methods 00115 00116 std::string GetFilePath(const char *Name) const; 00117 std::string GetProgramPath(const char *Name, bool WantFile = false) const; 00118 00119 // Platform defaults information 00120 00121 /// HasNativeLTOLinker - Check whether the linker and related tools have 00122 /// native LLVM support. 00123 virtual bool HasNativeLLVMSupport() const; 00124 00125 /// LookupTypeForExtension - Return the default language type to use for the 00126 /// given extension. 00127 virtual types::ID LookupTypeForExtension(const char *Ext) const; 00128 00129 /// IsBlocksDefault - Does this tool chain enable -fblocks by default. 00130 virtual bool IsBlocksDefault() const { return false; } 00131 00132 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as 00133 /// by default. 00134 virtual bool IsIntegratedAssemblerDefault() const { return false; } 00135 00136 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by 00137 /// default. 00138 virtual bool IsStrictAliasingDefault() const { return true; } 00139 00140 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default. 00141 virtual bool IsMathErrnoDefault() const { return true; } 00142 00143 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable 00144 /// -fobjc-default-synthesize-properties by default. 00145 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; } 00146 00147 /// IsObjCNonFragileABIDefault - Does this tool chain set 00148 /// -fobjc-nonfragile-abi by default. 00149 virtual bool IsObjCNonFragileABIDefault() const { return false; } 00150 00151 /// IsObjCLegacyDispatchDefault - Does this tool chain set 00152 /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile 00153 /// ABI). 00154 virtual bool IsObjCLegacyDispatchDefault() const { return true; } 00155 00156 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the 00157 /// mixed dispatch method be used? 00158 virtual bool UseObjCMixedDispatch() const { return false; } 00159 00160 /// GetDefaultStackProtectorLevel - Get the default stack protector level for 00161 /// this tool chain (0=off, 1=on, 2=all). 00162 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const { 00163 return 0; 00164 } 00165 00166 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use. 00167 virtual RuntimeLibType GetDefaultRuntimeLibType() const { 00168 return ToolChain::RLT_Libgcc; 00169 } 00170 00171 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables 00172 /// by default. 00173 virtual bool IsUnwindTablesDefault() const = 0; 00174 00175 /// GetDefaultRelocationModel - Return the LLVM name of the default 00176 /// relocation model for this tool chain. 00177 virtual const char *GetDefaultRelocationModel() const = 0; 00178 00179 /// GetForcedPicModel - Return the LLVM name of the forced PIC model 00180 /// for this tool chain, or 0 if this tool chain does not force a 00181 /// particular PIC mode. 00182 virtual const char *GetForcedPicModel() const = 0; 00183 00184 /// SupportsProfiling - Does this tool chain support -pg. 00185 virtual bool SupportsProfiling() const { return true; } 00186 00187 /// Does this tool chain support Objective-C garbage collection. 00188 virtual bool SupportsObjCGC() const { return true; } 00189 00190 /// Does this tool chain support Objective-C ARC. 00191 virtual bool SupportsObjCARC() const { return true; } 00192 00193 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf 00194 /// compile unit information. 00195 virtual bool UseDwarfDebugFlags() const { return false; } 00196 00197 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. 00198 virtual bool UseSjLjExceptions() const { return false; } 00199 00200 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking 00201 /// command line arguments into account. 00202 virtual std::string ComputeLLVMTriple(const ArgList &Args, 00203 types::ID InputType = types::TY_INVALID) const; 00204 00205 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this 00206 /// target, which may take into account the command line arguments. For 00207 /// example, on Darwin the -mmacosx-version-min= command line argument (which 00208 /// sets the deployment target) determines the version in the triple passed to 00209 /// Clang. 00210 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args, 00211 types::ID InputType = types::TY_INVALID) const; 00212 00213 /// configureObjCRuntime - Configure the known properties of the 00214 /// Objective-C runtime for this platform. 00215 /// 00216 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction 00217 virtual void configureObjCRuntime(ObjCRuntime &runtime) const; 00218 00219 /// hasBlocksRuntime - Given that the user is compiling with 00220 /// -fblocks, does this tool chain guarantee the existence of a 00221 /// blocks runtime? 00222 /// 00223 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction 00224 virtual bool hasBlocksRuntime() const { return true; } 00225 00226 /// \brief Add the clang cc1 arguments for system include paths. 00227 /// 00228 /// This routine is responsible for adding the necessary cc1 arguments to 00229 /// include headers from standard system header directories. 00230 virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs, 00231 ArgStringList &CC1Args) const; 00232 00233 // GetRuntimeLibType - Determine the runtime library type to use with the 00234 // given compilation arguments. 00235 virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const; 00236 00237 // GetCXXStdlibType - Determine the C++ standard library type to use with the 00238 // given compilation arguments. 00239 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const; 00240 00241 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set 00242 /// the include paths to use for the given C++ standard library type. 00243 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, 00244 ArgStringList &CC1Args) const; 00245 00246 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use 00247 /// for the given C++ standard library type. 00248 virtual void AddCXXStdlibLibArgs(const ArgList &Args, 00249 ArgStringList &CmdArgs) const; 00250 00251 /// AddCCKextLibArgs - Add the system specific linker arguments to use 00252 /// for kernel extensions (Darwin-specific). 00253 virtual void AddCCKextLibArgs(const ArgList &Args, 00254 ArgStringList &CmdArgs) const; 00255 }; 00256 00257 } // end namespace driver 00258 } // end namespace clang 00259 00260 #endif