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