blob: dfd39bc594ed842a5c0dcfaeb2b65099a83568ef [file] [log] [blame]
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +00001//===--- ToolChain.h - Collections of tools for one platform ----*- 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_DRIVER_TOOLCHAIN_H_
11#define CLANG_DRIVER_TOOLCHAIN_H_
12
Daniel Dunbar641b98b2010-09-14 23:12:35 +000013#include "clang/Driver/Util.h"
Daniel Dunbar41800112010-08-02 05:43:56 +000014#include "clang/Driver/Types.h"
Daniel Dunbar0edefeb2009-03-18 20:26:19 +000015#include "llvm/ADT/SmallVector.h"
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000016#include "llvm/ADT/Triple.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000017#include "llvm/Support/Path.h"
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000018#include <string>
19
20namespace clang {
21namespace driver {
Daniel Dunbar00577ad2010-08-23 22:35:37 +000022 class ArgList;
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000023 class Compilation;
Daniel Dunbarf3cad362009-03-25 04:13:45 +000024 class DerivedArgList;
Daniel Dunbaree788e72009-12-21 18:54:17 +000025 class Driver;
Daniel Dunbarfa0cda42009-03-17 21:21:26 +000026 class HostInfo;
Daniel Dunbarf3cad362009-03-25 04:13:45 +000027 class InputArgList;
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000028 class JobAction;
29 class Tool;
30
31/// ToolChain - Access to tools for a single platform.
32class ToolChain {
Daniel Dunbar0edefeb2009-03-18 20:26:19 +000033public:
34 typedef llvm::SmallVector<std::string, 4> path_list;
35
Daniel Dunbar641b98b2010-09-14 23:12:35 +000036 enum CXXStdlibType {
Daniel Dunbar3f16c952010-09-14 23:12:40 +000037 CST_Libcxx,
Daniel Dunbar641b98b2010-09-14 23:12:35 +000038 CST_Libstdcxx
39 };
40
Daniel Dunbar0edefeb2009-03-18 20:26:19 +000041private:
Daniel Dunbarfa0cda42009-03-17 21:21:26 +000042 const HostInfo &Host;
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000043 const llvm::Triple Triple;
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000044
Daniel Dunbar0edefeb2009-03-18 20:26:19 +000045 /// The list of toolchain specific path prefixes to search for
46 /// files.
47 path_list FilePaths;
48
49 /// The list of toolchain specific path prefixes to search for
50 /// programs.
51 path_list ProgramPaths;
52
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000053protected:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000054 ToolChain(const HostInfo &Host, const llvm::Triple &_Triple);
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000055
56public:
57 virtual ~ToolChain();
58
59 // Accessors
60
Daniel Dunbaree788e72009-12-21 18:54:17 +000061 const Driver &getDriver() const;
Daniel Dunbar12cfe032009-06-16 23:25:22 +000062 const llvm::Triple &getTriple() const { return Triple; }
63
Rafael Espindolaba30bbe2010-08-10 00:25:48 +000064 llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
Benjamin Kramerf22d1fd2010-01-30 15:01:47 +000065 llvm::StringRef getArchName() const { return Triple.getArchName(); }
66 llvm::StringRef getPlatform() const { return Triple.getVendorName(); }
67 llvm::StringRef getOS() const { return Triple.getOSName(); }
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000068
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000069 std::string getTripleString() const {
70 return Triple.getTriple();
Daniel Dunbarcd8e4c42009-03-30 06:36:42 +000071 }
72
Daniel Dunbarbbafc5c2009-03-20 04:36:45 +000073 path_list &getFilePaths() { return FilePaths; }
74 const path_list &getFilePaths() const { return FilePaths; }
Daniel Dunbar0edefeb2009-03-18 20:26:19 +000075
Daniel Dunbarbbafc5c2009-03-20 04:36:45 +000076 path_list &getProgramPaths() { return ProgramPaths; }
77 const path_list &getProgramPaths() const { return ProgramPaths; }
Daniel Dunbar0edefeb2009-03-18 20:26:19 +000078
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000079 // Tool access.
80
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +000081 /// TranslateArgs - Create a new derived argument list for any argument
Daniel Dunbar279c1db2010-06-11 22:00:26 +000082 /// translations this ToolChain may wish to perform, or 0 if no tool chain
83 /// specific translations are needed.
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +000084 ///
85 /// \param BoundArch - The bound architecture name, or 0.
Daniel Dunbar279c1db2010-06-11 22:00:26 +000086 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
87 const char *BoundArch) const {
88 return 0;
89 }
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000090
91 /// SelectTool - Choose a tool to use to handle the action \arg JA.
92 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const = 0;
93
94 // Helper methods
95
Daniel Dunbar4a7e8892010-07-14 18:46:23 +000096 std::string GetFilePath(const char *Name) const;
97 std::string GetProgramPath(const char *Name, bool WantFile = false) const;
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000098
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000099 // Platform defaults information
100
Daniel Dunbarb993f5d2010-09-17 00:24:52 +0000101 /// HasNativeLTOLinker - Check whether the linker and related tools have
102 /// native LLVM support.
103 virtual bool HasNativeLLVMSupport() const;
104
Daniel Dunbar41800112010-08-02 05:43:56 +0000105 /// LookupTypeForExtension - Return the default language type to use for the
106 /// given extension.
107 virtual types::ID LookupTypeForExtension(const char *Ext) const;
108
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000109 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
110 virtual bool IsBlocksDefault() const { return false; }
Ted Kremenekc32647d2010-12-23 21:35:43 +0000111
Daniel Dunbar8767cbc2010-02-03 03:07:56 +0000112 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
113 /// by default.
114 virtual bool IsIntegratedAssemblerDefault() const { return false; }
115
Ted Kremenekc32647d2010-12-23 21:35:43 +0000116 /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
117 /// -fobjc-default-synthesize-properties by default.
118 virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
119
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000120 /// IsObjCNonFragileABIDefault - Does this tool chain set
121 /// -fobjc-nonfragile-abi by default.
122 virtual bool IsObjCNonFragileABIDefault() const { return false; }
123
Daniel Dunbar609508c2010-02-01 21:07:43 +0000124 /// IsObjCLegacyDispatchDefault - Does this tool chain set
125 /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile
126 /// ABI).
127 virtual bool IsObjCLegacyDispatchDefault() const { return false; }
128
Daniel Dunbarf643b9b2010-04-24 17:56:46 +0000129 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
130 /// mixed dispatch method be used?
131 virtual bool UseObjCMixedDispatch() const { return false; }
132
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000133 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
134 /// this tool chain (0=off, 1=on, 2=all).
135 virtual unsigned GetDefaultStackProtectorLevel() const { return 0; }
136
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +0000137 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
138 /// by default.
139 virtual bool IsUnwindTablesDefault() const = 0;
140
141 /// GetDefaultRelocationModel - Return the LLVM name of the default
142 /// relocation model for this tool chain.
143 virtual const char *GetDefaultRelocationModel() const = 0;
144
145 /// GetForcedPicModel - Return the LLVM name of the forced PIC model
146 /// for this tool chain, or 0 if this tool chain does not force a
147 /// particular PIC mode.
148 virtual const char *GetForcedPicModel() const = 0;
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000149
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000150 /// Does this tool chain support Objective-C garbage collection.
151 virtual bool SupportsObjCGC() const { return false; }
152
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000153 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
154 /// compile unit information.
155 virtual bool UseDwarfDebugFlags() const { return false; }
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000156
157 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
Benjamin Kramer8aa79942010-02-11 11:33:47 +0000158 virtual bool UseSjLjExceptions() const { return false; }
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000159
160 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
161 /// command line arguments into account.
162 virtual std::string ComputeLLVMTriple(const ArgList &Args) const;
163
164 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
165 /// target, which may take into account the command line arguments. For
166 /// example, on Darwin the -mmacosx-version-min= command line argument (which
167 /// sets the deployment target) determines the version in the triple passed to
168 /// Clang.
169 virtual std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
Daniel Dunbar641b98b2010-09-14 23:12:35 +0000170
171 // GetCXXStdlibType - Determine the C++ standard library type to use with the
172 // given compilation arguments.
173 virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
174
175 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
176 /// the include paths to use for the given C++ standard library type.
177 virtual void AddClangCXXStdlibIncludeArgs(const ArgList &Args,
178 ArgStringList &CmdArgs) const;
179
Daniel Dunbar132e35d2010-09-17 01:20:05 +0000180 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
Daniel Dunbar641b98b2010-09-14 23:12:35 +0000181 /// for the given C++ standard library type.
Daniel Dunbar132e35d2010-09-17 01:20:05 +0000182 virtual void AddCXXStdlibLibArgs(const ArgList &Args,
183 ArgStringList &CmdArgs) const;
Shantonu Sen7433fed2010-09-17 18:39:08 +0000184
185 /// AddCCKextLibArgs - Add the system specific linker arguments to use
186 /// for kernel extensions (Darwin-specific).
187 virtual void AddCCKextLibArgs(const ArgList &Args,
188 ArgStringList &CmdArgs) const;
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +0000189};
190
191} // end namespace driver
192} // end namespace clang
193
194#endif