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/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"
32 /// ToolChain - Access to tools for a single platform.
35 typedef SmallVector<std::string, 4> path_list;
49 const llvm::Triple Triple;
51 /// The list of toolchain specific path prefixes to search for
55 /// The list of toolchain specific path prefixes to search for
57 path_list ProgramPaths;
60 ToolChain(const Driver &D, const llvm::Triple &T);
62 /// \name Utilities for implementing subclasses.
64 static void addSystemInclude(const ArgList &DriverArgs,
65 ArgStringList &CC1Args,
67 static void addExternCSystemInclude(const ArgList &DriverArgs,
68 ArgStringList &CC1Args,
70 static void addSystemIncludes(const ArgList &DriverArgs,
71 ArgStringList &CC1Args,
72 ArrayRef<StringRef> Paths);
80 const Driver &getDriver() const;
81 const llvm::Triple &getTriple() const { return Triple; }
83 llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
84 StringRef getArchName() const { return Triple.getArchName(); }
85 StringRef getPlatform() const { return Triple.getVendorName(); }
86 StringRef getOS() const { return Triple.getOSName(); }
88 /// \brief Provide the default architecture name (as expected by -arch) for
89 /// this toolchain. Note t
90 std::string getDefaultUniversalArchName() const;
92 std::string getTripleString() const {
93 return Triple.getTriple();
96 path_list &getFilePaths() { return FilePaths; }
97 const path_list &getFilePaths() const { return FilePaths; }
99 path_list &getProgramPaths() { return ProgramPaths; }
100 const path_list &getProgramPaths() const { return ProgramPaths; }
104 /// TranslateArgs - Create a new derived argument list for any argument
105 /// translations this ToolChain may wish to perform, or 0 if no tool chain
106 /// specific translations are needed.
108 /// \param BoundArch - The bound architecture name, or 0.
109 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
110 const char *BoundArch) const {
114 /// SelectTool - Choose a tool to use to handle the action \p JA with the
116 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
117 const ActionList &Inputs) const = 0;
121 std::string GetFilePath(const char *Name) const;
122 std::string GetProgramPath(const char *Name) const;
124 // Platform defaults information
126 /// HasNativeLTOLinker - Check whether the linker and related tools have
127 /// native LLVM support.
128 virtual bool HasNativeLLVMSupport() const;
130 /// LookupTypeForExtension - Return the default language type to use for the
132 virtual types::ID LookupTypeForExtension(const char *Ext) const;
134 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
135 virtual bool IsBlocksDefault() const { return false; }
137 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
139 virtual bool IsIntegratedAssemblerDefault() const { return false; }
141 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
143 virtual bool IsStrictAliasingDefault() const { return true; }
145 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
146 virtual bool IsMathErrnoDefault() const { return true; }
148 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
149 /// -fobjc-default-synthesize-properties by default.
150 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
152 /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
153 /// -fencode-extended-block-signature by default.
154 virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
156 /// IsObjCNonFragileABIDefault - Does this tool chain set
157 /// -fobjc-nonfragile-abi by default.
158 virtual bool IsObjCNonFragileABIDefault() const { return false; }
160 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
161 /// mixed dispatch method be used?
162 virtual bool UseObjCMixedDispatch() const { return false; }
164 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
165 /// this tool chain (0=off, 1=on, 2=all).
166 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
170 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
171 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
172 return ToolChain::RLT_Libgcc;
175 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
177 virtual bool IsUnwindTablesDefault() const;
179 /// \brief Test whether this toolchain defaults to PIC.
180 virtual bool isPICDefault() const = 0;
182 /// \brief Tests whether this toolchain forces its default for PIC or non-PIC.
183 /// If this returns true, any PIC related flags should be ignored and instead
184 /// the result of \c isPICDefault() is used exclusively.
185 virtual bool isPICDefaultForced() const = 0;
187 /// SupportsProfiling - Does this tool chain support -pg.
188 virtual bool SupportsProfiling() const { return true; }
190 /// Does this tool chain support Objective-C garbage collection.
191 virtual bool SupportsObjCGC() const { return true; }
193 /// Complain if this tool chain doesn't support Objective-C ARC.
194 virtual void CheckObjCARC() const {}
196 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
197 /// compile unit information.
198 virtual bool UseDwarfDebugFlags() const { return false; }
200 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
201 virtual bool UseSjLjExceptions() const { return false; }
203 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
204 /// command line arguments into account.
205 virtual std::string ComputeLLVMTriple(const ArgList &Args,
206 types::ID InputType = types::TY_INVALID) const;
208 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
209 /// target, which may take into account the command line arguments. For
210 /// example, on Darwin the -mmacosx-version-min= command line argument (which
211 /// sets the deployment target) determines the version in the triple passed to
213 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
214 types::ID InputType = types::TY_INVALID) const;
216 /// getDefaultObjCRuntime - Return the default Objective-C runtime
217 /// for this platform.
219 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
220 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
222 /// hasBlocksRuntime - Given that the user is compiling with
223 /// -fblocks, does this tool chain guarantee the existence of a
226 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
227 virtual bool hasBlocksRuntime() const { return true; }
229 /// \brief Add the clang cc1 arguments for system include paths.
231 /// This routine is responsible for adding the necessary cc1 arguments to
232 /// include headers from standard system header directories.
233 virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
234 ArgStringList &CC1Args) const;
236 // addClangTargetOptions - Add options that need to be passed to cc1 for
238 virtual void addClangTargetOptions(ArgStringList &CC1Args) const;
240 // GetRuntimeLibType - Determine the runtime library type to use with the
241 // given compilation arguments.
242 virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const;
244 // GetCXXStdlibType - Determine the C++ standard library type to use with the
245 // given compilation arguments.
246 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
248 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
249 /// the include paths to use for the given C++ standard library type.
250 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
251 ArgStringList &CC1Args) const;
253 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
254 /// for the given C++ standard library type.
255 virtual void AddCXXStdlibLibArgs(const ArgList &Args,
256 ArgStringList &CmdArgs) const;
258 /// AddCCKextLibArgs - Add the system specific linker arguments to use
259 /// for kernel extensions (Darwin-specific).
260 virtual void AddCCKextLibArgs(const ArgList &Args,
261 ArgStringList &CmdArgs) const;
263 /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
264 /// global flags for unsafe floating point math, add it and return true.
266 /// This checks for presence of the -ffast-math or -funsafe-math flags.
267 virtual bool AddFastMathRuntimeIfAvailable(const ArgList &Args,
268 ArgStringList &CmdArgs) const;
271 } // end namespace driver
272 } // end namespace clang