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 std::string getTripleString() const {
89 return Triple.getTriple();
92 path_list &getFilePaths() { return FilePaths; }
93 const path_list &getFilePaths() const { return FilePaths; }
95 path_list &getProgramPaths() { return ProgramPaths; }
96 const path_list &getProgramPaths() const { return ProgramPaths; }
100 /// TranslateArgs - Create a new derived argument list for any argument
101 /// translations this ToolChain may wish to perform, or 0 if no tool chain
102 /// specific translations are needed.
104 /// \param BoundArch - The bound architecture name, or 0.
105 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
106 const char *BoundArch) const {
110 /// SelectTool - Choose a tool to use to handle the action \arg JA with the
111 /// given \arg Inputs.
112 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
113 const ActionList &Inputs) const = 0;
117 std::string GetFilePath(const char *Name) const;
118 std::string GetProgramPath(const char *Name, bool WantFile = false) const;
120 // Platform defaults information
122 /// HasNativeLTOLinker - Check whether the linker and related tools have
123 /// native LLVM support.
124 virtual bool HasNativeLLVMSupport() const;
126 /// LookupTypeForExtension - Return the default language type to use for the
128 virtual types::ID LookupTypeForExtension(const char *Ext) const;
130 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
131 virtual bool IsBlocksDefault() const { return false; }
133 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
135 virtual bool IsIntegratedAssemblerDefault() const { return false; }
137 /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
139 virtual bool IsStrictAliasingDefault() const { return true; }
141 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
142 virtual bool IsMathErrnoDefault() const { return true; }
144 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
145 /// -fobjc-default-synthesize-properties by default.
146 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
148 /// IsObjCNonFragileABIDefault - Does this tool chain set
149 /// -fobjc-nonfragile-abi by default.
150 virtual bool IsObjCNonFragileABIDefault() const { return false; }
152 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
153 /// mixed dispatch method be used?
154 virtual bool UseObjCMixedDispatch() const { return false; }
156 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
157 /// this tool chain (0=off, 1=on, 2=all).
158 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
162 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
163 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
164 return ToolChain::RLT_Libgcc;
167 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
169 virtual bool IsUnwindTablesDefault() const = 0;
171 /// GetDefaultRelocationModel - Return the LLVM name of the default
172 /// relocation model for this tool chain.
173 virtual const char *GetDefaultRelocationModel() const = 0;
175 /// GetForcedPicModel - Return the LLVM name of the forced PIC model
176 /// for this tool chain, or 0 if this tool chain does not force a
177 /// particular PIC mode.
178 virtual const char *GetForcedPicModel() const = 0;
180 /// SupportsProfiling - Does this tool chain support -pg.
181 virtual bool SupportsProfiling() const { return true; }
183 /// Does this tool chain support Objective-C garbage collection.
184 virtual bool SupportsObjCGC() const { return true; }
186 /// Does this tool chain support Objective-C ARC.
187 virtual bool SupportsObjCARC() const { return true; }
189 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
190 /// compile unit information.
191 virtual bool UseDwarfDebugFlags() const { return false; }
193 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
194 virtual bool UseSjLjExceptions() const { return false; }
196 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
197 /// command line arguments into account.
198 virtual std::string ComputeLLVMTriple(const ArgList &Args,
199 types::ID InputType = types::TY_INVALID) const;
201 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
202 /// target, which may take into account the command line arguments. For
203 /// example, on Darwin the -mmacosx-version-min= command line argument (which
204 /// sets the deployment target) determines the version in the triple passed to
206 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
207 types::ID InputType = types::TY_INVALID) const;
209 /// getDefaultObjCRuntime - Return the default Objective-C runtime
210 /// for this platform.
212 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
213 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
215 /// hasBlocksRuntime - Given that the user is compiling with
216 /// -fblocks, does this tool chain guarantee the existence of a
219 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
220 virtual bool hasBlocksRuntime() const { return true; }
222 /// \brief Add the clang cc1 arguments for system include paths.
224 /// This routine is responsible for adding the necessary cc1 arguments to
225 /// include headers from standard system header directories.
226 virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
227 ArgStringList &CC1Args) const;
229 // addClangTargetOptions - Add options that need to be passed to cc1 for
231 virtual void addClangTargetOptions(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