]> granicus.if.org Git - clang/blob - include/clang/Driver/ToolChain.h
Keep track of the original target the user specified before
[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   /// The target triple originally requested by the user
50   /// before modifications due to -m32 and without normalization.
51   const std::string UserTriple;
52
53   /// The list of toolchain specific path prefixes to search for
54   /// files.
55   path_list FilePaths;
56
57   /// The list of toolchain specific path prefixes to search for
58   /// programs.
59   path_list ProgramPaths;
60
61 protected:
62   ToolChain(const Driver &D, const llvm::Triple &T, const std::string &UT);
63
64   /// \name Utilities for implementing subclasses.
65   ///@{
66   static void addSystemInclude(const ArgList &DriverArgs,
67                                ArgStringList &CC1Args,
68                                const Twine &Path);
69   static void addExternCSystemInclude(const ArgList &DriverArgs,
70                                       ArgStringList &CC1Args,
71                                       const Twine &Path);
72   static void addSystemIncludes(const ArgList &DriverArgs,
73                                 ArgStringList &CC1Args,
74                                 ArrayRef<StringRef> Paths);
75   ///@}
76
77 public:
78   virtual ~ToolChain();
79
80   // Accessors
81
82   const Driver &getDriver() const;
83   const llvm::Triple &getTriple() const { return Triple; }
84
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(); }
89
90   std::string getTripleString() const {
91     return Triple.getTriple();
92   }
93   const std::string &getUserTriple() const {
94     return UserTriple;
95   }
96
97   path_list &getFilePaths() { return FilePaths; }
98   const path_list &getFilePaths() const { return FilePaths; }
99
100   path_list &getProgramPaths() { return ProgramPaths; }
101   const path_list &getProgramPaths() const { return ProgramPaths; }
102
103   // Tool access.
104
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.
108   ///
109   /// \param BoundArch - The bound architecture name, or 0.
110   virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
111                                         const char *BoundArch) const {
112     return 0;
113   }
114
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;
119
120   // Helper methods
121
122   std::string GetFilePath(const char *Name) const;
123   std::string GetProgramPath(const char *Name, bool WantFile = false) const;
124
125   // Platform defaults information
126
127   /// HasNativeLTOLinker - Check whether the linker and related tools have
128   /// native LLVM support.
129   virtual bool HasNativeLLVMSupport() const;
130
131   /// LookupTypeForExtension - Return the default language type to use for the
132   /// given extension.
133   virtual types::ID LookupTypeForExtension(const char *Ext) const;
134
135   /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
136   virtual bool IsBlocksDefault() const { return false; }
137
138   /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
139   /// by default.
140   virtual bool IsIntegratedAssemblerDefault() const { return false; }
141
142   /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
143   /// default.
144   virtual bool IsStrictAliasingDefault() const { return true; }
145
146   /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
147   /// -fobjc-default-synthesize-properties by default.
148   virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
149
150   /// IsObjCNonFragileABIDefault - Does this tool chain set
151   /// -fobjc-nonfragile-abi by default.
152   virtual bool IsObjCNonFragileABIDefault() const { return false; }
153
154   /// IsObjCLegacyDispatchDefault - Does this tool chain set
155   /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile
156   /// ABI).
157   virtual bool IsObjCLegacyDispatchDefault() const { return true; }
158
159   /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
160   /// mixed dispatch method be used?
161   virtual bool UseObjCMixedDispatch() const { return false; }
162
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 {
166     return 0;
167   }
168
169   /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
170   virtual RuntimeLibType GetDefaultRuntimeLibType() const {
171     return ToolChain::RLT_Libgcc;
172   }
173
174   /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
175   /// by default.
176   virtual bool IsUnwindTablesDefault() const = 0;
177
178   /// GetDefaultRelocationModel - Return the LLVM name of the default
179   /// relocation model for this tool chain.
180   virtual const char *GetDefaultRelocationModel() const = 0;
181
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;
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   /// 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