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"
34 /// ToolChain - Access to tools for a single platform.
37 typedef SmallVector<std::string, 4> path_list;
51 const llvm::Triple Triple;
54 /// The list of toolchain specific path prefixes to search for
58 /// The list of toolchain specific path prefixes to search for
60 path_list ProgramPaths;
62 mutable OwningPtr<Tool> Clang;
63 mutable OwningPtr<Tool> Assemble;
64 mutable OwningPtr<Tool> Link;
65 Tool *getClang() const;
66 Tool *getAssemble() const;
67 Tool *getLink() const;
68 Tool *getClangAs() const;
71 ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args);
73 virtual Tool *buildAssembler() const;
74 virtual Tool *buildLinker() const;
75 virtual Tool *getTool(Action::ActionClass AC) const;
77 /// \name Utilities for implementing subclasses.
79 static void addSystemInclude(const ArgList &DriverArgs,
80 ArgStringList &CC1Args,
82 static void addExternCSystemInclude(const ArgList &DriverArgs,
83 ArgStringList &CC1Args,
85 static void addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
86 ArgStringList &CC1Args,
88 static void addSystemIncludes(const ArgList &DriverArgs,
89 ArgStringList &CC1Args,
90 ArrayRef<StringRef> Paths);
98 const Driver &getDriver() const;
99 const llvm::Triple &getTriple() const { return Triple; }
101 llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
102 StringRef getArchName() const { return Triple.getArchName(); }
103 StringRef getPlatform() const { return Triple.getVendorName(); }
104 StringRef getOS() const { return Triple.getOSName(); }
106 /// \brief Provide the default architecture name (as expected by -arch) for
107 /// this toolchain. Note t
108 std::string getDefaultUniversalArchName() const;
110 std::string getTripleString() const {
111 return Triple.getTriple();
114 path_list &getFilePaths() { return FilePaths; }
115 const path_list &getFilePaths() const { return FilePaths; }
117 path_list &getProgramPaths() { return ProgramPaths; }
118 const path_list &getProgramPaths() const { return ProgramPaths; }
122 /// TranslateArgs - Create a new derived argument list for any argument
123 /// translations this ToolChain may wish to perform, or 0 if no tool chain
124 /// specific translations are needed.
126 /// \param BoundArch - The bound architecture name, or 0.
127 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
128 const char *BoundArch) const {
132 /// Choose a tool to use to handle the action \p JA.
133 Tool *SelectTool(const JobAction &JA) const;
137 std::string GetFilePath(const char *Name) const;
138 std::string GetProgramPath(const char *Name) const;
140 // Platform defaults information
142 /// HasNativeLTOLinker - Check whether the linker and related tools have
143 /// native LLVM support.
144 virtual bool HasNativeLLVMSupport() const;
146 /// LookupTypeForExtension - Return the default language type to use for the
148 virtual types::ID LookupTypeForExtension(const char *Ext) const;
150 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
151 virtual bool IsBlocksDefault() const { return false; }
153 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
155 virtual bool IsIntegratedAssemblerDefault() const { return false; }
157 /// \brief Check if the toolchain should use the integrated assembler.
158 bool useIntegratedAs() const;
160 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
162 virtual bool IsStrictAliasingDefault() const { return true; }
164 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
165 virtual bool IsMathErrnoDefault() const { return true; }
167 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
168 /// -fobjc-default-synthesize-properties by default.
169 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return true; }
171 /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
172 /// -fencode-extended-block-signature by default.
173 virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
175 /// IsObjCNonFragileABIDefault - Does this tool chain set
176 /// -fobjc-nonfragile-abi by default.
177 virtual bool IsObjCNonFragileABIDefault() const { return false; }
179 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
180 /// mixed dispatch method be used?
181 virtual bool UseObjCMixedDispatch() const { return false; }
183 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
184 /// this tool chain (0=off, 1=on, 2=all).
185 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
189 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
190 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
191 return ToolChain::RLT_Libgcc;
194 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
196 virtual bool IsUnwindTablesDefault() const;
198 /// \brief Test whether this toolchain defaults to PIC.
199 virtual bool isPICDefault() const = 0;
201 /// \brief Test whether this toolchain defaults to PIE.
202 virtual bool isPIEDefault() const = 0;
204 /// \brief Tests whether this toolchain forces its default for PIC, PIE or
205 /// non-PIC. If this returns true, any PIC related flags should be ignored
206 /// and instead the results of \c isPICDefault() and \c isPIEDefault() are
207 /// used exclusively.
208 virtual bool isPICDefaultForced() const = 0;
210 /// SupportsProfiling - Does this tool chain support -pg.
211 virtual bool SupportsProfiling() const { return true; }
213 /// Does this tool chain support Objective-C garbage collection.
214 virtual bool SupportsObjCGC() const { return true; }
216 /// Complain if this tool chain doesn't support Objective-C ARC.
217 virtual void CheckObjCARC() const {}
219 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
220 /// compile unit information.
221 virtual bool UseDwarfDebugFlags() const { return false; }
223 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
224 virtual bool UseSjLjExceptions() const { return false; }
226 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
227 /// command line arguments into account.
228 virtual std::string ComputeLLVMTriple(const ArgList &Args,
229 types::ID InputType = types::TY_INVALID) const;
231 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
232 /// target, which may take into account the command line arguments. For
233 /// example, on Darwin the -mmacosx-version-min= command line argument (which
234 /// sets the deployment target) determines the version in the triple passed to
236 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
237 types::ID InputType = types::TY_INVALID) const;
239 /// getDefaultObjCRuntime - Return the default Objective-C runtime
240 /// for this platform.
242 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
243 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
245 /// hasBlocksRuntime - Given that the user is compiling with
246 /// -fblocks, does this tool chain guarantee the existence of a
249 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
250 virtual bool hasBlocksRuntime() const { return true; }
252 /// \brief Add the clang cc1 arguments for system include paths.
254 /// This routine is responsible for adding the necessary cc1 arguments to
255 /// include headers from standard system header directories.
256 virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
257 ArgStringList &CC1Args) const;
259 /// \brief Add options that need to be passed to cc1 for this target.
260 virtual void addClangTargetOptions(const ArgList &DriverArgs,
261 ArgStringList &CC1Args) const;
263 // GetRuntimeLibType - Determine the runtime library type to use with the
264 // given compilation arguments.
265 virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const;
267 // GetCXXStdlibType - Determine the C++ standard library type to use with the
268 // given compilation arguments.
269 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
271 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
272 /// the include paths to use for the given C++ standard library type.
273 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
274 ArgStringList &CC1Args) const;
276 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
277 /// for the given C++ standard library type.
278 virtual void AddCXXStdlibLibArgs(const ArgList &Args,
279 ArgStringList &CmdArgs) const;
281 /// AddCCKextLibArgs - Add the system specific linker arguments to use
282 /// for kernel extensions (Darwin-specific).
283 virtual void AddCCKextLibArgs(const ArgList &Args,
284 ArgStringList &CmdArgs) const;
286 /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
287 /// global flags for unsafe floating point math, add it and return true.
289 /// This checks for presence of the -ffast-math or -funsafe-math flags.
290 virtual bool AddFastMathRuntimeIfAvailable(const ArgList &Args,
291 ArgStringList &CmdArgs) const;
294 } // end namespace driver
295 } // end namespace clang