Driver: tweak handling of '--analyze' to invoke
[clang.git] / lib / Driver / ToolChains.h
blob33b805345321b1cca716c3f6e6ee155faf457ba0
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 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_LIB_DRIVER_TOOLCHAINS_H_
11 #define CLANG_LIB_DRIVER_TOOLCHAINS_H_
13 #include "clang/Driver/Action.h"
14 #include "clang/Driver/ToolChain.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/Support/Compiler.h"
19 #include "Tools.h"
21 namespace clang {
22 namespace driver {
23 namespace toolchains {
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;
32 public:
33 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
34 ~Generic_GCC();
36 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
38 virtual bool IsUnwindTablesDefault() const;
39 virtual const char *GetDefaultRelocationModel() const;
40 virtual const char *GetForcedPicModel() const;
43 /// Darwin - The base Darwin tool chain.
44 class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
45 public:
46 /// The host version.
47 unsigned DarwinVersion[3];
49 private:
50 mutable llvm::DenseMap<unsigned, Tool*> Tools;
52 /// Whether the information on the target has been initialized.
54 // FIXME: This should be eliminated. What we want to do is make this part of
55 // the "default target for arguments" selection process, once we get out of
56 // the argument translation business.
57 mutable bool TargetInitialized;
59 /// Whether we are targetting iPhoneOS target.
60 mutable bool TargetIsIPhoneOS;
62 /// The OS version we are targetting.
63 mutable unsigned TargetVersion[3];
65 /// The default macosx-version-min of this tool chain; empty until
66 /// initialized.
67 std::string MacosxVersionMin;
69 private:
70 void AddDeploymentTarget(DerivedArgList &Args) const;
72 public:
73 Darwin(const HostInfo &Host, const llvm::Triple& Triple);
74 ~Darwin();
76 std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
78 /// @name Darwin Specific Toolchain API
79 /// {
81 // FIXME: Eliminate these ...Target functions and derive separate tool chains
82 // for these targets and put version in constructor.
83 void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor,
84 unsigned Micro) const {
85 // FIXME: For now, allow reinitialization as long as values don't
86 // change. This will go away when we move away from argument translation.
87 if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS &&
88 TargetVersion[0] == Major && TargetVersion[1] == Minor &&
89 TargetVersion[2] == Micro)
90 return;
92 assert(!TargetInitialized && "Target already initialized!");
93 TargetInitialized = true;
94 TargetIsIPhoneOS = isIPhoneOS;
95 TargetVersion[0] = Major;
96 TargetVersion[1] = Minor;
97 TargetVersion[2] = Micro;
100 bool isTargetIPhoneOS() const {
101 assert(TargetInitialized && "Target not initialized!");
102 return TargetIsIPhoneOS;
105 bool isTargetInitialized() const { return TargetInitialized; }
107 void getTargetVersion(unsigned (&Res)[3]) const {
108 assert(TargetInitialized && "Target not initialized!");
109 Res[0] = TargetVersion[0];
110 Res[1] = TargetVersion[1];
111 Res[2] = TargetVersion[2];
114 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
115 /// invocation. For example, Darwin treats different ARM variations as
116 /// distinct architectures.
117 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
119 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
120 for (unsigned i=0; i < 3; ++i) {
121 if (A[i] > B[i]) return false;
122 if (A[i] < B[i]) return true;
124 return false;
127 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
128 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
129 unsigned B[3] = { V0, V1, V2 };
130 return isVersionLT(TargetVersion, B);
133 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
134 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
135 unsigned B[3] = { V0, V1, V2 };
136 return isVersionLT(TargetVersion, B);
139 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
141 /// \param Args - The input argument list.
142 /// \param CmdArgs [out] - The command argument list to append the paths
143 /// (prefixed by -L) to.
144 virtual void AddLinkSearchPathArgs(const ArgList &Args,
145 ArgStringList &CmdArgs) const = 0;
147 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
148 /// runtime library.
149 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
150 ArgStringList &CmdArgs) const = 0;
152 /// }
153 /// @name ToolChain Implementation
154 /// {
156 virtual types::ID LookupTypeForExtension(const char *Ext) const;
158 virtual bool HasNativeLLVMSupport() const;
160 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
161 const char *BoundArch) const;
163 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
165 virtual bool IsBlocksDefault() const {
166 // Always allow blocks on Darwin; users interested in versioning are
167 // expected to use /usr/include/Blocks.h.
168 return true;
170 virtual bool IsIntegratedAssemblerDefault() const {
171 #ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
172 return false;
173 #else
174 // Default integrated assembler to on for x86.
175 return (getTriple().getArch() == llvm::Triple::x86 ||
176 getTriple().getArch() == llvm::Triple::x86_64);
177 #endif
180 virtual bool IsObjCDefaultSynthPropertiesDefault() const {
181 // Always allow default synthesized properties on Darwin.
182 return true;
185 virtual bool IsObjCNonFragileABIDefault() const {
186 // Non-fragile ABI is default for everything but i386.
187 return getTriple().getArch() != llvm::Triple::x86;
189 virtual bool IsObjCLegacyDispatchDefault() const {
190 // This is only used with the non-fragile ABI.
192 // Legacy dispatch is used everywhere except on x86_64.
193 return getTriple().getArch() != llvm::Triple::x86_64;
195 virtual bool UseObjCMixedDispatch() const {
196 // This is only used with the non-fragile ABI and non-legacy dispatch.
198 // Mixed dispatch is used everywhere except OS X before 10.6.
199 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
201 virtual bool IsUnwindTablesDefault() const;
202 virtual unsigned GetDefaultStackProtectorLevel() const {
203 // Stack protectors default to on for 10.6 and beyond.
204 return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
206 virtual const char *GetDefaultRelocationModel() const;
207 virtual const char *GetForcedPicModel() const;
209 virtual bool SupportsObjCGC() const;
211 virtual bool UseDwarfDebugFlags() const;
213 virtual bool UseSjLjExceptions() const;
215 /// }
218 /// DarwinClang - The Darwin toolchain used by Clang.
219 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
220 public:
221 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple);
223 /// @name Darwin ToolChain Implementation
224 /// {
226 virtual void AddLinkSearchPathArgs(const ArgList &Args,
227 ArgStringList &CmdArgs) const;
229 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
230 ArgStringList &CmdArgs) const;
232 virtual void AddCXXStdlibLibArgs(const ArgList &Args,
233 ArgStringList &CmdArgs) const;
235 virtual void AddCCKextLibArgs(const ArgList &Args,
236 ArgStringList &CmdArgs) const;
238 /// }
241 /// DarwinGCC - The Darwin toolchain used by GCC.
242 class LLVM_LIBRARY_VISIBILITY DarwinGCC : public Darwin {
243 /// GCC version to use.
244 unsigned GCCVersion[3];
246 /// The directory suffix for this tool chain.
247 std::string ToolChainDir;
249 public:
250 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple);
252 /// @name Darwin ToolChain Implementation
253 /// {
255 virtual void AddLinkSearchPathArgs(const ArgList &Args,
256 ArgStringList &CmdArgs) const;
258 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
259 ArgStringList &CmdArgs) const;
261 /// }
264 /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
265 class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
266 public:
267 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
268 : Generic_GCC(Host, Triple) {}
270 std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
272 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
275 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
276 public:
277 Generic_ELF(const HostInfo &Host, const llvm::Triple& Triple)
278 : Generic_GCC(Host, Triple) {}
280 virtual bool IsIntegratedAssemblerDefault() const {
281 // Default integrated assembler to on for x86.
282 return (getTriple().getArch() == llvm::Triple::x86 ||
283 getTriple().getArch() == llvm::Triple::x86_64);
287 class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
288 public:
289 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
291 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
294 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
295 public:
296 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
298 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
301 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
302 public:
303 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple);
305 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
308 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC {
309 public:
310 Minix(const HostInfo &Host, const llvm::Triple& Triple);
312 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
315 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
316 public:
317 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
319 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
322 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
323 public:
324 Linux(const HostInfo &Host, const llvm::Triple& Triple);
326 virtual bool HasNativeLLVMSupport() const;
328 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
330 std::string Linker;
331 std::vector<std::string> ExtraOpts;
335 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
336 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
337 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
338 public:
339 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
340 ~TCEToolChain();
342 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
343 bool IsMathErrnoDefault() const;
344 bool IsUnwindTablesDefault() const;
345 const char* GetDefaultRelocationModel() const;
346 const char* GetForcedPicModel() const;
348 private:
349 mutable llvm::DenseMap<unsigned, Tool*> Tools;
353 class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain {
354 mutable llvm::DenseMap<unsigned, Tool*> Tools;
356 public:
357 Windows(const HostInfo &Host, const llvm::Triple& Triple);
359 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
361 virtual bool IsIntegratedAssemblerDefault() const;
362 virtual bool IsUnwindTablesDefault() const;
363 virtual const char *GetDefaultRelocationModel() const;
364 virtual const char *GetForcedPicModel() const;
367 } // end namespace toolchains
368 } // end namespace driver
369 } // end namespace clang
371 #endif