1 //===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
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"
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 {
30 mutable llvm::DenseMap<unsigned, Tool*> Tools;
33 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
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 mutable llvm::DenseMap<unsigned, Tool*> Tools;
47 /// Whether the information on the target has been initialized.
49 // FIXME: This should be eliminated. What we want to do is make this part of
50 // the "default target for arguments" selection process, once we get out of
51 // the argument translation business.
52 mutable bool TargetInitialized;
54 /// Whether we are targetting iPhoneOS target.
55 mutable bool TargetIsIPhoneOS;
57 /// The OS version we are targetting.
58 mutable unsigned TargetVersion[3];
60 /// The default macosx-version-min of this tool chain; empty until
62 std::string MacosxVersionMin;
65 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
66 const unsigned (&DarwinVersion)[3]);
69 /// @name Darwin Specific Toolchain API
72 // FIXME: Eliminate these ...Target functions and derive separate tool chains
73 // for these targets and put version in constructor.
74 void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor,
75 unsigned Micro) const {
76 // FIXME: For now, allow reinitialization as long as values don't
77 // change. This will go away when we move away from argument translation.
78 if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS &&
79 TargetVersion[0] == Major && TargetVersion[1] == Minor &&
80 TargetVersion[2] == Micro)
83 assert(!TargetInitialized && "Target already initialized!");
84 TargetInitialized = true;
85 TargetIsIPhoneOS = isIPhoneOS;
86 TargetVersion[0] = Major;
87 TargetVersion[1] = Minor;
88 TargetVersion[2] = Micro;
91 bool isTargetIPhoneOS() const {
92 assert(TargetInitialized && "Target not initialized!");
93 return TargetIsIPhoneOS;
96 bool isTargetInitialized() const { return TargetInitialized; }
98 void getTargetVersion(unsigned (&Res)[3]) const {
99 assert(TargetInitialized && "Target not initialized!");
100 Res[0] = TargetVersion[0];
101 Res[1] = TargetVersion[1];
102 Res[2] = TargetVersion[2];
105 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
106 /// invocation. For example, Darwin treats different ARM variations as
107 /// distinct architectures.
108 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
110 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
111 for (unsigned i=0; i < 3; ++i) {
112 if (A[i] > B[i]) return false;
113 if (A[i] < B[i]) return true;
118 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
119 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
120 unsigned B[3] = { V0, V1, V2 };
121 return isVersionLT(TargetVersion, B);
124 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
125 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
126 unsigned B[3] = { V0, V1, V2 };
127 return isVersionLT(TargetVersion, B);
130 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
132 /// \param Args - The input argument list.
133 /// \param CmdArgs [out] - The command argument list to append the paths
134 /// (prefixed by -L) to.
135 virtual void AddLinkSearchPathArgs(const ArgList &Args,
136 ArgStringList &CmdArgs) const = 0;
138 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
140 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
141 ArgStringList &CmdArgs) const = 0;
144 /// @name ToolChain Implementation
147 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
148 const char *BoundArch) const;
150 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
152 virtual bool IsBlocksDefault() const {
153 // Blocks default to on for OS X 10.6 and iPhoneOS 3.0 and beyond.
154 if (isTargetIPhoneOS())
155 return !isIPhoneOSVersionLT(3);
157 return !isMacosxVersionLT(10, 6);
159 virtual bool IsIntegratedAssemblerDefault() const {
160 #ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
163 // Default integrated assembler to on for x86.
164 return (getTriple().getArch() == llvm::Triple::x86 ||
165 getTriple().getArch() == llvm::Triple::x86_64);
168 virtual bool IsObjCNonFragileABIDefault() const {
169 // Non-fragile ABI is default for everything but i386.
170 return getTriple().getArch() != llvm::Triple::x86;
172 virtual bool IsObjCLegacyDispatchDefault() const {
173 // This is only used with the non-fragile ABI.
175 // Legacy dispatch is used everywhere except on x86_64.
176 return getTriple().getArch() != llvm::Triple::x86_64;
178 virtual bool UseObjCMixedDispatch() const {
179 // This is only used with the non-fragile ABI and non-legacy dispatch.
181 // Mixed dispatch is used everywhere except OS X before 10.6.
182 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
184 virtual bool IsUnwindTablesDefault() const;
185 virtual unsigned GetDefaultStackProtectorLevel() const {
186 // Stack protectors default to on for 10.6 and beyond.
187 return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
189 virtual const char *GetDefaultRelocationModel() const;
190 virtual const char *GetForcedPicModel() const;
192 virtual bool SupportsObjCGC() const;
194 virtual bool UseDwarfDebugFlags() const;
196 virtual bool UseSjLjExceptions() const;
201 /// DarwinClang - The Darwin toolchain used by Clang.
202 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
204 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
205 const unsigned (&DarwinVersion)[3]);
207 /// @name Darwin ToolChain Implementation
210 virtual void AddLinkSearchPathArgs(const ArgList &Args,
211 ArgStringList &CmdArgs) const;
213 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
214 ArgStringList &CmdArgs) const;
219 /// DarwinGCC - The Darwin toolchain used by GCC.
220 class LLVM_LIBRARY_VISIBILITY DarwinGCC : public Darwin {
221 /// GCC version to use.
222 unsigned GCCVersion[3];
224 /// The directory suffix for this tool chain.
225 std::string ToolChainDir;
228 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
229 const unsigned (&DarwinVersion)[3],
230 const unsigned (&GCCVersion)[3]);
232 /// @name Darwin ToolChain Implementation
235 virtual void AddLinkSearchPathArgs(const ArgList &Args,
236 ArgStringList &CmdArgs) const;
238 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
239 ArgStringList &CmdArgs) const;
244 /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
245 class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
247 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
248 : Generic_GCC(Host, Triple) {}
250 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
253 class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
255 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
257 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
260 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_GCC {
262 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
264 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
267 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_GCC {
269 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
271 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
274 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC {
276 Minix(const HostInfo &Host, const llvm::Triple& Triple);
278 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
281 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_GCC {
283 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
285 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
288 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_GCC {
290 Linux(const HostInfo &Host, const llvm::Triple& Triple);
294 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
295 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
296 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
298 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
301 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
302 bool IsMathErrnoDefault() const;
303 bool IsUnwindTablesDefault() const;
304 const char* GetDefaultRelocationModel() const;
305 const char* GetForcedPicModel() const;
308 mutable llvm::DenseMap<unsigned, Tool*> Tools;
312 } // end namespace toolchains
313 } // end namespace driver
314 } // end namespace clang