Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 641b98b | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Util.h" |
Daniel Dunbar | 4180011 | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Types.h" |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/Triple.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Path.h" |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 18 | #include <string> |
| 19 | |
| 20 | namespace clang { |
| 21 | namespace driver { |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 22 | class ArgList; |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 23 | class Compilation; |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 24 | class DerivedArgList; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 25 | class Driver; |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame] | 26 | class HostInfo; |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 27 | class InputArgList; |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 28 | class JobAction; |
| 29 | class Tool; |
| 30 | |
| 31 | /// ToolChain - Access to tools for a single platform. |
| 32 | class ToolChain { |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 33 | public: |
| 34 | typedef llvm::SmallVector<std::string, 4> path_list; |
| 35 | |
Daniel Dunbar | 641b98b | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 36 | enum CXXStdlibType { |
Daniel Dunbar | 3f16c95 | 2010-09-14 23:12:40 +0000 | [diff] [blame] | 37 | CST_Libcxx, |
Daniel Dunbar | 641b98b | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 38 | CST_Libstdcxx |
| 39 | }; |
| 40 | |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 41 | private: |
Daniel Dunbar | fa0cda4 | 2009-03-17 21:21:26 +0000 | [diff] [blame] | 42 | const HostInfo &Host; |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 43 | const llvm::Triple Triple; |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 44 | |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 53 | protected: |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 54 | ToolChain(const HostInfo &Host, const llvm::Triple &_Triple); |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 55 | |
| 56 | public: |
| 57 | virtual ~ToolChain(); |
| 58 | |
| 59 | // Accessors |
| 60 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 61 | const Driver &getDriver() const; |
Daniel Dunbar | 12cfe03 | 2009-06-16 23:25:22 +0000 | [diff] [blame] | 62 | const llvm::Triple &getTriple() const { return Triple; } |
| 63 | |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 64 | llvm::Triple::ArchType getArch() const { return Triple.getArch(); } |
Benjamin Kramer | f22d1fd | 2010-01-30 15:01:47 +0000 | [diff] [blame] | 65 | llvm::StringRef getArchName() const { return Triple.getArchName(); } |
| 66 | llvm::StringRef getPlatform() const { return Triple.getVendorName(); } |
| 67 | llvm::StringRef getOS() const { return Triple.getOSName(); } |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 68 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 69 | std::string getTripleString() const { |
| 70 | return Triple.getTriple(); |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Daniel Dunbar | bbafc5c | 2009-03-20 04:36:45 +0000 | [diff] [blame] | 73 | path_list &getFilePaths() { return FilePaths; } |
| 74 | const path_list &getFilePaths() const { return FilePaths; } |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 75 | |
Daniel Dunbar | bbafc5c | 2009-03-20 04:36:45 +0000 | [diff] [blame] | 76 | path_list &getProgramPaths() { return ProgramPaths; } |
| 77 | const path_list &getProgramPaths() const { return ProgramPaths; } |
Daniel Dunbar | 0edefeb | 2009-03-18 20:26:19 +0000 | [diff] [blame] | 78 | |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 79 | // Tool access. |
| 80 | |
Daniel Dunbar | 0dcb9a3 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 81 | /// TranslateArgs - Create a new derived argument list for any argument |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 82 | /// translations this ToolChain may wish to perform, or 0 if no tool chain |
| 83 | /// specific translations are needed. |
Daniel Dunbar | 0dcb9a3 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 84 | /// |
| 85 | /// \param BoundArch - The bound architecture name, or 0. |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 86 | virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args, |
| 87 | const char *BoundArch) const { |
| 88 | return 0; |
| 89 | } |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 96 | std::string GetFilePath(const char *Name) const; |
| 97 | std::string GetProgramPath(const char *Name, bool WantFile = false) const; |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 98 | |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 99 | // Platform defaults information |
| 100 | |
Daniel Dunbar | b993f5d | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 101 | /// HasNativeLTOLinker - Check whether the linker and related tools have |
| 102 | /// native LLVM support. |
| 103 | virtual bool HasNativeLLVMSupport() const; |
| 104 | |
Daniel Dunbar | 4180011 | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 105 | /// LookupTypeForExtension - Return the default language type to use for the |
| 106 | /// given extension. |
| 107 | virtual types::ID LookupTypeForExtension(const char *Ext) const; |
| 108 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 109 | /// IsBlocksDefault - Does this tool chain enable -fblocks by default. |
| 110 | virtual bool IsBlocksDefault() const { return false; } |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame^] | 111 | |
Daniel Dunbar | 8767cbc | 2010-02-03 03:07:56 +0000 | [diff] [blame] | 112 | /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as |
| 113 | /// by default. |
| 114 | virtual bool IsIntegratedAssemblerDefault() const { return false; } |
| 115 | |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame^] | 116 | /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable |
| 117 | /// -fobjc-default-synthesize-properties by default. |
| 118 | virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; } |
| 119 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 120 | /// IsObjCNonFragileABIDefault - Does this tool chain set |
| 121 | /// -fobjc-nonfragile-abi by default. |
| 122 | virtual bool IsObjCNonFragileABIDefault() const { return false; } |
| 123 | |
Daniel Dunbar | 609508c | 2010-02-01 21:07:43 +0000 | [diff] [blame] | 124 | /// IsObjCLegacyDispatchDefault - Does this tool chain set |
| 125 | /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile |
| 126 | /// ABI). |
| 127 | virtual bool IsObjCLegacyDispatchDefault() const { return false; } |
| 128 | |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 129 | /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the |
| 130 | /// mixed dispatch method be used? |
| 131 | virtual bool UseObjCMixedDispatch() const { return false; } |
| 132 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 133 | /// GetDefaultStackProtectorLevel - Get the default stack protector level for |
| 134 | /// this tool chain (0=off, 1=on, 2=all). |
| 135 | virtual unsigned GetDefaultStackProtectorLevel() const { return 0; } |
| 136 | |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 137 | /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables |
| 138 | /// by default. |
| 139 | virtual bool IsUnwindTablesDefault() const = 0; |
| 140 | |
| 141 | /// GetDefaultRelocationModel - Return the LLVM name of the default |
| 142 | /// relocation model for this tool chain. |
| 143 | virtual const char *GetDefaultRelocationModel() const = 0; |
| 144 | |
| 145 | /// GetForcedPicModel - Return the LLVM name of the forced PIC model |
| 146 | /// for this tool chain, or 0 if this tool chain does not force a |
| 147 | /// particular PIC mode. |
| 148 | virtual const char *GetForcedPicModel() const = 0; |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 149 | |
Daniel Dunbar | 43a9b32 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 150 | /// Does this tool chain support Objective-C garbage collection. |
| 151 | virtual bool SupportsObjCGC() const { return false; } |
| 152 | |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 153 | /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf |
| 154 | /// compile unit information. |
| 155 | virtual bool UseDwarfDebugFlags() const { return false; } |
Daniel Dunbar | b2987d1 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 156 | |
| 157 | /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. |
Benjamin Kramer | 8aa7994 | 2010-02-11 11:33:47 +0000 | [diff] [blame] | 158 | virtual bool UseSjLjExceptions() const { return false; } |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 159 | |
| 160 | /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking |
| 161 | /// command line arguments into account. |
| 162 | virtual std::string ComputeLLVMTriple(const ArgList &Args) const; |
| 163 | |
| 164 | /// ComputeEffectiveClangTriple - Return the Clang triple to use for this |
| 165 | /// target, which may take into account the command line arguments. For |
| 166 | /// example, on Darwin the -mmacosx-version-min= command line argument (which |
| 167 | /// sets the deployment target) determines the version in the triple passed to |
| 168 | /// Clang. |
| 169 | virtual std::string ComputeEffectiveClangTriple(const ArgList &Args) const; |
Daniel Dunbar | 641b98b | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 170 | |
| 171 | // GetCXXStdlibType - Determine the C++ standard library type to use with the |
| 172 | // given compilation arguments. |
| 173 | virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const; |
| 174 | |
| 175 | /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set |
| 176 | /// the include paths to use for the given C++ standard library type. |
| 177 | virtual void AddClangCXXStdlibIncludeArgs(const ArgList &Args, |
| 178 | ArgStringList &CmdArgs) const; |
| 179 | |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 180 | /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use |
Daniel Dunbar | 641b98b | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 181 | /// for the given C++ standard library type. |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 182 | virtual void AddCXXStdlibLibArgs(const ArgList &Args, |
| 183 | ArgStringList &CmdArgs) const; |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 184 | |
| 185 | /// AddCCKextLibArgs - Add the system specific linker arguments to use |
| 186 | /// for kernel extensions (Darwin-specific). |
| 187 | virtual void AddCCKextLibArgs(const ArgList &Args, |
| 188 | ArgStringList &CmdArgs) const; |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | } // end namespace driver |
| 192 | } // end namespace clang |
| 193 | |
| 194 | #endif |