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 addSystemIncludes(const ArgList &DriverArgs,
86 ArgStringList &CC1Args,
87 ArrayRef<StringRef> Paths);
95 const Driver &getDriver() const;
96 const llvm::Triple &getTriple() const { return Triple; }
98 llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
99 StringRef getArchName() const { return Triple.getArchName(); }
100 StringRef getPlatform() const { return Triple.getVendorName(); }
101 StringRef getOS() const { return Triple.getOSName(); }
103 /// \brief Provide the default architecture name (as expected by -arch) for
104 /// this toolchain. Note t
105 std::string getDefaultUniversalArchName() const;
107 std::string getTripleString() const {
108 return Triple.getTriple();
111 path_list &getFilePaths() { return FilePaths; }
112 const path_list &getFilePaths() const { return FilePaths; }
114 path_list &getProgramPaths() { return ProgramPaths; }
115 const path_list &getProgramPaths() const { return ProgramPaths; }
119 /// TranslateArgs - Create a new derived argument list for any argument
120 /// translations this ToolChain may wish to perform, or 0 if no tool chain
121 /// specific translations are needed.
123 /// \param BoundArch - The bound architecture name, or 0.
124 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
125 const char *BoundArch) const {
129 /// Choose a tool to use to handle the action \p JA.
130 Tool *SelectTool(const JobAction &JA) const;
134 std::string GetFilePath(const char *Name) const;
135 std::string GetProgramPath(const char *Name) const;
137 // Platform defaults information
139 /// HasNativeLTOLinker - Check whether the linker and related tools have
140 /// native LLVM support.
141 virtual bool HasNativeLLVMSupport() const;
143 /// LookupTypeForExtension - Return the default language type to use for the
145 virtual types::ID LookupTypeForExtension(const char *Ext) const;
147 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
148 virtual bool IsBlocksDefault() const { return false; }
150 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
152 virtual bool IsIntegratedAssemblerDefault() const { return false; }
154 /// \brief Check if the toolchain should use the integrated assembler.
155 bool useIntegratedAs() const;
157 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
159 virtual bool IsStrictAliasingDefault() const { return true; }
161 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
162 virtual bool IsMathErrnoDefault() const { return true; }
164 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
165 /// -fobjc-default-synthesize-properties by default.
166 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return true; }
168 /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
169 /// -fencode-extended-block-signature by default.
170 virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
172 /// IsObjCNonFragileABIDefault - Does this tool chain set
173 /// -fobjc-nonfragile-abi by default.
174 virtual bool IsObjCNonFragileABIDefault() const { return false; }
176 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
177 /// mixed dispatch method be used?
178 virtual bool UseObjCMixedDispatch() const { return false; }
180 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
181 /// this tool chain (0=off, 1=on, 2=all).
182 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
186 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
187 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
188 return ToolChain::RLT_Libgcc;
191 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
193 virtual bool IsUnwindTablesDefault() const;
195 /// \brief Test whether this toolchain defaults to PIC.
196 virtual bool isPICDefault() const = 0;
198 /// \brief Tests whether this toolchain forces its default for PIC or non-PIC.
199 /// If this returns true, any PIC related flags should be ignored and instead
200 /// the result of \c isPICDefault() is used exclusively.
201 virtual bool isPICDefaultForced() const = 0;
203 /// SupportsProfiling - Does this tool chain support -pg.
204 virtual bool SupportsProfiling() const { return true; }
206 /// Does this tool chain support Objective-C garbage collection.
207 virtual bool SupportsObjCGC() const { return true; }
209 /// Complain if this tool chain doesn't support Objective-C ARC.
210 virtual void CheckObjCARC() const {}
212 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
213 /// compile unit information.
214 virtual bool UseDwarfDebugFlags() const { return false; }
216 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
217 virtual bool UseSjLjExceptions() const { return false; }
219 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
220 /// command line arguments into account.
221 virtual std::string ComputeLLVMTriple(const ArgList &Args,
222 types::ID InputType = types::TY_INVALID) const;
224 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
225 /// target, which may take into account the command line arguments. For
226 /// example, on Darwin the -mmacosx-version-min= command line argument (which
227 /// sets the deployment target) determines the version in the triple passed to
229 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
230 types::ID InputType = types::TY_INVALID) const;
232 /// getDefaultObjCRuntime - Return the default Objective-C runtime
233 /// for this platform.
235 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
236 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
238 /// hasBlocksRuntime - Given that the user is compiling with
239 /// -fblocks, does this tool chain guarantee the existence of a
242 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
243 virtual bool hasBlocksRuntime() const { return true; }
245 /// \brief Add the clang cc1 arguments for system include paths.
247 /// This routine is responsible for adding the necessary cc1 arguments to
248 /// include headers from standard system header directories.
249 virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
250 ArgStringList &CC1Args) const;
252 /// \brief Add options that need to be passed to cc1 for this target.
253 virtual void addClangTargetOptions(const ArgList &DriverArgs,
254 ArgStringList &CC1Args) const;
256 // GetRuntimeLibType - Determine the runtime library type to use with the
257 // given compilation arguments.
258 virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const;
260 // GetCXXStdlibType - Determine the C++ standard library type to use with the
261 // given compilation arguments.
262 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
264 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
265 /// the include paths to use for the given C++ standard library type.
266 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
267 ArgStringList &CC1Args) const;
269 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
270 /// for the given C++ standard library type.
271 virtual void AddCXXStdlibLibArgs(const ArgList &Args,
272 ArgStringList &CmdArgs) const;
274 /// AddCCKextLibArgs - Add the system specific linker arguments to use
275 /// for kernel extensions (Darwin-specific).
276 virtual void AddCCKextLibArgs(const ArgList &Args,
277 ArgStringList &CmdArgs) const;
279 /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
280 /// global flags for unsafe floating point math, add it and return true.
282 /// This checks for presence of the -ffast-math or -funsafe-math flags.
283 virtual bool AddFastMathRuntimeIfAvailable(const ArgList &Args,
284 ArgStringList &CmdArgs) const;
287 } // end namespace driver
288 } // end namespace clang