1 //===--- ToolChain.h - Collections of tools for one platform ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_DRIVER_TOOLCHAIN_H_
11 #define CLANG_DRIVER_TOOLCHAIN_H_
13 #include "clang/Driver/Action.h"
14 #include "clang/Driver/Types.h"
15 #include "clang/Driver/Util.h"
16 #include "llvm/ADT/OwningPtr.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Path.h"
40 /// ToolChain - Access to tools for a single platform.
43 typedef SmallVector<std::string, 4> path_list;
57 const llvm::Triple Triple;
58 const llvm::opt::ArgList &Args;
60 /// The list of toolchain specific path prefixes to search for
64 /// The list of toolchain specific path prefixes to search for
66 path_list ProgramPaths;
68 mutable OwningPtr<Tool> Clang;
69 mutable OwningPtr<Tool> Assemble;
70 mutable OwningPtr<Tool> Link;
71 Tool *getClang() const;
72 Tool *getAssemble() const;
73 Tool *getLink() const;
74 Tool *getClangAs() const;
76 mutable OwningPtr<SanitizerArgs> SanitizerArguments;
79 ToolChain(const Driver &D, const llvm::Triple &T,
80 const llvm::opt::ArgList &Args);
82 virtual Tool *buildAssembler() const;
83 virtual Tool *buildLinker() const;
84 virtual Tool *getTool(Action::ActionClass AC) const;
86 /// \name Utilities for implementing subclasses.
88 static void addSystemInclude(const llvm::opt::ArgList &DriverArgs,
89 llvm::opt::ArgStringList &CC1Args,
91 static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs,
92 llvm::opt::ArgStringList &CC1Args,
95 addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs,
96 llvm::opt::ArgStringList &CC1Args,
98 static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs,
99 llvm::opt::ArgStringList &CC1Args,
100 ArrayRef<StringRef> Paths);
104 virtual ~ToolChain();
108 const Driver &getDriver() const;
109 const llvm::Triple &getTriple() const { return Triple; }
111 llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
112 StringRef getArchName() const { return Triple.getArchName(); }
113 StringRef getPlatform() const { return Triple.getVendorName(); }
114 StringRef getOS() const { return Triple.getOSName(); }
116 /// \brief Provide the default architecture name (as expected by -arch) for
117 /// this toolchain. Note t
118 std::string getDefaultUniversalArchName() const;
120 std::string getTripleString() const {
121 return Triple.getTriple();
124 path_list &getFilePaths() { return FilePaths; }
125 const path_list &getFilePaths() const { return FilePaths; }
127 path_list &getProgramPaths() { return ProgramPaths; }
128 const path_list &getProgramPaths() const { return ProgramPaths; }
130 const SanitizerArgs& getSanitizerArgs() const;
134 /// TranslateArgs - Create a new derived argument list for any argument
135 /// translations this ToolChain may wish to perform, or 0 if no tool chain
136 /// specific translations are needed.
138 /// \param BoundArch - The bound architecture name, or 0.
139 virtual llvm::opt::DerivedArgList *
140 TranslateArgs(const llvm::opt::DerivedArgList &Args,
141 const char *BoundArch) const {
145 /// Choose a tool to use to handle the action \p JA.
146 Tool *SelectTool(const JobAction &JA) const;
150 std::string GetFilePath(const char *Name) const;
151 std::string GetProgramPath(const char *Name) const;
153 /// Returns the linker path, respecting the -fuse-ld= argument to determine
154 /// the linker suffix or name.
155 std::string GetLinkerPath() const;
157 /// \brief Dispatch to the specific toolchain for verbose printing.
159 /// This is used when handling the verbose option to print detailed,
160 /// toolchain-specific information useful for understanding the behavior of
161 /// the driver on a specific platform.
162 virtual void printVerboseInfo(raw_ostream &OS) const {};
164 // Platform defaults information
166 /// HasNativeLTOLinker - Check whether the linker and related tools have
167 /// native LLVM support.
168 virtual bool HasNativeLLVMSupport() const;
170 /// LookupTypeForExtension - Return the default language type to use for the
172 virtual types::ID LookupTypeForExtension(const char *Ext) const;
174 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
175 virtual bool IsBlocksDefault() const { return false; }
177 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
179 virtual bool IsIntegratedAssemblerDefault() const { return false; }
181 /// \brief Check if the toolchain should use the integrated assembler.
182 bool useIntegratedAs() const;
184 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
185 virtual bool IsMathErrnoDefault() const { return true; }
187 /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
188 /// -fencode-extended-block-signature by default.
189 virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
191 /// IsObjCNonFragileABIDefault - Does this tool chain set
192 /// -fobjc-nonfragile-abi by default.
193 virtual bool IsObjCNonFragileABIDefault() const { return false; }
195 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
196 /// mixed dispatch method be used?
197 virtual bool UseObjCMixedDispatch() const { return false; }
199 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
200 /// this tool chain (0=off, 1=on, 2=all).
201 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
205 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
206 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
207 return ToolChain::RLT_Libgcc;
210 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
212 virtual bool IsUnwindTablesDefault() const;
214 /// \brief Test whether this toolchain defaults to PIC.
215 virtual bool isPICDefault() const = 0;
217 /// \brief Test whether this toolchain defaults to PIE.
218 virtual bool isPIEDefault() const = 0;
220 /// \brief Tests whether this toolchain forces its default for PIC, PIE or
221 /// non-PIC. If this returns true, any PIC related flags should be ignored
222 /// and instead the results of \c isPICDefault() and \c isPIEDefault() are
223 /// used exclusively.
224 virtual bool isPICDefaultForced() const = 0;
226 /// SupportsProfiling - Does this tool chain support -pg.
227 virtual bool SupportsProfiling() const { return true; }
229 /// Does this tool chain support Objective-C garbage collection.
230 virtual bool SupportsObjCGC() const { return true; }
232 /// Complain if this tool chain doesn't support Objective-C ARC.
233 virtual void CheckObjCARC() const {}
235 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
236 /// compile unit information.
237 virtual bool UseDwarfDebugFlags() const { return false; }
239 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
240 virtual bool UseSjLjExceptions() const { return false; }
242 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
243 /// command line arguments into account.
245 ComputeLLVMTriple(const llvm::opt::ArgList &Args,
246 types::ID InputType = types::TY_INVALID) const;
248 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
249 /// target, which may take into account the command line arguments. For
250 /// example, on Darwin the -mmacosx-version-min= command line argument (which
251 /// sets the deployment target) determines the version in the triple passed to
253 virtual std::string ComputeEffectiveClangTriple(
254 const llvm::opt::ArgList &Args,
255 types::ID InputType = types::TY_INVALID) const;
257 /// getDefaultObjCRuntime - Return the default Objective-C runtime
258 /// for this platform.
260 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
261 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
263 /// hasBlocksRuntime - Given that the user is compiling with
264 /// -fblocks, does this tool chain guarantee the existence of a
267 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
268 virtual bool hasBlocksRuntime() const { return true; }
270 /// \brief Add the clang cc1 arguments for system include paths.
272 /// This routine is responsible for adding the necessary cc1 arguments to
273 /// include headers from standard system header directories.
275 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
276 llvm::opt::ArgStringList &CC1Args) const;
278 /// \brief Add options that need to be passed to cc1 for this target.
279 virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
280 llvm::opt::ArgStringList &CC1Args) const;
282 // GetRuntimeLibType - Determine the runtime library type to use with the
283 // given compilation arguments.
284 virtual RuntimeLibType
285 GetRuntimeLibType(const llvm::opt::ArgList &Args) const;
287 // GetCXXStdlibType - Determine the C++ standard library type to use with the
288 // given compilation arguments.
289 virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
291 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
292 /// the include paths to use for the given C++ standard library type.
294 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
295 llvm::opt::ArgStringList &CC1Args) const;
297 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
298 /// for the given C++ standard library type.
299 virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
300 llvm::opt::ArgStringList &CmdArgs) const;
302 /// AddCCKextLibArgs - Add the system specific linker arguments to use
303 /// for kernel extensions (Darwin-specific).
304 virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
305 llvm::opt::ArgStringList &CmdArgs) const;
307 /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
308 /// global flags for unsafe floating point math, add it and return true.
310 /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
312 AddFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args,
313 llvm::opt::ArgStringList &CmdArgs) const;
316 } // end namespace driver
317 } // end namespace clang