1//===--- 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
13#include "clang/Driver/Util.h"
14#include "clang/Driver/Types.h"
15#include "llvm/ADT/SmallVector.h"
16#include "llvm/ADT/Triple.h"
17#include "llvm/Support/Path.h"
18#include <string>
19
20namespace clang {
21namespace driver {
22  class ArgList;
23  class Compilation;
24  class DerivedArgList;
25  class Driver;
26  class InputArgList;
27  class JobAction;
28  class ObjCRuntime;
29  class Tool;
30
31/// ToolChain - Access to tools for a single platform.
32class ToolChain {
33public:
34  typedef SmallVector<std::string, 4> path_list;
35
36  enum CXXStdlibType {
37    CST_Libcxx,
38    CST_Libstdcxx
39  };
40
41  enum RuntimeLibType {
42    RLT_CompilerRT,
43    RLT_Libgcc
44  };
45
46private:
47  const Driver &D;
48  const llvm::Triple Triple;
49
50  /// The list of toolchain specific path prefixes to search for
51  /// files.
52  path_list FilePaths;
53
54  /// The list of toolchain specific path prefixes to search for
55  /// programs.
56  path_list ProgramPaths;
57
58protected:
59  ToolChain(const Driver &D, const llvm::Triple &T);
60
61  /// \name Utilities for implementing subclasses.
62  ///@{
63  static void addSystemInclude(const ArgList &DriverArgs,
64                               ArgStringList &CC1Args,
65                               const Twine &Path);
66  static void addExternCSystemInclude(const ArgList &DriverArgs,
67                                      ArgStringList &CC1Args,
68                                      const Twine &Path);
69  static void addSystemIncludes(const ArgList &DriverArgs,
70                                ArgStringList &CC1Args,
71                                ArrayRef<StringRef> Paths);
72  ///@}
73
74public:
75  virtual ~ToolChain();
76
77  // Accessors
78
79  const Driver &getDriver() const;
80  const llvm::Triple &getTriple() const { return Triple; }
81
82  llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
83  StringRef getArchName() const { return Triple.getArchName(); }
84  StringRef getPlatform() const { return Triple.getVendorName(); }
85  StringRef getOS() const { return Triple.getOSName(); }
86
87  std::string getTripleString() const {
88    return Triple.getTriple();
89  }
90
91  path_list &getFilePaths() { return FilePaths; }
92  const path_list &getFilePaths() const { return FilePaths; }
93
94  path_list &getProgramPaths() { return ProgramPaths; }
95  const path_list &getProgramPaths() const { return ProgramPaths; }
96
97  // Tool access.
98
99  /// TranslateArgs - Create a new derived argument list for any argument
100  /// translations this ToolChain may wish to perform, or 0 if no tool chain
101  /// specific translations are needed.
102  ///
103  /// \param BoundArch - The bound architecture name, or 0.
104  virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
105                                        const char *BoundArch) const {
106    return 0;
107  }
108
109  /// SelectTool - Choose a tool to use to handle the action \arg JA with the
110  /// given \arg Inputs.
111  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
112                           const ActionList &Inputs) const = 0;
113
114  // Helper methods
115
116  std::string GetFilePath(const char *Name) const;
117  std::string GetProgramPath(const char *Name, bool WantFile = false) const;
118
119  // Platform defaults information
120
121  /// HasNativeLTOLinker - Check whether the linker and related tools have
122  /// native LLVM support.
123  virtual bool HasNativeLLVMSupport() const;
124
125  /// LookupTypeForExtension - Return the default language type to use for the
126  /// given extension.
127  virtual types::ID LookupTypeForExtension(const char *Ext) const;
128
129  /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
130  virtual bool IsBlocksDefault() const { return false; }
131
132  /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
133  /// by default.
134  virtual bool IsIntegratedAssemblerDefault() const { return false; }
135
136  /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
137  /// default.
138  virtual bool IsStrictAliasingDefault() const { return true; }
139
140  /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
141  /// -fobjc-default-synthesize-properties by default.
142  virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
143
144  /// IsObjCNonFragileABIDefault - Does this tool chain set
145  /// -fobjc-nonfragile-abi by default.
146  virtual bool IsObjCNonFragileABIDefault() const { return false; }
147
148  /// IsObjCLegacyDispatchDefault - Does this tool chain set
149  /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile
150  /// ABI).
151  virtual bool IsObjCLegacyDispatchDefault() const { return true; }
152
153  /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
154  /// mixed dispatch method be used?
155  virtual bool UseObjCMixedDispatch() const { return false; }
156
157  /// GetDefaultStackProtectorLevel - Get the default stack protector level for
158  /// this tool chain (0=off, 1=on, 2=all).
159  virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
160    return 0;
161  }
162
163  /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
164  virtual RuntimeLibType GetDefaultRuntimeLibType() const {
165    return ToolChain::RLT_Libgcc;
166  }
167
168  /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
169  /// by default.
170  virtual bool IsUnwindTablesDefault() const = 0;
171
172  /// GetDefaultRelocationModel - Return the LLVM name of the default
173  /// relocation model for this tool chain.
174  virtual const char *GetDefaultRelocationModel() const = 0;
175
176  /// GetForcedPicModel - Return the LLVM name of the forced PIC model
177  /// for this tool chain, or 0 if this tool chain does not force a
178  /// particular PIC mode.
179  virtual const char *GetForcedPicModel() const = 0;
180
181  /// SupportsProfiling - Does this tool chain support -pg.
182  virtual bool SupportsProfiling() const { return true; }
183
184  /// Does this tool chain support Objective-C garbage collection.
185  virtual bool SupportsObjCGC() const { return true; }
186
187  /// Does this tool chain support Objective-C ARC.
188  virtual bool SupportsObjCARC() const { return true; }
189
190  /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
191  /// compile unit information.
192  virtual bool UseDwarfDebugFlags() const { return false; }
193
194  /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
195  virtual bool UseSjLjExceptions() const { return false; }
196
197  /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
198  /// command line arguments into account.
199  virtual std::string ComputeLLVMTriple(const ArgList &Args,
200                                 types::ID InputType = types::TY_INVALID) const;
201
202  /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
203  /// target, which may take into account the command line arguments. For
204  /// example, on Darwin the -mmacosx-version-min= command line argument (which
205  /// sets the deployment target) determines the version in the triple passed to
206  /// Clang.
207  virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
208                                 types::ID InputType = types::TY_INVALID) const;
209
210  /// configureObjCRuntime - Configure the known properties of the
211  /// Objective-C runtime for this platform.
212  ///
213  /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
214  virtual void configureObjCRuntime(ObjCRuntime &runtime) const;
215
216  /// hasBlocksRuntime - Given that the user is compiling with
217  /// -fblocks, does this tool chain guarantee the existence of a
218  /// blocks runtime?
219  ///
220  /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
221  virtual bool hasBlocksRuntime() const { return true; }
222
223  /// \brief Add the clang cc1 arguments for system include paths.
224  ///
225  /// This routine is responsible for adding the necessary cc1 arguments to
226  /// include headers from standard system header directories.
227  virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
228                                         ArgStringList &CC1Args) const;
229
230  // GetRuntimeLibType - Determine the runtime library type to use with the
231  // given compilation arguments.
232  virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const;
233
234  // GetCXXStdlibType - Determine the C++ standard library type to use with the
235  // given compilation arguments.
236  virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
237
238  /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
239  /// the include paths to use for the given C++ standard library type.
240  virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
241                                            ArgStringList &CC1Args) const;
242
243  /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
244  /// for the given C++ standard library type.
245  virtual void AddCXXStdlibLibArgs(const ArgList &Args,
246                                   ArgStringList &CmdArgs) const;
247
248  /// AddCCKextLibArgs - Add the system specific linker arguments to use
249  /// for kernel extensions (Darwin-specific).
250  virtual void AddCCKextLibArgs(const ArgList &Args,
251                                ArgStringList &CmdArgs) const;
252};
253
254} // end namespace driver
255} // end namespace clang
256
257#endif
258