]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Driver/ToolChains.h
Upgrade our copy of llvm/clang to r130700, from upstream's trunk.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Driver / ToolChains.h
1 //===--- ToolChains.h - ToolChain Implementations ---------------*- 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_LIB_DRIVER_TOOLCHAINS_H_
11 #define CLANG_LIB_DRIVER_TOOLCHAINS_H_
12
13 #include "clang/Driver/Action.h"
14 #include "clang/Driver/ToolChain.h"
15
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/Support/Compiler.h"
18
19 #include "Tools.h"
20
21 namespace clang {
22 namespace driver {
23 namespace toolchains {
24
25 /// Generic_GCC - A tool chain using the 'gcc' command to perform
26 /// all subcommands; this relies on gcc translating the majority of
27 /// command line options.
28 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
29 protected:
30   mutable llvm::DenseMap<unsigned, Tool*> Tools;
31
32 public:
33   Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
34   ~Generic_GCC();
35
36   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
37                            const ActionList &Inputs) const;
38
39   virtual bool IsUnwindTablesDefault() const;
40   virtual const char *GetDefaultRelocationModel() const;
41   virtual const char *GetForcedPicModel() const;
42 };
43
44 /// Darwin - The base Darwin tool chain.
45 class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
46 public:
47   /// The host version.
48   unsigned DarwinVersion[3];
49
50 private:
51   mutable llvm::DenseMap<unsigned, Tool*> Tools;
52
53   /// Whether the information on the target has been initialized.
54   //
55   // FIXME: This should be eliminated. What we want to do is make this part of
56   // the "default target for arguments" selection process, once we get out of
57   // the argument translation business.
58   mutable bool TargetInitialized;
59
60   /// Whether we are targeting iPhoneOS target.
61   mutable bool TargetIsIPhoneOS;
62
63   /// Whether we are targeting the iPhoneOS simulator target.
64   mutable bool TargetIsIPhoneOSSimulator;
65
66   /// The OS version we are targeting.
67   mutable unsigned TargetVersion[3];
68
69   /// The default macosx-version-min of this tool chain; empty until
70   /// initialized.
71   std::string MacosxVersionMin;
72
73 private:
74   void AddDeploymentTarget(DerivedArgList &Args) const;
75
76 public:
77   Darwin(const HostInfo &Host, const llvm::Triple& Triple);
78   ~Darwin();
79
80   std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
81
82   /// @name Darwin Specific Toolchain API
83   /// {
84
85   // FIXME: Eliminate these ...Target functions and derive separate tool chains
86   // for these targets and put version in constructor.
87   void setTarget(bool IsIPhoneOS, unsigned Major, unsigned Minor,
88                  unsigned Micro, bool IsIOSSim) const {
89     assert((!IsIOSSim || IsIPhoneOS) && "Unexpected deployment target!");
90
91     // FIXME: For now, allow reinitialization as long as values don't
92     // change. This will go away when we move away from argument translation.
93     if (TargetInitialized && TargetIsIPhoneOS == IsIPhoneOS &&
94         TargetIsIPhoneOSSimulator == IsIOSSim &&
95         TargetVersion[0] == Major && TargetVersion[1] == Minor &&
96         TargetVersion[2] == Micro)
97       return;
98
99     assert(!TargetInitialized && "Target already initialized!");
100     TargetInitialized = true;
101     TargetIsIPhoneOS = IsIPhoneOS;
102     TargetIsIPhoneOSSimulator = IsIOSSim;
103     TargetVersion[0] = Major;
104     TargetVersion[1] = Minor;
105     TargetVersion[2] = Micro;
106   }
107
108   bool isTargetIPhoneOS() const {
109     assert(TargetInitialized && "Target not initialized!");
110     return TargetIsIPhoneOS;
111   }
112
113   bool isTargetIOSSimulator() const {
114     assert(TargetInitialized && "Target not initialized!");
115     return TargetIsIPhoneOSSimulator;
116   }
117
118   bool isTargetInitialized() const { return TargetInitialized; }
119
120   void getTargetVersion(unsigned (&Res)[3]) const {
121     assert(TargetInitialized && "Target not initialized!");
122     Res[0] = TargetVersion[0];
123     Res[1] = TargetVersion[1];
124     Res[2] = TargetVersion[2];
125   }
126
127   /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
128   /// invocation. For example, Darwin treats different ARM variations as
129   /// distinct architectures.
130   llvm::StringRef getDarwinArchName(const ArgList &Args) const;
131
132   static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
133     for (unsigned i=0; i < 3; ++i) {
134       if (A[i] > B[i]) return false;
135       if (A[i] < B[i]) return true;
136     }
137     return false;
138   }
139
140   bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
141     assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
142     unsigned B[3] = { V0, V1, V2 };
143     return isVersionLT(TargetVersion, B);
144   }
145
146   bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
147     assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
148     unsigned B[3] = { V0, V1, V2 };
149     return isVersionLT(TargetVersion, B);
150   }
151
152   /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
153   ///
154   /// \param Args - The input argument list.
155   /// \param CmdArgs [out] - The command argument list to append the paths
156   /// (prefixed by -L) to.
157   virtual void AddLinkSearchPathArgs(const ArgList &Args,
158                                      ArgStringList &CmdArgs) const = 0;
159
160   /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
161   /// runtime library.
162   virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
163                                      ArgStringList &CmdArgs) const = 0;
164
165   /// }
166   /// @name ToolChain Implementation
167   /// {
168
169   virtual types::ID LookupTypeForExtension(const char *Ext) const;
170
171   virtual bool HasNativeLLVMSupport() const;
172
173   virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
174                                         const char *BoundArch) const;
175
176   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
177                            const ActionList &Inputs) const;
178
179   virtual bool IsBlocksDefault() const {
180     // Always allow blocks on Darwin; users interested in versioning are
181     // expected to use /usr/include/Blocks.h.
182     return true;
183   }
184   virtual bool IsIntegratedAssemblerDefault() const {
185 #ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
186     return false;
187 #else
188     // Default integrated assembler to on for x86.
189     return (getTriple().getArch() == llvm::Triple::x86 ||
190             getTriple().getArch() == llvm::Triple::x86_64);
191 #endif
192   }
193   virtual bool IsStrictAliasingDefault() const {
194 #ifdef DISABLE_DEFAULT_STRICT_ALIASING
195     return false;
196 #else
197     return ToolChain::IsStrictAliasingDefault();
198 #endif
199   }
200   
201   virtual bool IsObjCDefaultSynthPropertiesDefault() const {
202     return false;
203   }
204
205   virtual bool IsObjCNonFragileABIDefault() const {
206     // Non-fragile ABI is default for everything but i386.
207     return getTriple().getArch() != llvm::Triple::x86;
208   }
209   virtual bool IsObjCLegacyDispatchDefault() const {
210     // This is only used with the non-fragile ABI.
211
212     // Legacy dispatch is used everywhere except on x86_64.
213     return getTriple().getArch() != llvm::Triple::x86_64;
214   }
215   virtual bool UseObjCMixedDispatch() const {
216     // This is only used with the non-fragile ABI and non-legacy dispatch.
217
218     // Mixed dispatch is used everywhere except OS X before 10.6.
219     return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
220   }
221   virtual bool IsUnwindTablesDefault() const;
222   virtual unsigned GetDefaultStackProtectorLevel() const {
223     // Stack protectors default to on for 10.6 and beyond.
224     return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
225   }
226   virtual const char *GetDefaultRelocationModel() const;
227   virtual const char *GetForcedPicModel() const;
228
229   virtual bool SupportsProfiling() const;
230
231   virtual bool SupportsObjCGC() const;
232
233   virtual bool UseDwarfDebugFlags() const;
234
235   virtual bool UseSjLjExceptions() const;
236
237   /// }
238 };
239
240 /// DarwinClang - The Darwin toolchain used by Clang.
241 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
242 public:
243   DarwinClang(const HostInfo &Host, const llvm::Triple& Triple);
244
245   /// @name Darwin ToolChain Implementation
246   /// {
247
248   virtual void AddLinkSearchPathArgs(const ArgList &Args,
249                                     ArgStringList &CmdArgs) const;
250
251   virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
252                                      ArgStringList &CmdArgs) const;
253
254   virtual void AddCXXStdlibLibArgs(const ArgList &Args,
255                                    ArgStringList &CmdArgs) const;
256
257   virtual void AddCCKextLibArgs(const ArgList &Args,
258                                 ArgStringList &CmdArgs) const;
259
260   /// }
261 };
262
263 /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
264 class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
265 public:
266   Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
267     : Generic_GCC(Host, Triple) {}
268
269   std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
270
271   virtual const char *GetDefaultRelocationModel() const { return "pic"; }
272 };
273
274 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
275  public:
276   Generic_ELF(const HostInfo &Host, const llvm::Triple& Triple)
277     : Generic_GCC(Host, Triple) {}
278
279   virtual bool IsIntegratedAssemblerDefault() const {
280     // Default integrated assembler to on for x86.
281     return (getTriple().getArch() == llvm::Triple::x86 ||
282             getTriple().getArch() == llvm::Triple::x86_64);
283   }
284 };
285
286 class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
287 public:
288   AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
289
290   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
291                            const ActionList &Inputs) const;
292 };
293
294 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
295 public:
296   OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
297
298   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
299                            const ActionList &Inputs) const;
300 };
301
302 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
303 public:
304   FreeBSD(const HostInfo &Host, const llvm::Triple& Triple);
305
306   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
307                            const ActionList &Inputs) const;
308 };
309
310 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
311 public:
312   NetBSD(const HostInfo &Host, const llvm::Triple& Triple);
313
314   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
315                            const ActionList &Inputs) const;
316 };
317
318 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC {
319 public:
320   Minix(const HostInfo &Host, const llvm::Triple& Triple);
321
322   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
323                            const ActionList &Inputs) const;
324 };
325
326 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
327 public:
328   DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
329
330   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
331                            const ActionList &Inputs) const;
332 };
333
334 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
335 public:
336   Linux(const HostInfo &Host, const llvm::Triple& Triple);
337
338   virtual bool HasNativeLLVMSupport() const;
339
340   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
341                            const ActionList &Inputs) const;
342
343   std::string Linker;
344   std::vector<std::string> ExtraOpts;
345 };
346
347
348 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
349 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
350 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
351 public:
352   TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
353   ~TCEToolChain();
354
355   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
356                            const ActionList &Inputs) const;
357   bool IsMathErrnoDefault() const;
358   bool IsUnwindTablesDefault() const;
359   const char* GetDefaultRelocationModel() const;
360   const char* GetForcedPicModel() const;
361
362 private:
363   mutable llvm::DenseMap<unsigned, Tool*> Tools;
364
365 };
366
367 class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain {
368   mutable llvm::DenseMap<unsigned, Tool*> Tools;
369
370 public:
371   Windows(const HostInfo &Host, const llvm::Triple& Triple);
372
373   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
374                            const ActionList &Inputs) const;
375
376   virtual bool IsIntegratedAssemblerDefault() const;
377   virtual bool IsUnwindTablesDefault() const;
378   virtual const char *GetDefaultRelocationModel() const;
379   virtual const char *GetForcedPicModel() const;
380 };
381
382 } // end namespace toolchains
383 } // end namespace driver
384 } // end namespace clang
385
386 #endif