]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/clang/include/clang/Driver/ToolChain.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / clang / include / clang / Driver / ToolChain.h
1 //===--- ToolChain.h - Collections of tools for one platform ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef CLANG_DRIVER_TOOLCHAIN_H_
11 #define CLANG_DRIVER_TOOLCHAIN_H_
12
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"
20 #include <string>
21
22 namespace clang {
23   class ObjCRuntime;
24
25 namespace driver {
26   class ArgList;
27   class Compilation;
28   class DerivedArgList;
29   class Driver;
30   class InputArgList;
31   class JobAction;
32   class Tool;
33
34 /// ToolChain - Access to tools for a single platform.
35 class ToolChain {
36 public:
37   typedef SmallVector<std::string, 4> path_list;
38
39   enum CXXStdlibType {
40     CST_Libcxx,
41     CST_Libstdcxx
42   };
43
44   enum RuntimeLibType {
45     RLT_CompilerRT,
46     RLT_Libgcc
47   };
48
49 private:
50   const Driver &D;
51   const llvm::Triple Triple;
52   const ArgList &Args;
53
54   /// The list of toolchain specific path prefixes to search for
55   /// files.
56   path_list FilePaths;
57
58   /// The list of toolchain specific path prefixes to search for
59   /// programs.
60   path_list ProgramPaths;
61
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;
69
70 protected:
71   ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args);
72
73   virtual Tool *buildAssembler() const;
74   virtual Tool *buildLinker() const;
75   virtual Tool *getTool(Action::ActionClass AC) const;
76
77   /// \name Utilities for implementing subclasses.
78   ///@{
79   static void addSystemInclude(const ArgList &DriverArgs,
80                                ArgStringList &CC1Args,
81                                const Twine &Path);
82   static void addExternCSystemInclude(const ArgList &DriverArgs,
83                                       ArgStringList &CC1Args,
84                                       const Twine &Path);
85   static void addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
86                                               ArgStringList &CC1Args,
87                                               const Twine &Path);
88   static void addSystemIncludes(const ArgList &DriverArgs,
89                                 ArgStringList &CC1Args,
90                                 ArrayRef<StringRef> Paths);
91   ///@}
92
93 public:
94   virtual ~ToolChain();
95
96   // Accessors
97
98   const Driver &getDriver() const;
99   const llvm::Triple &getTriple() const { return Triple; }
100
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(); }
105
106   /// \brief Provide the default architecture name (as expected by -arch) for
107   /// this toolchain. Note t
108   std::string getDefaultUniversalArchName() const;
109
110   std::string getTripleString() const {
111     return Triple.getTriple();
112   }
113
114   path_list &getFilePaths() { return FilePaths; }
115   const path_list &getFilePaths() const { return FilePaths; }
116
117   path_list &getProgramPaths() { return ProgramPaths; }
118   const path_list &getProgramPaths() const { return ProgramPaths; }
119
120   // Tool access.
121
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.
125   ///
126   /// \param BoundArch - The bound architecture name, or 0.
127   virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
128                                         const char *BoundArch) const {
129     return 0;
130   }
131
132   /// Choose a tool to use to handle the action \p JA.
133   Tool *SelectTool(const JobAction &JA) const;
134
135   // Helper methods
136
137   std::string GetFilePath(const char *Name) const;
138   std::string GetProgramPath(const char *Name) const;
139
140   // Platform defaults information
141
142   /// HasNativeLTOLinker - Check whether the linker and related tools have
143   /// native LLVM support.
144   virtual bool HasNativeLLVMSupport() const;
145
146   /// LookupTypeForExtension - Return the default language type to use for the
147   /// given extension.
148   virtual types::ID LookupTypeForExtension(const char *Ext) const;
149
150   /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
151   virtual bool IsBlocksDefault() const { return false; }
152
153   /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
154   /// by default.
155   virtual bool IsIntegratedAssemblerDefault() const { return false; }
156
157   /// \brief Check if the toolchain should use the integrated assembler.
158   bool useIntegratedAs() const;
159
160   /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
161   /// default.
162   virtual bool IsStrictAliasingDefault() const { return true; }
163
164   /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
165   virtual bool IsMathErrnoDefault() const { return true; }
166
167   /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
168   /// -fobjc-default-synthesize-properties by default.
169   virtual bool IsObjCDefaultSynthPropertiesDefault() const { return true; }
170   
171   /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
172   /// -fencode-extended-block-signature by default.
173   virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
174
175   /// IsObjCNonFragileABIDefault - Does this tool chain set
176   /// -fobjc-nonfragile-abi by default.
177   virtual bool IsObjCNonFragileABIDefault() const { return false; }
178
179   /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
180   /// mixed dispatch method be used?
181   virtual bool UseObjCMixedDispatch() const { return false; }
182
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 {
186     return 0;
187   }
188
189   /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
190   virtual RuntimeLibType GetDefaultRuntimeLibType() const {
191     return ToolChain::RLT_Libgcc;
192   }
193
194   /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
195   /// by default.
196   virtual bool IsUnwindTablesDefault() const;
197
198   /// \brief Test whether this toolchain defaults to PIC.
199   virtual bool isPICDefault() const = 0;
200
201   /// \brief Test whether this toolchain defaults to PIE.
202   virtual bool isPIEDefault() const = 0;
203
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;
209
210   /// SupportsProfiling - Does this tool chain support -pg.
211   virtual bool SupportsProfiling() const { return true; }
212
213   /// Does this tool chain support Objective-C garbage collection.
214   virtual bool SupportsObjCGC() const { return true; }
215
216   /// Complain if this tool chain doesn't support Objective-C ARC.
217   virtual void CheckObjCARC() const {}
218
219   /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
220   /// compile unit information.
221   virtual bool UseDwarfDebugFlags() const { return false; }
222
223   /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
224   virtual bool UseSjLjExceptions() const { return false; }
225
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;
230
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
235   /// Clang.
236   virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
237                                  types::ID InputType = types::TY_INVALID) const;
238
239   /// getDefaultObjCRuntime - Return the default Objective-C runtime
240   /// for this platform.
241   ///
242   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
243   virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
244
245   /// hasBlocksRuntime - Given that the user is compiling with
246   /// -fblocks, does this tool chain guarantee the existence of a
247   /// blocks runtime?
248   ///
249   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
250   virtual bool hasBlocksRuntime() const { return true; }
251
252   /// \brief Add the clang cc1 arguments for system include paths.
253   ///
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;
258
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;
262
263   // GetRuntimeLibType - Determine the runtime library type to use with the
264   // given compilation arguments.
265   virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const;
266
267   // GetCXXStdlibType - Determine the C++ standard library type to use with the
268   // given compilation arguments.
269   virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
270
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;
275
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;
280
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;
285
286   /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
287   /// global flags for unsafe floating point math, add it and return true.
288   ///
289   /// This checks for presence of the -ffast-math or -funsafe-math flags.
290   virtual bool AddFastMathRuntimeIfAvailable(const ArgList &Args,
291                                              ArgStringList &CmdArgs) const;
292 };
293
294 } // end namespace driver
295 } // end namespace clang
296
297 #endif