]> granicus.if.org Git - clang/blob - include/clang/Driver/ToolChain.h
Driver: Turn the default value for -fmath-errno into a proper target hook and disable...
[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 namespace driver {
22   class ArgList;
23   class Compilation;
24   class DerivedArgList;
25   class Driver;
26   class InputArgList;
27   class JobAction;
28   class ObjCRuntime;
29   class Tool;
30
31 /// ToolChain - Access to tools for a single platform.
32 class ToolChain {
33 public:
34   typedef SmallVector<std::string, 4> path_list;
35
36   enum CXXStdlibType {
37     CST_Libcxx,
38     CST_Libstdcxx
39   };
40
41   enum RuntimeLibType {
42     RLT_CompilerRT,
43     RLT_Libgcc
44   };
45
46 private:
47   const Driver &D;
48   const llvm::Triple Triple;
49
50   /// The list of toolchain specific path prefixes to search for
51   /// files.
52   path_list FilePaths;
53
54   /// The list of toolchain specific path prefixes to search for
55   /// programs.
56   path_list ProgramPaths;
57
58 protected:
59   ToolChain(const Driver &D, const llvm::Triple &T);
60
61   /// \name Utilities for implementing subclasses.
62   ///@{
63   static void addSystemInclude(const ArgList &DriverArgs,
64                                ArgStringList &CC1Args,
65                                const Twine &Path);
66   static void addExternCSystemInclude(const ArgList &DriverArgs,
67                                       ArgStringList &CC1Args,
68                                       const Twine &Path);
69   static void addSystemIncludes(const ArgList &DriverArgs,
70                                 ArgStringList &CC1Args,
71                                 ArrayRef<StringRef> Paths);
72   ///@}
73
74 public:
75   virtual ~ToolChain();
76
77   // Accessors
78
79   const Driver &getDriver() const;
80   const llvm::Triple &getTriple() const { return Triple; }
81
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(); }
86
87   std::string getTripleString() const {
88     return Triple.getTriple();
89   }
90
91   path_list &getFilePaths() { return FilePaths; }
92   const path_list &getFilePaths() const { return FilePaths; }
93
94   path_list &getProgramPaths() { return ProgramPaths; }
95   const path_list &getProgramPaths() const { return ProgramPaths; }
96
97   // Tool access.
98
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.
102   ///
103   /// \param BoundArch - The bound architecture name, or 0.
104   virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
105                                         const char *BoundArch) const {
106     return 0;
107   }
108
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;
113
114   // Helper methods
115
116   std::string GetFilePath(const char *Name) const;
117   std::string GetProgramPath(const char *Name, bool WantFile = false) const;
118
119   // Platform defaults information
120
121   /// HasNativeLTOLinker - Check whether the linker and related tools have
122   /// native LLVM support.
123   virtual bool HasNativeLLVMSupport() const;
124
125   /// LookupTypeForExtension - Return the default language type to use for the
126   /// given extension.
127   virtual types::ID LookupTypeForExtension(const char *Ext) const;
128
129   /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
130   virtual bool IsBlocksDefault() const { return false; }
131
132   /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
133   /// by default.
134   virtual bool IsIntegratedAssemblerDefault() const { return false; }
135
136   /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
137   /// default.
138   virtual bool IsStrictAliasingDefault() const { return true; }
139
140   /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
141   virtual bool IsMathErrnoDefault() const { return true; }
142
143   /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
144   /// -fobjc-default-synthesize-properties by default.
145   virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
146
147   /// IsObjCNonFragileABIDefault - Does this tool chain set
148   /// -fobjc-nonfragile-abi by default.
149   virtual bool IsObjCNonFragileABIDefault() const { return false; }
150
151   /// IsObjCLegacyDispatchDefault - Does this tool chain set
152   /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile
153   /// ABI).
154   virtual bool IsObjCLegacyDispatchDefault() const { return true; }
155
156   /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
157   /// mixed dispatch method be used?
158   virtual bool UseObjCMixedDispatch() const { return false; }
159
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 {
163     return 0;
164   }
165
166   /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
167   virtual RuntimeLibType GetDefaultRuntimeLibType() const {
168     return ToolChain::RLT_Libgcc;
169   }
170
171   /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
172   /// by default.
173   virtual bool IsUnwindTablesDefault() const = 0;
174
175   /// GetDefaultRelocationModel - Return the LLVM name of the default
176   /// relocation model for this tool chain.
177   virtual const char *GetDefaultRelocationModel() const = 0;
178
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;
183
184   /// SupportsProfiling - Does this tool chain support -pg.
185   virtual bool SupportsProfiling() const { return true; }
186
187   /// Does this tool chain support Objective-C garbage collection.
188   virtual bool SupportsObjCGC() const { return true; }
189
190   /// Does this tool chain support Objective-C ARC.
191   virtual bool SupportsObjCARC() const { return true; }
192
193   /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
194   /// compile unit information.
195   virtual bool UseDwarfDebugFlags() const { return false; }
196
197   /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
198   virtual bool UseSjLjExceptions() const { return false; }
199
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;
204
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
209   /// Clang.
210   virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
211                                  types::ID InputType = types::TY_INVALID) const;
212
213   /// configureObjCRuntime - Configure the known properties of the
214   /// Objective-C runtime for this platform.
215   ///
216   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
217   virtual void configureObjCRuntime(ObjCRuntime &runtime) const;
218
219   /// hasBlocksRuntime - Given that the user is compiling with
220   /// -fblocks, does this tool chain guarantee the existence of a
221   /// blocks runtime?
222   ///
223   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
224   virtual bool hasBlocksRuntime() const { return true; }
225
226   /// \brief Add the clang cc1 arguments for system include paths.
227   ///
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;
232
233   // GetRuntimeLibType - Determine the runtime library type to use with the
234   // given compilation arguments.
235   virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const;
236
237   // GetCXXStdlibType - Determine the C++ standard library type to use with the
238   // given compilation arguments.
239   virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
240
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;
245
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;
250
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;
255 };
256
257 } // end namespace driver
258 } // end namespace clang
259
260 #endif