blob: aebc8fae4e78f3333b240b78e008182ca6f78f7d [file] [log] [blame]
Daniel Dunbar83b08eb2009-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 Dunbar670b7f42009-03-17 22:07:31 +000013#include "clang/Driver/Action.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000014#include "clang/Driver/ToolChain.h"
15
Daniel Dunbar670b7f42009-03-17 22:07:31 +000016#include "llvm/ADT/DenseMap.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000017#include "llvm/Support/Compiler.h"
18
Daniel Dunbar670b7f42009-03-17 22:07:31 +000019#include "Tools.h"
20
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000021namespace clang {
22namespace driver {
Daniel Dunbar985b8252009-03-17 22:18:43 +000023namespace toolchains {
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000024
Daniel Dunbar670b7f42009-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 Dunbar985b8252009-03-17 22:18:43 +000028class VISIBILITY_HIDDEN Generic_GCC : public ToolChain {
Daniel Dunbar75358d22009-03-30 21:06:03 +000029protected:
Daniel Dunbar670b7f42009-03-17 22:07:31 +000030 mutable llvm::DenseMap<unsigned, Tool*> Tools;
31
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000032public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000033 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar39176082009-03-20 00:20:03 +000034 ~Generic_GCC();
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000035
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +000036 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
37 const char *BoundArch) const;
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000038
Daniel Dunbar39176082009-03-20 00:20:03 +000039 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Daniel Dunbar670b7f42009-03-17 22:07:31 +000040
Daniel Dunbar39176082009-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 Dunbar83b08eb2009-03-17 21:38:00 +000045};
46
Daniel Dunbarf3955282009-09-04 18:34:51 +000047/// Darwin - Darwin tool chain.
48class VISIBILITY_HIDDEN Darwin : public ToolChain {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000049 mutable llvm::DenseMap<unsigned, Tool*> Tools;
50
Daniel Dunbarc50b00d2009-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 Dunbar30392de2009-09-04 18:35:21 +000057 /// Whether this is this an iPhone toolchain.
58 bool IsIPhone;
59
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000060 /// The directory suffix for this tool chain.
61 std::string ToolChainDir;
62
Daniel Dunbar02633b52009-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 Dunbar30392de2009-09-04 18:35:21 +000067 /// The default iphoneos-version-min of this tool chain.
68 std::string IPhoneOSVersionMin;
69
Daniel Dunbar02633b52009-03-26 16:23:12 +000070 const char *getMacosxVersionMin() const;
Daniel Dunbarec069ed2009-03-25 06:58:31 +000071
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000072public:
Mike Stump1eb44332009-09-09 15:08:12 +000073 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar30392de2009-09-04 18:35:21 +000074 const unsigned (&DarwinVersion)[3],
75 const unsigned (&GCCVersion)[3],
76 bool IsIPhone);
Daniel Dunbarf3955282009-09-04 18:34:51 +000077 ~Darwin();
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000078
Daniel Dunbar6b200b22009-09-18 08:14:36 +000079 /// @name Darwin Specific Toolchain API
80 /// {
81
Daniel Dunbar02633b52009-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 Dunbar48d5aae2009-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 Dunbar02633b52009-03-26 16:23:12 +000098 const char *getMacosxVersionStr() const {
99 return MacosxVersionMin.c_str();
100 }
101
Daniel Dunbar30392de2009-09-04 18:35:21 +0000102 const char *getIPhoneOSVersionStr() const {
103 return IPhoneOSVersionMin.c_str();
104 }
105
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000106 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
107 ///
108 /// \param Args - The input argument list.
109 /// \param CmdArgs [out] - The command argument list to append the paths
110 /// (prefixed by -L) to.
111 void AddLinkSearchPathArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
Daniel Dunbar02633b52009-03-26 16:23:12 +0000112
Daniel Dunbar30392de2009-09-04 18:35:21 +0000113 bool isIPhone() const { return IsIPhone; }
114
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000115 /// }
116 /// @name ToolChain Implementation
117 /// {
118
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000119 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
120 const char *BoundArch) const;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000121
122 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
123
124 virtual bool IsMathErrnoDefault() const;
125 virtual bool IsUnwindTablesDefault() const;
126 virtual const char *GetDefaultRelocationModel() const;
127 virtual const char *GetForcedPicModel() const;
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000128
129 /// }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000130};
131
132 /// Darwin_GCC - Generic Darwin tool chain using gcc.
133class VISIBILITY_HIDDEN Darwin_GCC : public Generic_GCC {
134public:
Mike Stump1eb44332009-09-09 15:08:12 +0000135 Darwin_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000136 : Generic_GCC(Host, Triple) {}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000137
138 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
139};
140
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000141class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
142public:
143 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
144
145 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
146};
147
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000148class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
149public:
150 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
151
152 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
153};
154
Daniel Dunbar75358d22009-03-30 21:06:03 +0000155class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
156public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000157 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbar75358d22009-03-30 21:06:03 +0000158
159 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
160};
161
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000162class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
163public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000164 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000165
166 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
167};
168
Eli Friedman6b3454a2009-05-26 07:52:18 +0000169class VISIBILITY_HIDDEN Linux : public Generic_GCC {
170public:
171 Linux(const HostInfo &Host, const llvm::Triple& Triple);
172};
173
174
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000175} // end namespace toolchains
176} // end namespace driver
177} // end namespace clang
178
179#endif