blob: 91e5750dd63be3aea0233e10f5a80e37e0468962 [file] [log] [blame]
Daniel Dunbar0a248bb2009-03-17 21:38:00 +00001//===--- 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
Daniel Dunbar04cb0292009-03-17 22:07:31 +000013#include "clang/Driver/Action.h"
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000014#include "clang/Driver/ToolChain.h"
15
Daniel Dunbar04cb0292009-03-17 22:07:31 +000016#include "llvm/ADT/DenseMap.h"
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000017#include "llvm/Support/Compiler.h"
18
Daniel Dunbar04cb0292009-03-17 22:07:31 +000019#include "Tools.h"
20
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000021namespace clang {
22namespace driver {
Daniel Dunbar15abb2e2009-03-17 22:18:43 +000023namespace toolchains {
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000024
Daniel Dunbar04cb0292009-03-17 22:07:31 +000025 /// 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.
Daniel Dunbar15abb2e2009-03-17 22:18:43 +000028class VISIBILITY_HIDDEN Generic_GCC : public ToolChain {
Daniel Dunbare24297c2009-03-30 21:06:03 +000029protected:
Daniel Dunbar04cb0292009-03-17 22:07:31 +000030 mutable llvm::DenseMap<unsigned, Tool*> Tools;
31
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000032public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +000033 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar59e5e882009-03-20 00:20:03 +000034 ~Generic_GCC();
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000035
Daniel Dunbare7af3412009-09-09 18:36:12 +000036 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
37 const char *BoundArch) const;
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000038
Daniel Dunbar59e5e882009-03-20 00:20:03 +000039 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Daniel Dunbar04cb0292009-03-17 22:07:31 +000040
Daniel Dunbar59e5e882009-03-20 00:20:03 +000041 virtual bool IsMathErrnoDefault() const;
42 virtual bool IsUnwindTablesDefault() const;
43 virtual const char *GetDefaultRelocationModel() const;
44 virtual const char *GetForcedPicModel() const;
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000045};
46
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000047/// Darwin - Darwin tool chain.
48class VISIBILITY_HIDDEN Darwin : public ToolChain {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000049 mutable llvm::DenseMap<unsigned, Tool*> Tools;
50
Daniel Dunbar76ce7412009-03-23 16:15:50 +000051 /// Darwin version of tool chain.
52 unsigned DarwinVersion[3];
53
54 /// GCC version to use.
55 unsigned GCCVersion[3];
56
Daniel Dunbar84e727f2009-09-04 18:35:21 +000057 /// Whether this is this an iPhone toolchain.
58 bool IsIPhone;
59
Daniel Dunbar76ce7412009-03-23 16:15:50 +000060 /// The directory suffix for this tool chain.
61 std::string ToolChainDir;
62
Daniel Dunbarc1964212009-03-26 16:23:12 +000063 /// The default macosx-version-min of this tool chain; empty until
64 /// initialized.
65 mutable std::string MacosxVersionMin;
66
Daniel Dunbar84e727f2009-09-04 18:35:21 +000067 /// The default iphoneos-version-min of this tool chain.
68 std::string IPhoneOSVersionMin;
69
Daniel Dunbarc1964212009-03-26 16:23:12 +000070 const char *getMacosxVersionMin() const;
Daniel Dunbar0af75a12009-03-25 06:58:31 +000071
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000072public:
Mike Stump11289f42009-09-09 15:08:12 +000073 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar84e727f2009-09-04 18:35:21 +000074 const unsigned (&DarwinVersion)[3],
75 const unsigned (&GCCVersion)[3],
76 bool IsIPhone);
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000077 ~Darwin();
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000078
Daniel Dunbar4c30b892009-09-18 08:14:36 +000079 /// @name Darwin Specific Toolchain API
80 /// {
81
Daniel Dunbarc1964212009-03-26 16:23:12 +000082 void getDarwinVersion(unsigned (&Res)[3]) const {
83 Res[0] = DarwinVersion[0];
84 Res[1] = DarwinVersion[1];
85 Res[2] = DarwinVersion[2];
86 }
87
88 void getMacosxVersion(unsigned (&Res)[3]) const {
89 Res[0] = 10;
90 Res[1] = DarwinVersion[0] - 4;
91 Res[2] = DarwinVersion[1];
92 }
93
Daniel Dunbar510d8a82009-09-18 08:14:46 +000094 /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is
95 /// either the -mmacosx-version-min, or the current version if unspecified.
96 void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const;
97
Daniel Dunbard5bd81e2009-09-18 08:14:55 +000098 static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
99 for (unsigned i=0; i < 3; ++i) {
100 if (A[i] > B[i]) return false;
101 if (A[i] < B[i]) return true;
102 }
103 return false;
104 }
105
106 static bool isMacosxVersionLT(unsigned (&A)[3],
107 unsigned V0, unsigned V1=0, unsigned V2=0) {
108 unsigned B[3] = { V0, V1, V2 };
109 return isMacosxVersionLT(A, B);
110 }
111
Daniel Dunbarc1964212009-03-26 16:23:12 +0000112 const char *getMacosxVersionStr() const {
113 return MacosxVersionMin.c_str();
114 }
115
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000116 const char *getIPhoneOSVersionStr() const {
117 return IPhoneOSVersionMin.c_str();
118 }
119
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000120 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
121 ///
122 /// \param Args - The input argument list.
123 /// \param CmdArgs [out] - The command argument list to append the paths
124 /// (prefixed by -L) to.
125 void AddLinkSearchPathArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
Daniel Dunbarc1964212009-03-26 16:23:12 +0000126
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000127 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
128 /// runtime library.
129 void AddLinkRuntimeLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
130
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000131 bool isIPhone() const { return IsIPhone; }
132
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000133 /// }
134 /// @name ToolChain Implementation
135 /// {
136
Daniel Dunbare7af3412009-09-09 18:36:12 +0000137 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
138 const char *BoundArch) const;
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000139
140 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
141
142 virtual bool IsMathErrnoDefault() const;
143 virtual bool IsUnwindTablesDefault() const;
144 virtual const char *GetDefaultRelocationModel() const;
145 virtual const char *GetForcedPicModel() const;
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000146
147 /// }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000148};
149
150 /// Darwin_GCC - Generic Darwin tool chain using gcc.
151class VISIBILITY_HIDDEN Darwin_GCC : public Generic_GCC {
152public:
Mike Stump11289f42009-09-09 15:08:12 +0000153 Darwin_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000154 : Generic_GCC(Host, Triple) {}
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000155
156 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
157};
158
Edward O'Callaghan856e4ff2009-08-22 01:06:46 +0000159class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
160public:
161 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
162
163 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
164};
165
Daniel Dunbar10de9e62009-06-29 20:52:51 +0000166class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
167public:
168 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
169
170 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
171};
172
Daniel Dunbare24297c2009-03-30 21:06:03 +0000173class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
174public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000175 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbare24297c2009-03-30 21:06:03 +0000176
177 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
178};
179
Daniel Dunbarcc912342009-05-02 18:28:39 +0000180class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
181public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000182 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarcc912342009-05-02 18:28:39 +0000183
184 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
185};
186
Eli Friedman5cd659f2009-05-26 07:52:18 +0000187class VISIBILITY_HIDDEN Linux : public Generic_GCC {
188public:
189 Linux(const HostInfo &Host, const llvm::Triple& Triple);
190};
191
192
Daniel Dunbar0a248bb2009-03-17 21:38:00 +0000193} // end namespace toolchains
194} // end namespace driver
195} // end namespace clang
196
197#endif