]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/include/clang/Driver/ToolChain.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / clang / include / clang / Driver / ToolChain.h
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 namespace driver {
22   class ArgList;
23   class Compilation;
24   class DerivedArgList;
25   class Driver;
26   class HostInfo;
27   class InputArgList;
28   class JobAction;
29   class ObjCRuntime;
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 private:
43   const HostInfo &Host;
44   const llvm::Triple Triple;
45
46   /// The list of toolchain specific path prefixes to search for
47   /// files.
48   path_list FilePaths;
49
50   /// The list of toolchain specific path prefixes to search for
51   /// programs.
52   path_list ProgramPaths;
53
54 protected:
55   ToolChain(const HostInfo &Host, const llvm::Triple &_Triple);
56
57 public:
58   virtual ~ToolChain();
59
60   // Accessors
61
62   const Driver &getDriver() const;
63   const llvm::Triple &getTriple() const { return Triple; }
64
65   llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
66   StringRef getArchName() const { return Triple.getArchName(); }
67   StringRef getPlatform() const { return Triple.getVendorName(); }
68   StringRef getOS() const { return Triple.getOSName(); }
69
70   std::string getTripleString() const {
71     return Triple.getTriple();
72   }
73
74   path_list &getFilePaths() { return FilePaths; }
75   const path_list &getFilePaths() const { return FilePaths; }
76
77   path_list &getProgramPaths() { return ProgramPaths; }
78   const path_list &getProgramPaths() const { return ProgramPaths; }
79
80   // Tool access.
81
82   /// TranslateArgs - Create a new derived argument list for any argument
83   /// translations this ToolChain may wish to perform, or 0 if no tool chain
84   /// specific translations are needed.
85   ///
86   /// \param BoundArch - The bound architecture name, or 0.
87   virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
88                                         const char *BoundArch) const {
89     return 0;
90   }
91
92   /// SelectTool - Choose a tool to use to handle the action \arg JA with the
93   /// given \arg Inputs.
94   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
95                            const ActionList &Inputs) const = 0;
96
97   // Helper methods
98
99   std::string GetFilePath(const char *Name) const;
100   std::string GetProgramPath(const char *Name, bool WantFile = false) const;
101
102   // Platform defaults information
103
104   /// HasNativeLTOLinker - Check whether the linker and related tools have
105   /// native LLVM support.
106   virtual bool HasNativeLLVMSupport() const;
107
108   /// LookupTypeForExtension - Return the default language type to use for the
109   /// given extension.
110   virtual types::ID LookupTypeForExtension(const char *Ext) const;
111
112   /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
113   virtual bool IsBlocksDefault() const { return false; }
114
115   /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
116   /// by default.
117   virtual bool IsIntegratedAssemblerDefault() const { return false; }
118
119   /// IsStrictAliasingDefault - Does this tool chain use -fstrict-aliasing by
120   /// default.
121   virtual bool IsStrictAliasingDefault() const { return true; }
122
123   /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
124   /// -fobjc-default-synthesize-properties by default.
125   virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
126
127   /// IsObjCNonFragileABIDefault - Does this tool chain set
128   /// -fobjc-nonfragile-abi by default.
129   virtual bool IsObjCNonFragileABIDefault() const { return false; }
130
131   /// IsObjCLegacyDispatchDefault - Does this tool chain set
132   /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile
133   /// ABI).
134   virtual bool IsObjCLegacyDispatchDefault() const { return false; }
135
136   /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
137   /// mixed dispatch method be used?
138   virtual bool UseObjCMixedDispatch() const { return false; }
139
140   /// GetDefaultStackProtectorLevel - Get the default stack protector level for
141   /// this tool chain (0=off, 1=on, 2=all).
142   virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
143     return 0;
144   }
145
146   /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
147   /// by default.
148   virtual bool IsUnwindTablesDefault() const = 0;
149
150   /// GetDefaultRelocationModel - Return the LLVM name of the default
151   /// relocation model for this tool chain.
152   virtual const char *GetDefaultRelocationModel() const = 0;
153
154   /// GetForcedPicModel - Return the LLVM name of the forced PIC model
155   /// for this tool chain, or 0 if this tool chain does not force a
156   /// particular PIC mode.
157   virtual const char *GetForcedPicModel() const = 0;
158
159   /// SupportsProfiling - Does this tool chain support -pg.
160   virtual bool SupportsProfiling() const { return true; }
161
162   /// Does this tool chain support Objective-C garbage collection.
163   virtual bool SupportsObjCGC() const { return true; }
164
165   /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
166   /// compile unit information.
167   virtual bool UseDwarfDebugFlags() const { return false; }
168
169   /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
170   virtual bool UseSjLjExceptions() const { return false; }
171
172   /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
173   /// command line arguments into account.
174   virtual std::string ComputeLLVMTriple(const ArgList &Args,
175                                  types::ID InputType = types::TY_INVALID) const;
176
177   /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
178   /// target, which may take into account the command line arguments. For
179   /// example, on Darwin the -mmacosx-version-min= command line argument (which
180   /// sets the deployment target) determines the version in the triple passed to
181   /// Clang.
182   virtual std::string ComputeEffectiveClangTriple(const ArgList &Args,
183                                  types::ID InputType = types::TY_INVALID) const;
184
185   /// configureObjCRuntime - Configure the known properties of the
186   /// Objective-C runtime for this platform.
187   ///
188   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
189   virtual void configureObjCRuntime(ObjCRuntime &runtime) const;
190
191   /// hasBlocksRuntime - Given that the user is compiling with
192   /// -fblocks, does this tool chain guarantee the existence of a
193   /// blocks runtime?
194   ///
195   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
196   virtual bool hasBlocksRuntime() const { return true; }
197
198   // GetCXXStdlibType - Determine the C++ standard library type to use with the
199   // given compilation arguments.
200   virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
201
202   /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
203   /// the include paths to use for the given C++ standard library type.
204   virtual void AddClangCXXStdlibIncludeArgs(const ArgList &Args,
205                                             ArgStringList &CmdArgs,
206                                             bool ObjCXXAutoRefCount) const;
207
208   /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
209   /// for the given C++ standard library type.
210   virtual void AddCXXStdlibLibArgs(const ArgList &Args,
211                                    ArgStringList &CmdArgs) const;
212
213   /// AddCCKextLibArgs - Add the system specific linker arguments to use
214   /// for kernel extensions (Darwin-specific).
215   virtual void AddCCKextLibArgs(const ArgList &Args,
216                                 ArgStringList &CmdArgs) const;
217 };
218
219 } // end namespace driver
220 } // end namespace clang
221
222 #endif