]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/Driver/ToolChain.h
MFC r244628:
[FreeBSD/stable/9.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/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"
18 #include <string>
19
20 namespace clang {
21   class ObjCRuntime;
22
23 namespace driver {
24   class ArgList;
25   class Compilation;
26   class DerivedArgList;
27   class Driver;
28   class InputArgList;
29   class JobAction;
30   class Tool;
31
32 /// ToolChain - Access to tools for a single platform.
33 class ToolChain {
34 public:
35   typedef SmallVector<std::string, 4> path_list;
36
37   enum CXXStdlibType {
38     CST_Libcxx,
39     CST_Libstdcxx
40   };
41
42   enum RuntimeLibType {
43     RLT_CompilerRT,
44     RLT_Libgcc
45   };
46
47 private:
48   const Driver &D;
49   const llvm::Triple Triple;
50
51   /// The list of toolchain specific path prefixes to search for
52   /// files.
53   path_list FilePaths;
54
55   /// The list of toolchain specific path prefixes to search for
56   /// programs.
57   path_list ProgramPaths;
58
59 protected:
60   ToolChain(const Driver &D, const llvm::Triple &T);
61
62   /// \name Utilities for implementing subclasses.
63   ///@{
64   static void addSystemInclude(const ArgList &DriverArgs,
65                                ArgStringList &CC1Args,
66                                const Twine &Path);
67   static void addExternCSystemInclude(const ArgList &DriverArgs,
68                                       ArgStringList &CC1Args,
69                                       const Twine &Path);
70   static void addSystemIncludes(const ArgList &DriverArgs,
71                                 ArgStringList &CC1Args,
72                                 ArrayRef<StringRef> Paths);
73   ///@}
74
75 public:
76   virtual ~ToolChain();
77
78   // Accessors
79
80   const Driver &getDriver() const;
81   const llvm::Triple &getTriple() const { return Triple; }
82
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(); }
87
88   /// \brief Provide the default architecture name (as expected by -arch) for
89   /// this toolchain. Note t
90   std::string getDefaultUniversalArchName() const;
91
92   std::string getTripleString() const {
93     return Triple.getTriple();
94   }
95
96   path_list &getFilePaths() { return FilePaths; }
97   const path_list &getFilePaths() const { return FilePaths; }
98
99   path_list &getProgramPaths() { return ProgramPaths; }
100   const path_list &getProgramPaths() const { return ProgramPaths; }
101
102   // Tool access.
103
104   /// TranslateArgs - Create a new derived argument list for any argument
105   /// translations this ToolChain may wish to perform, or 0 if no tool chain
106   /// specific translations are needed.
107   ///
108   /// \param BoundArch - The bound architecture name, or 0.
109   virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
110                                         const char *BoundArch) const {
111     return 0;
112   }
113
114   /// SelectTool - Choose a tool to use to handle the action \p JA with the
115   /// given \p Inputs.
116   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
117                            const ActionList &Inputs) const = 0;
118
119   // Helper methods
120
121   std::string GetFilePath(const char *Name) const;
122   std::string GetProgramPath(const char *Name) const;
123
124   // Platform defaults information
125
126   /// HasNativeLTOLinker - Check whether the linker and related tools have
127   /// native LLVM support.
128   virtual bool HasNativeLLVMSupport() const;
129
130   /// LookupTypeForExtension - Return the default language type to use for the
131   /// given extension.
132   virtual types::ID LookupTypeForExtension(const char *Ext) const;
133
134   /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
135   virtual bool IsBlocksDefault() const { return false; }
136
137   /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
138   /// by default.
139   virtual bool IsIntegratedAssemblerDefault() const { return false; }
140
141   /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
142   /// default.
143   virtual bool IsStrictAliasingDefault() const { return true; }
144
145   /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
146   virtual bool IsMathErrnoDefault() const { return true; }
147
148   /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
149   /// -fobjc-default-synthesize-properties by default.
150   virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
151   
152   /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
153   /// -fencode-extended-block-signature by default.
154   virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
155
156   /// IsObjCNonFragileABIDefault - Does this tool chain set
157   /// -fobjc-nonfragile-abi by default.
158   virtual bool IsObjCNonFragileABIDefault() const { return false; }
159
160   /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
161   /// mixed dispatch method be used?
162   virtual bool UseObjCMixedDispatch() const { return false; }
163
164   /// GetDefaultStackProtectorLevel - Get the default stack protector level for
165   /// this tool chain (0=off, 1=on, 2=all).
166   virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
167     return 0;
168   }
169
170   /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
171   virtual RuntimeLibType GetDefaultRuntimeLibType() const {
172     return ToolChain::RLT_Libgcc;
173   }
174
175   /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
176   /// by default.
177   virtual bool IsUnwindTablesDefault() const;
178
179   /// \brief Test whether this toolchain defaults to PIC.
180   virtual bool isPICDefault() const = 0;
181
182   /// \brief Tests whether this toolchain forces its default for PIC or non-PIC.
183   /// If this returns true, any PIC related flags should be ignored and instead
184   /// the result of \c isPICDefault() is used exclusively.
185   virtual bool isPICDefaultForced() const = 0;
186
187   /// SupportsProfiling - Does this tool chain support -pg.
188   virtual bool SupportsProfiling() const { return true; }
189
190   /// Does this tool chain support Objective-C garbage collection.
191   virtual bool SupportsObjCGC() const { return true; }
192
193   /// Complain if this tool chain doesn't support Objective-C ARC.
194   virtual void CheckObjCARC() const {}
195
196   /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
197   /// compile unit information.
198   virtual bool UseDwarfDebugFlags() const { return false; }
199
200   /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
201   virtual bool UseSjLjExceptions() const { return false; }
202
203   /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
204   /// command line arguments into account.
205   virtual std::string ComputeLLVMTriple(const ArgList &Args,
206                                  types::ID InputType = types::TY_INVALID) const;
207
208   /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
209   /// target, which may take into account the command line arguments. For
210   /// example, on Darwin the -mmacosx-version-min= command line argument (which
211   /// sets the deployment target) determines the version in the triple passed to
212   /// Clang.
213   virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
214                                  types::ID InputType = types::TY_INVALID) const;
215
216   /// getDefaultObjCRuntime - Return the default Objective-C runtime
217   /// for this platform.
218   ///
219   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
220   virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
221
222   /// hasBlocksRuntime - Given that the user is compiling with
223   /// -fblocks, does this tool chain guarantee the existence of a
224   /// blocks runtime?
225   ///
226   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
227   virtual bool hasBlocksRuntime() const { return true; }
228
229   /// \brief Add the clang cc1 arguments for system include paths.
230   ///
231   /// This routine is responsible for adding the necessary cc1 arguments to
232   /// include headers from standard system header directories.
233   virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
234                                          ArgStringList &CC1Args) const;
235
236   // addClangTargetOptions - Add options that need to be passed to cc1 for
237   // this target.
238   virtual void addClangTargetOptions(ArgStringList &CC1Args) const;
239
240   // GetRuntimeLibType - Determine the runtime library type to use with the
241   // given compilation arguments.
242   virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const;
243
244   // GetCXXStdlibType - Determine the C++ standard library type to use with the
245   // given compilation arguments.
246   virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
247
248   /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
249   /// the include paths to use for the given C++ standard library type.
250   virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
251                                             ArgStringList &CC1Args) const;
252
253   /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
254   /// for the given C++ standard library type.
255   virtual void AddCXXStdlibLibArgs(const ArgList &Args,
256                                    ArgStringList &CmdArgs) const;
257
258   /// AddCCKextLibArgs - Add the system specific linker arguments to use
259   /// for kernel extensions (Darwin-specific).
260   virtual void AddCCKextLibArgs(const ArgList &Args,
261                                 ArgStringList &CmdArgs) const;
262
263   /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
264   /// global flags for unsafe floating point math, add it and return true.
265   ///
266   /// This checks for presence of the -ffast-math or -funsafe-math flags.
267   virtual bool AddFastMathRuntimeIfAvailable(const ArgList &Args,
268                                              ArgStringList &CmdArgs) const;
269 };
270
271 } // end namespace driver
272 } // end namespace clang
273
274 #endif