ToolChains.h revision 6cd4154b9088fa18ae05d11c0f3140fafd76c734
183b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar//===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
283b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar//
383b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar//                     The LLVM Compiler Infrastructure
483b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar//
583b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar// This file is distributed under the University of Illinois Open Source
683b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar// License. See LICENSE.TXT for details.
783b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar//
883b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar//===----------------------------------------------------------------------===//
983b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar
1083b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar#ifndef CLANG_LIB_DRIVER_TOOLCHAINS_H_
1183b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar#define CLANG_LIB_DRIVER_TOOLCHAINS_H_
1283b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar
13670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar#include "clang/Driver/Action.h"
1483b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar#include "clang/Driver/ToolChain.h"
1583b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar
16670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar#include "llvm/ADT/DenseMap.h"
1783b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar#include "llvm/Support/Compiler.h"
1883b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar
19670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar#include "Tools.h"
20670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar
2183b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbarnamespace clang {
2283b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbarnamespace driver {
23985b825eea7387be10478de0430815ed6a673326Daniel Dunbarnamespace toolchains {
2483b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar
25670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar  /// Generic_GCC - A tool chain using the 'gcc' command to perform
26670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar  /// all subcommands; this relies on gcc translating the majority of
27670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar  /// command line options.
28985b825eea7387be10478de0430815ed6a673326Daniel Dunbarclass VISIBILITY_HIDDEN Generic_GCC : public ToolChain {
2975358d267256022475371416654b056ad8531cb3Daniel Dunbarprotected:
30670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar  mutable llvm::DenseMap<unsigned, Tool*> Tools;
31670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar
3283b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbarpublic:
33cb8ab23f7c800b041aeb6fc38c341d1aa0da86bfDaniel Dunbar  Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
343917608370583fa30c466b6c3893448229aea9adDaniel Dunbar  ~Generic_GCC();
3583b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar
360dcb9a3705743ec972af37f48ead81a0939e3958Daniel Dunbar  virtual DerivedArgList *TranslateArgs(InputArgList &Args,
370dcb9a3705743ec972af37f48ead81a0939e3958Daniel Dunbar                                        const char *BoundArch) const;
3883b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar
393917608370583fa30c466b6c3893448229aea9adDaniel Dunbar  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
40670b7f4fe6720e91520ec5a993b33c00058ed77aDaniel Dunbar
413917608370583fa30c466b6c3893448229aea9adDaniel Dunbar  virtual bool IsMathErrnoDefault() const;
423917608370583fa30c466b6c3893448229aea9adDaniel Dunbar  virtual bool IsUnwindTablesDefault() const;
433917608370583fa30c466b6c3893448229aea9adDaniel Dunbar  virtual const char *GetDefaultRelocationModel() const;
443917608370583fa30c466b6c3893448229aea9adDaniel Dunbar  virtual const char *GetForcedPicModel() const;
4583b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar};
4683b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar
47f395528158379e7ea9f6ff4bbb791abadca15aabDaniel Dunbar/// Darwin - Darwin tool chain.
48f395528158379e7ea9f6ff4bbb791abadca15aabDaniel Dunbarclass VISIBILITY_HIDDEN Darwin : public ToolChain {
498eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar  mutable llvm::DenseMap<unsigned, Tool*> Tools;
508eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar
51c50b00dbd843cd929b5f220d4a8699852249f64cDaniel Dunbar  /// Darwin version of tool chain.
52c50b00dbd843cd929b5f220d4a8699852249f64cDaniel Dunbar  unsigned DarwinVersion[3];
53c50b00dbd843cd929b5f220d4a8699852249f64cDaniel Dunbar
54c50b00dbd843cd929b5f220d4a8699852249f64cDaniel Dunbar  /// GCC version to use.
55c50b00dbd843cd929b5f220d4a8699852249f64cDaniel Dunbar  unsigned GCCVersion[3];
56c50b00dbd843cd929b5f220d4a8699852249f64cDaniel Dunbar
5730392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar  /// Whether this is this an iPhone toolchain.
5830392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar  bool IsIPhone;
5930392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar
60c50b00dbd843cd929b5f220d4a8699852249f64cDaniel Dunbar  /// The directory suffix for this tool chain.
61c50b00dbd843cd929b5f220d4a8699852249f64cDaniel Dunbar  std::string ToolChainDir;
62c50b00dbd843cd929b5f220d4a8699852249f64cDaniel Dunbar
6302633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  /// The default macosx-version-min of this tool chain; empty until
6402633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  /// initialized.
6502633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  mutable std::string MacosxVersionMin;
6602633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar
6730392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar  /// The default iphoneos-version-min of this tool chain.
6830392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar  std::string IPhoneOSVersionMin;
6930392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar
7002633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  const char *getMacosxVersionMin() const;
71ec069ed8a6647d84cc3a58d46d5b2a3c9f000704Daniel Dunbar
728eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbarpublic:
731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Darwin(const HostInfo &Host, const llvm::Triple& Triple,
7430392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar         const unsigned (&DarwinVersion)[3],
7530392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar         const unsigned (&GCCVersion)[3],
7630392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar         bool IsIPhone);
77f395528158379e7ea9f6ff4bbb791abadca15aabDaniel Dunbar  ~Darwin();
788eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar
796b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// @name Darwin Specific Toolchain API
806b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// {
816b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar
8202633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  void getDarwinVersion(unsigned (&Res)[3]) const {
8302633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar    Res[0] = DarwinVersion[0];
8402633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar    Res[1] = DarwinVersion[1];
8502633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar    Res[2] = DarwinVersion[2];
8602633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  }
8702633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar
8802633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  void getMacosxVersion(unsigned (&Res)[3]) const {
8902633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar    Res[0] = 10;
9002633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar    Res[1] = DarwinVersion[0] - 4;
9102633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar    Res[2] = DarwinVersion[1];
9202633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  }
9302633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar
9448d5aae4387f07aef99dbe03f4047d709e9f4d35Daniel Dunbar  /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is
9548d5aae4387f07aef99dbe03f4047d709e9f4d35Daniel Dunbar  /// either the -mmacosx-version-min, or the current version if unspecified.
9648d5aae4387f07aef99dbe03f4047d709e9f4d35Daniel Dunbar  void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const;
9748d5aae4387f07aef99dbe03f4047d709e9f4d35Daniel Dunbar
98608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar  static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
99608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar    for (unsigned i=0; i < 3; ++i) {
100608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar      if (A[i] > B[i]) return false;
101608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar      if (A[i] < B[i]) return true;
102608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar    }
103608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar    return false;
104608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar  }
105608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar
106608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar  static bool isMacosxVersionLT(unsigned (&A)[3],
107608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar                                unsigned V0, unsigned V1=0, unsigned V2=0) {
108608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar    unsigned B[3] = { V0, V1, V2 };
109608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar    return isMacosxVersionLT(A, B);
110608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar  }
111608d04cb7bee2db28c8689f6626bf9e0b114c473Daniel Dunbar
11202633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  const char *getMacosxVersionStr() const {
11302633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar    return MacosxVersionMin.c_str();
11402633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar  }
11502633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar
11630392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar  const char *getIPhoneOSVersionStr() const {
11730392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar    return IPhoneOSVersionMin.c_str();
11830392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar  }
11930392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar
1206b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
1216b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  ///
1226b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// \param Args - The input argument list.
1236b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// \param CmdArgs [out] - The command argument list to append the paths
1246b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// (prefixed by -L) to.
1256b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  void AddLinkSearchPathArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
12602633b541b04ad5ffc1c70f4c2feeeb13e607057Daniel Dunbar
1276cd4154b9088fa18ae05d11c0f3140fafd76c734Daniel Dunbar  /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
1286cd4154b9088fa18ae05d11c0f3140fafd76c734Daniel Dunbar  /// runtime library.
1296cd4154b9088fa18ae05d11c0f3140fafd76c734Daniel Dunbar  void AddLinkRuntimeLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
1306cd4154b9088fa18ae05d11c0f3140fafd76c734Daniel Dunbar
13130392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar  bool isIPhone() const { return IsIPhone; }
13230392de4681602f1aabc61b0184b1de53bc172f0Daniel Dunbar
1336b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// }
1346b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// @name ToolChain Implementation
1356b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// {
1366b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar
1370dcb9a3705743ec972af37f48ead81a0939e3958Daniel Dunbar  virtual DerivedArgList *TranslateArgs(InputArgList &Args,
1380dcb9a3705743ec972af37f48ead81a0939e3958Daniel Dunbar                                        const char *BoundArch) const;
1398eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar
1408eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
1418eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar
1428eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar  virtual bool IsMathErrnoDefault() const;
1438eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar  virtual bool IsUnwindTablesDefault() const;
1448eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar  virtual const char *GetDefaultRelocationModel() const;
1458eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar  virtual const char *GetForcedPicModel() const;
1466b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar
1476b200b2b698b6ac9e310f2225c69c85d28ae4fb0Daniel Dunbar  /// }
1488eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar};
1498eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar
1508eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar  /// Darwin_GCC - Generic Darwin tool chain using gcc.
1518eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbarclass VISIBILITY_HIDDEN Darwin_GCC : public Generic_GCC {
1528eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbarpublic:
1531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Darwin_GCC(const HostInfo &Host, const llvm::Triple& Triple)
154cb8ab23f7c800b041aeb6fc38c341d1aa0da86bfDaniel Dunbar    : Generic_GCC(Host, Triple) {}
1558eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar
1568eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar  virtual const char *GetDefaultRelocationModel() const { return "pic"; }
1578eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar};
1588eddb3fb6ff3dd20e3920380e1ce56df105b8a98Daniel Dunbar
159e7925a075f110ab21afeae084670a155dea568e3Edward O'Callaghanclass VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
160e7925a075f110ab21afeae084670a155dea568e3Edward O'Callaghanpublic:
161e7925a075f110ab21afeae084670a155dea568e3Edward O'Callaghan  AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
162e7925a075f110ab21afeae084670a155dea568e3Edward O'Callaghan
163e7925a075f110ab21afeae084670a155dea568e3Edward O'Callaghan  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
164e7925a075f110ab21afeae084670a155dea568e3Edward O'Callaghan};
165e7925a075f110ab21afeae084670a155dea568e3Edward O'Callaghan
166f7b8eec37c8c8012fa525c71fb29a58c9f29beefDaniel Dunbarclass VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
167f7b8eec37c8c8012fa525c71fb29a58c9f29beefDaniel Dunbarpublic:
168f7b8eec37c8c8012fa525c71fb29a58c9f29beefDaniel Dunbar  OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
169f7b8eec37c8c8012fa525c71fb29a58c9f29beefDaniel Dunbar
170f7b8eec37c8c8012fa525c71fb29a58c9f29beefDaniel Dunbar  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
171f7b8eec37c8c8012fa525c71fb29a58c9f29beefDaniel Dunbar};
172f7b8eec37c8c8012fa525c71fb29a58c9f29beefDaniel Dunbar
17375358d267256022475371416654b056ad8531cb3Daniel Dunbarclass VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
17475358d267256022475371416654b056ad8531cb3Daniel Dunbarpublic:
175cb8ab23f7c800b041aeb6fc38c341d1aa0da86bfDaniel Dunbar  FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
17675358d267256022475371416654b056ad8531cb3Daniel Dunbar
17775358d267256022475371416654b056ad8531cb3Daniel Dunbar  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
17875358d267256022475371416654b056ad8531cb3Daniel Dunbar};
17975358d267256022475371416654b056ad8531cb3Daniel Dunbar
18011e1b40d759a643086f590f6ffbd9d68360bad46Daniel Dunbarclass VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
18111e1b40d759a643086f590f6ffbd9d68360bad46Daniel Dunbarpublic:
182cb8ab23f7c800b041aeb6fc38c341d1aa0da86bfDaniel Dunbar  DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
18311e1b40d759a643086f590f6ffbd9d68360bad46Daniel Dunbar
18411e1b40d759a643086f590f6ffbd9d68360bad46Daniel Dunbar  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
18511e1b40d759a643086f590f6ffbd9d68360bad46Daniel Dunbar};
18611e1b40d759a643086f590f6ffbd9d68360bad46Daniel Dunbar
1876b3454a219cee5ef36c4668961f93a5c32deab61Eli Friedmanclass VISIBILITY_HIDDEN Linux : public Generic_GCC {
1886b3454a219cee5ef36c4668961f93a5c32deab61Eli Friedmanpublic:
1896b3454a219cee5ef36c4668961f93a5c32deab61Eli Friedman  Linux(const HostInfo &Host, const llvm::Triple& Triple);
1906b3454a219cee5ef36c4668961f93a5c32deab61Eli Friedman};
1916b3454a219cee5ef36c4668961f93a5c32deab61Eli Friedman
1926b3454a219cee5ef36c4668961f93a5c32deab61Eli Friedman
19383b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar} // end namespace toolchains
19483b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar} // end namespace driver
19583b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar} // end namespace clang
19683b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar
19783b08eb6d2a7f71328db51baa79c654bb9dcc55dDaniel Dunbar#endif
198