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"
31 /// ToolChain - Access to tools for a single platform.
34 typedef SmallVector<std::string, 4> path_list;
48 const llvm::Triple Triple;
50 /// The list of toolchain specific path prefixes to search for
54 /// The list of toolchain specific path prefixes to search for
56 path_list ProgramPaths;
59 ToolChain(const Driver &D, const llvm::Triple &T);
61 /// \name Utilities for implementing subclasses.
63 static void addSystemInclude(const ArgList &DriverArgs,
64 ArgStringList &CC1Args,
66 static void addExternCSystemInclude(const ArgList &DriverArgs,
67 ArgStringList &CC1Args,
69 static void addSystemIncludes(const ArgList &DriverArgs,
70 ArgStringList &CC1Args,
71 ArrayRef<StringRef> Paths);
79 const Driver &getDriver() const;
80 const llvm::Triple &getTriple() const { return Triple; }
82 llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
83 StringRef getArchName() const { return Triple.getArchName(); }
84 StringRef getPlatform() const { return Triple.getVendorName(); }
85 StringRef getOS() const { return Triple.getOSName(); }
87 std::string getTripleString() const {
88 return Triple.getTriple();
91 path_list &getFilePaths() { return FilePaths; }
92 const path_list &getFilePaths() const { return FilePaths; }
94 path_list &getProgramPaths() { return ProgramPaths; }
95 const path_list &getProgramPaths() const { return ProgramPaths; }
99 /// TranslateArgs - Create a new derived argument list for any argument
100 /// translations this ToolChain may wish to perform, or 0 if no tool chain
101 /// specific translations are needed.
103 /// \param BoundArch - The bound architecture name, or 0.
104 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
105 const char *BoundArch) const {
109 /// SelectTool - Choose a tool to use to handle the action \arg JA with the
110 /// given \arg Inputs.
111 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
112 const ActionList &Inputs) const = 0;
116 std::string GetFilePath(const char *Name) const;
117 std::string GetProgramPath(const char *Name, bool WantFile = false) const;
119 // Platform defaults information
121 /// HasNativeLTOLinker - Check whether the linker and related tools have
122 /// native LLVM support.
123 virtual bool HasNativeLLVMSupport() const;
125 /// LookupTypeForExtension - Return the default language type to use for the
127 virtual types::ID LookupTypeForExtension(const char *Ext) const;
129 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
130 virtual bool IsBlocksDefault() const { return false; }
132 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
134 virtual bool IsIntegratedAssemblerDefault() const { return false; }
136 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
138 virtual bool IsStrictAliasingDefault() const { return true; }
140 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
141 virtual bool IsMathErrnoDefault() const { return true; }
143 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
144 /// -fobjc-default-synthesize-properties by default.
145 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
147 /// IsObjCNonFragileABIDefault - Does this tool chain set
148 /// -fobjc-nonfragile-abi by default.
149 virtual bool IsObjCNonFragileABIDefault() const { return false; }
151 /// IsObjCLegacyDispatchDefault - Does this tool chain set
152 /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile
154 virtual bool IsObjCLegacyDispatchDefault() const { return true; }
156 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
157 /// mixed dispatch method be used?
158 virtual bool UseObjCMixedDispatch() const { return false; }
160 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
161 /// this tool chain (0=off, 1=on, 2=all).
162 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
166 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
167 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
168 return ToolChain::RLT_Libgcc;
171 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
173 virtual bool IsUnwindTablesDefault() const = 0;
175 /// GetDefaultRelocationModel - Return the LLVM name of the default
176 /// relocation model for this tool chain.
177 virtual const char *GetDefaultRelocationModel() const = 0;
179 /// GetForcedPicModel - Return the LLVM name of the forced PIC model
180 /// for this tool chain, or 0 if this tool chain does not force a
181 /// particular PIC mode.
182 virtual const char *GetForcedPicModel() const = 0;
184 /// SupportsProfiling - Does this tool chain support -pg.
185 virtual bool SupportsProfiling() const { return true; }
187 /// Does this tool chain support Objective-C garbage collection.
188 virtual bool SupportsObjCGC() const { return true; }
190 /// Does this tool chain support Objective-C ARC.
191 virtual bool SupportsObjCARC() const { return true; }
193 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
194 /// compile unit information.
195 virtual bool UseDwarfDebugFlags() const { return false; }
197 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
198 virtual bool UseSjLjExceptions() const { return false; }
200 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
201 /// command line arguments into account.
202 virtual std::string ComputeLLVMTriple(const ArgList &Args,
203 types::ID InputType = types::TY_INVALID) const;
205 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
206 /// target, which may take into account the command line arguments. For
207 /// example, on Darwin the -mmacosx-version-min= command line argument (which
208 /// sets the deployment target) determines the version in the triple passed to
210 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
211 types::ID InputType = types::TY_INVALID) const;
213 /// configureObjCRuntime - Configure the known properties of the
214 /// Objective-C runtime for this platform.
216 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
217 virtual void configureObjCRuntime(ObjCRuntime &runtime) const;
219 /// hasBlocksRuntime - Given that the user is compiling with
220 /// -fblocks, does this tool chain guarantee the existence of a
223 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
224 virtual bool hasBlocksRuntime() const { return true; }
226 /// \brief Add the clang cc1 arguments for system include paths.
228 /// This routine is responsible for adding the necessary cc1 arguments to
229 /// include headers from standard system header directories.
230 virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
231 ArgStringList &CC1Args) const;
233 // GetRuntimeLibType - Determine the runtime library type to use with the
234 // given compilation arguments.
235 virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const;
237 // GetCXXStdlibType - Determine the C++ standard library type to use with the
238 // given compilation arguments.
239 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
241 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
242 /// the include paths to use for the given C++ standard library type.
243 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
244 ArgStringList &CC1Args) const;
246 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
247 /// for the given C++ standard library type.
248 virtual void AddCXXStdlibLibArgs(const ArgList &Args,
249 ArgStringList &CmdArgs) const;
251 /// AddCCKextLibArgs - Add the system specific linker arguments to use
252 /// for kernel extensions (Darwin-specific).
253 virtual void AddCCKextLibArgs(const ArgList &Args,
254 ArgStringList &CmdArgs) const;
257 } // end namespace driver
258 } // end namespace clang