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