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;
49 /// The target triple originally requested by the user
50 /// before modifications due to -m32 and without normalization.
51 const std::string UserTriple;
53 /// The list of toolchain specific path prefixes to search for
57 /// The list of toolchain specific path prefixes to search for
59 path_list ProgramPaths;
62 ToolChain(const Driver &D, const llvm::Triple &T, const std::string &UT);
64 /// \name Utilities for implementing subclasses.
66 static void addSystemInclude(const ArgList &DriverArgs,
67 ArgStringList &CC1Args,
69 static void addExternCSystemInclude(const ArgList &DriverArgs,
70 ArgStringList &CC1Args,
72 static void addSystemIncludes(const ArgList &DriverArgs,
73 ArgStringList &CC1Args,
74 ArrayRef<StringRef> Paths);
82 const Driver &getDriver() const;
83 const llvm::Triple &getTriple() const { return Triple; }
85 llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
86 StringRef getArchName() const { return Triple.getArchName(); }
87 StringRef getPlatform() const { return Triple.getVendorName(); }
88 StringRef getOS() const { return Triple.getOSName(); }
90 std::string getTripleString() const {
91 return Triple.getTriple();
93 const std::string &getUserTriple() const {
97 path_list &getFilePaths() { return FilePaths; }
98 const path_list &getFilePaths() const { return FilePaths; }
100 path_list &getProgramPaths() { return ProgramPaths; }
101 const path_list &getProgramPaths() const { return ProgramPaths; }
105 /// TranslateArgs - Create a new derived argument list for any argument
106 /// translations this ToolChain may wish to perform, or 0 if no tool chain
107 /// specific translations are needed.
109 /// \param BoundArch - The bound architecture name, or 0.
110 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
111 const char *BoundArch) const {
115 /// SelectTool - Choose a tool to use to handle the action \arg JA with the
116 /// given \arg Inputs.
117 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
118 const ActionList &Inputs) const = 0;
122 std::string GetFilePath(const char *Name) const;
123 std::string GetProgramPath(const char *Name, bool WantFile = false) const;
125 // Platform defaults information
127 /// HasNativeLTOLinker - Check whether the linker and related tools have
128 /// native LLVM support.
129 virtual bool HasNativeLLVMSupport() const;
131 /// LookupTypeForExtension - Return the default language type to use for the
133 virtual types::ID LookupTypeForExtension(const char *Ext) const;
135 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
136 virtual bool IsBlocksDefault() const { return false; }
138 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
140 virtual bool IsIntegratedAssemblerDefault() const { return false; }
142 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
144 virtual bool IsStrictAliasingDefault() const { return true; }
146 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
147 /// -fobjc-default-synthesize-properties by default.
148 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
150 /// IsObjCNonFragileABIDefault - Does this tool chain set
151 /// -fobjc-nonfragile-abi by default.
152 virtual bool IsObjCNonFragileABIDefault() const { return false; }
154 /// IsObjCLegacyDispatchDefault - Does this tool chain set
155 /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile
157 virtual bool IsObjCLegacyDispatchDefault() const { return true; }
159 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
160 /// mixed dispatch method be used?
161 virtual bool UseObjCMixedDispatch() const { return false; }
163 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
164 /// this tool chain (0=off, 1=on, 2=all).
165 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
169 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
170 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
171 return ToolChain::RLT_Libgcc;
174 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
176 virtual bool IsUnwindTablesDefault() const = 0;
178 /// GetDefaultRelocationModel - Return the LLVM name of the default
179 /// relocation model for this tool chain.
180 virtual const char *GetDefaultRelocationModel() const = 0;
182 /// GetForcedPicModel - Return the LLVM name of the forced PIC model
183 /// for this tool chain, or 0 if this tool chain does not force a
184 /// particular PIC mode.
185 virtual const char *GetForcedPicModel() 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 /// 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