]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/Driver/ToolChains.h
Update clang to r99115.
[FreeBSD/FreeBSD.git] / 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 VISIBILITY_HIDDEN 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 DerivedArgList *TranslateArgs(InputArgList &Args,
37                                         const char *BoundArch) const;
38
39   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
40
41   virtual bool IsUnwindTablesDefault() const;
42   virtual const char *GetDefaultRelocationModel() const;
43   virtual const char *GetForcedPicModel() const;
44 };
45
46 /// Darwin - The base Darwin tool chain.
47 class VISIBILITY_HIDDEN Darwin : public ToolChain {
48   mutable llvm::DenseMap<unsigned, Tool*> Tools;
49
50   /// Whether the information on the target has been initialized.
51   //
52   // FIXME: This should be eliminated. What we want to do is make this part of
53   // the "default target for arguments" selection process, once we get out of
54   // the argument translation business.
55   mutable bool TargetInitialized;
56
57   /// Whether we are targetting iPhoneOS target.
58   mutable bool TargetIsIPhoneOS;
59   
60   /// The OS version we are targetting.
61   mutable unsigned TargetVersion[3];
62
63   /// The default macosx-version-min of this tool chain; empty until
64   /// initialized.
65   std::string MacosxVersionMin;
66
67 public:
68   Darwin(const HostInfo &Host, const llvm::Triple& Triple,
69          const unsigned (&DarwinVersion)[3]);
70   ~Darwin();
71
72   /// @name Darwin Specific Toolchain API
73   /// {
74
75   // FIXME: Eliminate these ...Target functions and derive separate tool chains
76   // for these targets and put version in constructor.
77   void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor,
78                  unsigned Micro) const {
79     // FIXME: For now, allow reinitialization as long as values don't
80     // change. This will go away when we move away from argument translation.
81     if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS &&
82         TargetVersion[0] == Major && TargetVersion[1] == Minor &&
83         TargetVersion[2] == Micro)
84       return;
85
86     assert(!TargetInitialized && "Target already initialized!");
87     TargetInitialized = true;
88     TargetIsIPhoneOS = isIPhoneOS;
89     TargetVersion[0] = Major;
90     TargetVersion[1] = Minor;
91     TargetVersion[2] = Micro;
92   }
93
94   bool isTargetIPhoneOS() const {
95     assert(TargetInitialized && "Target not initialized!");
96     return TargetIsIPhoneOS;
97   }
98
99   bool isTargetInitialized() const { return TargetInitialized; }
100
101   void getTargetVersion(unsigned (&Res)[3]) const {
102     assert(TargetInitialized && "Target not initialized!");
103     Res[0] = TargetVersion[0];
104     Res[1] = TargetVersion[1];
105     Res[2] = TargetVersion[2];
106   }
107
108   /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
109   /// invocation. For example, Darwin treats different ARM variations as
110   /// distinct architectures.
111   llvm::StringRef getDarwinArchName(const ArgList &Args) const;
112
113   static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
114     for (unsigned i=0; i < 3; ++i) {
115       if (A[i] > B[i]) return false;
116       if (A[i] < B[i]) return true;
117     }
118     return false;
119   }
120
121   bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
122     assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
123     unsigned B[3] = { V0, V1, V2 };
124     return isVersionLT(TargetVersion, B);
125   }
126
127   bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
128     assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
129     unsigned B[3] = { V0, V1, V2 };
130     return isVersionLT(TargetVersion, B);
131   }
132
133   /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
134   ///
135   /// \param Args - The input argument list.
136   /// \param CmdArgs [out] - The command argument list to append the paths
137   /// (prefixed by -L) to.
138   virtual void AddLinkSearchPathArgs(const ArgList &Args,
139                                      ArgStringList &CmdArgs) const = 0;
140
141   /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
142   /// runtime library.
143   virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
144                                      ArgStringList &CmdArgs) const = 0;
145
146   /// }
147   /// @name ToolChain Implementation
148   /// {
149
150   virtual DerivedArgList *TranslateArgs(InputArgList &Args,
151                                         const char *BoundArch) const;
152
153   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
154
155   virtual bool IsBlocksDefault() const {
156     // Blocks default to on for OS X 10.6 and iPhoneOS 3.0 and beyond.
157     if (isTargetIPhoneOS())
158       return !isIPhoneOSVersionLT(3);
159     else
160       return !isMacosxVersionLT(10, 6);
161   }
162   virtual bool IsObjCNonFragileABIDefault() const {
163     // Non-fragile ABI default to on for iPhoneOS and x86-64.
164     return isTargetIPhoneOS() || getTriple().getArch() == llvm::Triple::x86_64;
165   }
166   virtual bool IsObjCLegacyDispatchDefault() const {
167     // This is only used with the non-fragile ABI.
168     return (getTriple().getArch() == llvm::Triple::arm ||
169             getTriple().getArch() == llvm::Triple::thumb);
170   }
171   virtual bool IsUnwindTablesDefault() const;
172   virtual unsigned GetDefaultStackProtectorLevel() const {
173     // Stack protectors default to on for 10.6 and beyond.
174     return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
175   }
176   virtual const char *GetDefaultRelocationModel() const;
177   virtual const char *GetForcedPicModel() const;
178
179   virtual bool UseDwarfDebugFlags() const;
180
181   virtual bool UseSjLjExceptions() const;
182
183   /// }
184 };
185
186 /// DarwinClang - The Darwin toolchain used by Clang.
187 class VISIBILITY_HIDDEN DarwinClang : public Darwin {
188 public:
189   DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
190               const unsigned (&DarwinVersion)[3]);
191
192   /// @name Darwin ToolChain Implementation
193   /// {
194
195   virtual void AddLinkSearchPathArgs(const ArgList &Args,
196                                     ArgStringList &CmdArgs) const;
197
198   virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
199                                      ArgStringList &CmdArgs) const;
200
201   /// }
202 };
203
204 /// DarwinGCC - The Darwin toolchain used by GCC.
205 class VISIBILITY_HIDDEN DarwinGCC : public Darwin {
206   /// GCC version to use.
207   unsigned GCCVersion[3];
208
209   /// The directory suffix for this tool chain.
210   std::string ToolChainDir;
211
212 public:
213   DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
214             const unsigned (&DarwinVersion)[3],
215             const unsigned (&GCCVersion)[3]);
216
217   /// @name Darwin ToolChain Implementation
218   /// {
219
220   virtual void AddLinkSearchPathArgs(const ArgList &Args,
221                                     ArgStringList &CmdArgs) const;
222
223   virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
224                                      ArgStringList &CmdArgs) const;
225
226   /// }
227 };
228
229 /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
230 class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC {
231 public:
232   Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
233     : Generic_GCC(Host, Triple) {}
234
235   virtual const char *GetDefaultRelocationModel() const { return "pic"; }
236 };
237
238 class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
239 public:
240   AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
241
242   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
243 };
244
245 class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
246 public:
247   OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
248
249   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
250 };
251
252 class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
253 public:
254   FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
255
256   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
257 };
258
259 class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
260 public:
261   DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
262
263   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
264 };
265
266 class VISIBILITY_HIDDEN Linux : public Generic_GCC {
267 public:
268   Linux(const HostInfo &Host, const llvm::Triple& Triple);
269 };
270
271
272 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
273 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
274 class VISIBILITY_HIDDEN TCEToolChain : public ToolChain {
275 public:
276   TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
277   ~TCEToolChain();
278
279   virtual DerivedArgList *TranslateArgs(InputArgList &Args,
280                                         const char *BoundArch) const;
281   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
282   bool IsMathErrnoDefault() const;
283   bool IsUnwindTablesDefault() const;
284   const char* GetDefaultRelocationModel() const;
285   const char* GetForcedPicModel() const;
286
287 private:
288   mutable llvm::DenseMap<unsigned, Tool*> Tools;
289
290 };
291
292 } // end namespace toolchains
293 } // end namespace driver
294 } // end namespace clang
295
296 #endif