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 /// \brief Dispatch to the specific toolchain for verbose printing.
155 /// This is used when handling the verbose option to print detailed,
156 /// toolchain-specific information useful for understanding the behavior of
157 /// the driver on a specific platform.
158 virtual void printVerboseInfo(raw_ostream &OS) const {};
160 // Platform defaults information
162 /// HasNativeLTOLinker - Check whether the linker and related tools have
163 /// native LLVM support.
164 virtual bool HasNativeLLVMSupport() const;
166 /// LookupTypeForExtension - Return the default language type to use for the
168 virtual types::ID LookupTypeForExtension(const char *Ext) const;
170 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
171 virtual bool IsBlocksDefault() const { return false; }
173 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
175 virtual bool IsIntegratedAssemblerDefault() const { return false; }
177 /// \brief Check if the toolchain should use the integrated assembler.
178 bool useIntegratedAs() const;
180 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
181 virtual bool IsMathErrnoDefault() const { return true; }
183 /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
184 /// -fencode-extended-block-signature by default.
185 virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
187 /// IsObjCNonFragileABIDefault - Does this tool chain set
188 /// -fobjc-nonfragile-abi by default.
189 virtual bool IsObjCNonFragileABIDefault() const { return false; }
191 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
192 /// mixed dispatch method be used?
193 virtual bool UseObjCMixedDispatch() const { return false; }
195 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
196 /// this tool chain (0=off, 1=on, 2=all).
197 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
201 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
202 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
203 return ToolChain::RLT_Libgcc;
206 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
208 virtual bool IsUnwindTablesDefault() const;
210 /// \brief Test whether this toolchain defaults to PIC.
211 virtual bool isPICDefault() const = 0;
213 /// \brief Test whether this toolchain defaults to PIE.
214 virtual bool isPIEDefault() const = 0;
216 /// \brief Tests whether this toolchain forces its default for PIC, PIE or
217 /// non-PIC. If this returns true, any PIC related flags should be ignored
218 /// and instead the results of \c isPICDefault() and \c isPIEDefault() are
219 /// used exclusively.
220 virtual bool isPICDefaultForced() const = 0;
222 /// SupportsProfiling - Does this tool chain support -pg.
223 virtual bool SupportsProfiling() const { return true; }
225 /// Does this tool chain support Objective-C garbage collection.
226 virtual bool SupportsObjCGC() const { return true; }
228 /// Complain if this tool chain doesn't support Objective-C ARC.
229 virtual void CheckObjCARC() const {}
231 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
232 /// compile unit information.
233 virtual bool UseDwarfDebugFlags() const { return false; }
235 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
236 virtual bool UseSjLjExceptions() const { return false; }
238 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
239 /// command line arguments into account.
241 ComputeLLVMTriple(const llvm::opt::ArgList &Args,
242 types::ID InputType = types::TY_INVALID) const;
244 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
245 /// target, which may take into account the command line arguments. For
246 /// example, on Darwin the -mmacosx-version-min= command line argument (which
247 /// sets the deployment target) determines the version in the triple passed to
249 virtual std::string ComputeEffectiveClangTriple(
250 const llvm::opt::ArgList &Args,
251 types::ID InputType = types::TY_INVALID) const;
253 /// getDefaultObjCRuntime - Return the default Objective-C runtime
254 /// for this platform.
256 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
257 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
259 /// hasBlocksRuntime - Given that the user is compiling with
260 /// -fblocks, does this tool chain guarantee the existence of a
263 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
264 virtual bool hasBlocksRuntime() const { return true; }
266 /// \brief Add the clang cc1 arguments for system include paths.
268 /// This routine is responsible for adding the necessary cc1 arguments to
269 /// include headers from standard system header directories.
271 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
272 llvm::opt::ArgStringList &CC1Args) const;
274 /// \brief Add options that need to be passed to cc1 for this target.
275 virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
276 llvm::opt::ArgStringList &CC1Args) const;
278 // GetRuntimeLibType - Determine the runtime library type to use with the
279 // given compilation arguments.
280 virtual RuntimeLibType
281 GetRuntimeLibType(const llvm::opt::ArgList &Args) const;
283 // GetCXXStdlibType - Determine the C++ standard library type to use with the
284 // given compilation arguments.
285 virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
287 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
288 /// the include paths to use for the given C++ standard library type.
290 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
291 llvm::opt::ArgStringList &CC1Args) const;
293 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
294 /// for the given C++ standard library type.
295 virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
296 llvm::opt::ArgStringList &CmdArgs) const;
298 /// AddCCKextLibArgs - Add the system specific linker arguments to use
299 /// for kernel extensions (Darwin-specific).
300 virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
301 llvm::opt::ArgStringList &CmdArgs) const;
303 /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
304 /// global flags for unsafe floating point math, add it and return true.
306 /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
308 AddFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args,
309 llvm::opt::ArgStringList &CmdArgs) const;
312 } // end namespace driver
313 } // end namespace clang