]> granicus.if.org Git - clang/blob - lib/Driver/Tools.h
[driver] Clang doesn't support -mkernel/-fapple-kext for i386, so it's
[clang] / lib / Driver / Tools.h
1 //===--- Tools.h - Tool Implementations -------------------------*- 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_LIB_DRIVER_TOOLS_H_
11 #define CLANG_LIB_DRIVER_TOOLS_H_
12
13 #include "clang/Driver/Tool.h"
14 #include "clang/Driver/Types.h"
15 #include "clang/Driver/Util.h"
16
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Support/Compiler.h"
19
20 namespace clang {
21 namespace driver {
22   class Driver;
23
24 namespace toolchains {
25   class Darwin;
26 }
27
28 namespace tools {
29
30   /// \brief Clang compiler tool.
31   class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
32     void AddPreprocessingOptions(const Driver &D,
33                                  const ArgList &Args,
34                                  ArgStringList &CmdArgs,
35                                  const InputInfo &Output,
36                                  const InputInfoList &Inputs) const;
37
38     void AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs,
39                           bool KernelOrKext) const;
40     void AddMIPSTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
41     void AddSparcTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
42     void AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
43
44   public:
45     Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {}
46
47     virtual bool hasGoodDiagnostics() const { return true; }
48     virtual bool hasIntegratedAssembler() const { return true; }
49     virtual bool hasIntegratedCPP() const { return true; }
50
51     virtual void ConstructJob(Compilation &C, const JobAction &JA,
52                               const InputInfo &Output,
53                               const InputInfoList &Inputs,
54                               const ArgList &TCArgs,
55                               const char *LinkingOutput) const;
56   };
57
58   /// \brief Clang integrated assembler tool.
59   class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
60   public:
61     ClangAs(const ToolChain &TC) : Tool("clang::as",
62                                         "clang integrated assembler", TC) {}
63
64     virtual bool hasGoodDiagnostics() const { return true; }
65     virtual bool hasIntegratedAssembler() const { return false; }
66     virtual bool hasIntegratedCPP() const { return false; }
67
68     virtual void ConstructJob(Compilation &C, const JobAction &JA,
69                               const InputInfo &Output,
70                               const InputInfoList &Inputs,
71                               const ArgList &TCArgs,
72                               const char *LinkingOutput) const;
73   };
74
75   /// gcc - Generic GCC tool implementations.
76 namespace gcc {
77   class LLVM_LIBRARY_VISIBILITY Common : public Tool {
78   public:
79     Common(const char *Name, const char *ShortName,
80            const ToolChain &TC) : Tool(Name, ShortName, TC) {}
81
82     virtual void ConstructJob(Compilation &C, const JobAction &JA,
83                               const InputInfo &Output,
84                               const InputInfoList &Inputs,
85                               const ArgList &TCArgs,
86                               const char *LinkingOutput) const;
87
88     /// RenderExtraToolArgs - Render any arguments necessary to force
89     /// the particular tool mode.
90     virtual void RenderExtraToolArgs(const JobAction &JA,
91                                      ArgStringList &CmdArgs) const = 0;
92   };
93
94
95   class LLVM_LIBRARY_VISIBILITY Preprocess : public Common {
96   public:
97     Preprocess(const ToolChain &TC) : Common("gcc::Preprocess",
98                                              "gcc preprocessor", TC) {}
99
100     virtual bool hasGoodDiagnostics() const { return true; }
101     virtual bool hasIntegratedCPP() const { return false; }
102
103     virtual void RenderExtraToolArgs(const JobAction &JA,
104                                      ArgStringList &CmdArgs) const;
105   };
106
107   class LLVM_LIBRARY_VISIBILITY Precompile : public Common  {
108   public:
109     Precompile(const ToolChain &TC) : Common("gcc::Precompile",
110                                              "gcc precompile", TC) {}
111
112     virtual bool hasGoodDiagnostics() const { return true; }
113     virtual bool hasIntegratedCPP() const { return true; }
114
115     virtual void RenderExtraToolArgs(const JobAction &JA,
116                                      ArgStringList &CmdArgs) const;
117   };
118
119   class LLVM_LIBRARY_VISIBILITY Compile : public Common  {
120   public:
121     Compile(const ToolChain &TC) : Common("gcc::Compile",
122                                           "gcc frontend", TC) {}
123
124     virtual bool hasGoodDiagnostics() const { return true; }
125     virtual bool hasIntegratedCPP() const { return true; }
126
127     virtual void RenderExtraToolArgs(const JobAction &JA,
128                                      ArgStringList &CmdArgs) const;
129   };
130
131   class LLVM_LIBRARY_VISIBILITY Assemble : public Common  {
132   public:
133     Assemble(const ToolChain &TC) : Common("gcc::Assemble",
134                                            "assembler (via gcc)", TC) {}
135
136     virtual bool hasIntegratedCPP() const { return false; }
137
138     virtual void RenderExtraToolArgs(const JobAction &JA,
139                                      ArgStringList &CmdArgs) const;
140   };
141
142   class LLVM_LIBRARY_VISIBILITY Link : public Common  {
143   public:
144     Link(const ToolChain &TC) : Common("gcc::Link",
145                                        "linker (via gcc)", TC) {}
146
147     virtual bool hasIntegratedCPP() const { return false; }
148
149     virtual void RenderExtraToolArgs(const JobAction &JA,
150                                      ArgStringList &CmdArgs) const;
151   };
152 } // end namespace gcc
153
154 namespace darwin {
155   class LLVM_LIBRARY_VISIBILITY DarwinTool : public Tool {
156   protected:
157     void AddDarwinArch(const ArgList &Args, ArgStringList &CmdArgs) const;
158
159     const toolchains::Darwin &getDarwinToolChain() const {
160       return reinterpret_cast<const toolchains::Darwin&>(getToolChain());
161     }
162
163   public:
164     DarwinTool(const char *Name, const char *ShortName,
165                const ToolChain &TC) : Tool(Name, ShortName, TC) {}
166   };
167
168   class LLVM_LIBRARY_VISIBILITY CC1 : public DarwinTool  {
169   public:
170     static const char *getBaseInputName(const ArgList &Args,
171                                  const InputInfoList &Input);
172     static const char *getBaseInputStem(const ArgList &Args,
173                                  const InputInfoList &Input);
174     static const char *getDependencyFileName(const ArgList &Args,
175                                              const InputInfoList &Inputs);
176
177   protected:
178     const char *getCC1Name(types::ID Type) const;
179
180     void AddCC1Args(const ArgList &Args, ArgStringList &CmdArgs) const;
181     void RemoveCC1UnsupportedArgs(ArgStringList &CmdArgs) const;
182     void AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
183                            const InputInfoList &Inputs,
184                            const ArgStringList &OutputArgs) const;
185     void AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
186                            const InputInfoList &Inputs,
187                            const ArgStringList &OutputArgs) const;
188     void AddCPPUniqueOptionsArgs(const ArgList &Args,
189                                  ArgStringList &CmdArgs,
190                                  const InputInfoList &Inputs) const;
191     void AddCPPArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
192
193   public:
194     CC1(const char *Name, const char *ShortName,
195         const ToolChain &TC) : DarwinTool(Name, ShortName, TC) {}
196
197     virtual bool hasGoodDiagnostics() const { return true; }
198     virtual bool hasIntegratedCPP() const { return true; }
199   };
200
201   class LLVM_LIBRARY_VISIBILITY Preprocess : public CC1  {
202   public:
203     Preprocess(const ToolChain &TC) : CC1("darwin::Preprocess",
204                                           "gcc preprocessor", TC) {}
205
206     virtual void ConstructJob(Compilation &C, const JobAction &JA,
207                               const InputInfo &Output,
208                               const InputInfoList &Inputs,
209                               const ArgList &TCArgs,
210                               const char *LinkingOutput) const;
211   };
212
213   class LLVM_LIBRARY_VISIBILITY Compile : public CC1  {
214   public:
215     Compile(const ToolChain &TC) : CC1("darwin::Compile", "gcc frontend", TC) {}
216
217     virtual void ConstructJob(Compilation &C, const JobAction &JA,
218                               const InputInfo &Output,
219                               const InputInfoList &Inputs,
220                               const ArgList &TCArgs,
221                               const char *LinkingOutput) const;
222   };
223
224   class LLVM_LIBRARY_VISIBILITY Assemble : public DarwinTool  {
225   public:
226     Assemble(const ToolChain &TC) : DarwinTool("darwin::Assemble",
227                                                "assembler", TC) {}
228
229     virtual bool hasIntegratedCPP() const { return false; }
230
231     virtual void ConstructJob(Compilation &C, const JobAction &JA,
232                               const InputInfo &Output,
233                               const InputInfoList &Inputs,
234                               const ArgList &TCArgs,
235                               const char *LinkingOutput) const;
236   };
237
238   class LLVM_LIBRARY_VISIBILITY Link : public DarwinTool  {
239     void AddLinkArgs(Compilation &C, const ArgList &Args,
240                      ArgStringList &CmdArgs) const;
241
242   public:
243     Link(const ToolChain &TC) : DarwinTool("darwin::Link", "linker", TC) {}
244
245     virtual bool hasIntegratedCPP() const { return false; }
246
247     virtual void ConstructJob(Compilation &C, const JobAction &JA,
248                               const InputInfo &Output,
249                               const InputInfoList &Inputs,
250                               const ArgList &TCArgs,
251                               const char *LinkingOutput) const;
252   };
253
254   class LLVM_LIBRARY_VISIBILITY Lipo : public DarwinTool  {
255   public:
256     Lipo(const ToolChain &TC) : DarwinTool("darwin::Lipo", "lipo", TC) {}
257
258     virtual bool hasIntegratedCPP() const { return false; }
259
260     virtual void ConstructJob(Compilation &C, const JobAction &JA,
261                               const InputInfo &Output,
262                               const InputInfoList &Inputs,
263                               const ArgList &TCArgs,
264                               const char *LinkingOutput) const;
265   };
266
267   class LLVM_LIBRARY_VISIBILITY Dsymutil : public DarwinTool  {
268   public:
269     Dsymutil(const ToolChain &TC) : DarwinTool("darwin::Dsymutil",
270                                                "dsymutil", TC) {}
271
272     virtual bool hasIntegratedCPP() const { return false; }
273
274     virtual void ConstructJob(Compilation &C, const JobAction &JA,
275                               const InputInfo &Output,
276                               const InputInfoList &Inputs,
277                               const ArgList &TCArgs,
278                               const char *LinkingOutput) const;
279   };
280 }
281
282   /// openbsd -- Directly call GNU Binutils assembler and linker
283 namespace openbsd {
284   class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
285   public:
286     Assemble(const ToolChain &TC) : Tool("openbsd::Assemble", "assembler",
287                                          TC) {}
288
289     virtual bool hasIntegratedCPP() const { return false; }
290
291     virtual void ConstructJob(Compilation &C, const JobAction &JA,
292                               const InputInfo &Output,
293                               const InputInfoList &Inputs,
294                               const ArgList &TCArgs,
295                               const char *LinkingOutput) const;
296   };
297   class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
298   public:
299     Link(const ToolChain &TC) : Tool("openbsd::Link", "linker", TC) {}
300
301     virtual bool hasIntegratedCPP() const { return false; }
302
303     virtual void ConstructJob(Compilation &C, const JobAction &JA,
304                               const InputInfo &Output,
305                               const InputInfoList &Inputs,
306                               const ArgList &TCArgs,
307                               const char *LinkingOutput) const;
308   };
309 } // end namespace openbsd
310
311   /// freebsd -- Directly call GNU Binutils assembler and linker
312 namespace freebsd {
313   class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
314   public:
315     Assemble(const ToolChain &TC) : Tool("freebsd::Assemble", "assembler",
316                                          TC) {}
317
318     virtual bool hasIntegratedCPP() const { return false; }
319
320     virtual void ConstructJob(Compilation &C, const JobAction &JA,
321                               const InputInfo &Output,
322                               const InputInfoList &Inputs,
323                               const ArgList &TCArgs,
324                               const char *LinkingOutput) const;
325   };
326   class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
327   public:
328     Link(const ToolChain &TC) : Tool("freebsd::Link", "linker", TC) {}
329
330     virtual bool hasIntegratedCPP() const { return false; }
331
332     virtual void ConstructJob(Compilation &C, const JobAction &JA,
333                               const InputInfo &Output,
334                               const InputInfoList &Inputs,
335                               const ArgList &TCArgs,
336                               const char *LinkingOutput) const;
337   };
338 } // end namespace freebsd
339
340   /// netbsd -- Directly call GNU Binutils assembler and linker
341 namespace netbsd {
342   class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
343   private:
344     const llvm::Triple ToolTriple;
345
346   public:
347     Assemble(const ToolChain &TC, const llvm::Triple &ToolTriple)
348       : Tool("netbsd::Assemble", "assembler", TC), ToolTriple(ToolTriple) {}
349
350     virtual bool hasIntegratedCPP() const { return false; }
351
352     virtual void ConstructJob(Compilation &C, const JobAction &JA,
353                               const InputInfo &Output,
354                               const InputInfoList &Inputs,
355                               const ArgList &TCArgs,
356                               const char *LinkingOutput) const;
357   };
358   class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
359   private:
360     const llvm::Triple ToolTriple;
361
362   public:
363     Link(const ToolChain &TC, const llvm::Triple &ToolTriple)
364       : Tool("netbsd::Link", "linker", TC), ToolTriple(ToolTriple) {}
365
366     virtual bool hasIntegratedCPP() const { return false; }
367
368     virtual void ConstructJob(Compilation &C, const JobAction &JA,
369                               const InputInfo &Output,
370                               const InputInfoList &Inputs,
371                               const ArgList &TCArgs,
372                               const char *LinkingOutput) const;
373   };
374 } // end namespace netbsd
375
376   /// linux -- Directly call GNU Binutils assembler and linker
377 namespace linuxtools {
378   class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
379   public:
380     Assemble(const ToolChain &TC) : Tool("linux::Assemble", "assembler",
381                                          TC) {}
382
383     virtual bool hasIntegratedCPP() const { return false; }
384
385     virtual void ConstructJob(Compilation &C, const JobAction &JA,
386                               const InputInfo &Output,
387                               const InputInfoList &Inputs,
388                               const ArgList &TCArgs,
389                               const char *LinkingOutput) const;
390   };
391   class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
392   public:
393     Link(const ToolChain &TC) : Tool("linux::Link", "linker", TC) {}
394
395     virtual bool hasIntegratedCPP() const { return false; }
396
397     virtual void ConstructJob(Compilation &C, const JobAction &JA,
398                               const InputInfo &Output,
399                               const InputInfoList &Inputs,
400                               const ArgList &TCArgs,
401                               const char *LinkingOutput) const;
402   };
403 }
404   /// minix -- Directly call GNU Binutils assembler and linker
405 namespace minix {
406   class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
407   public:
408     Assemble(const ToolChain &TC) : Tool("minix::Assemble", "assembler",
409                                          TC) {}
410
411     virtual bool hasIntegratedCPP() const { return false; }
412
413     virtual void ConstructJob(Compilation &C, const JobAction &JA,
414                               const InputInfo &Output,
415                               const InputInfoList &Inputs,
416                               const ArgList &TCArgs,
417                               const char *LinkingOutput) const;
418   };
419   class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
420   public:
421     Link(const ToolChain &TC) : Tool("minix::Link", "linker", TC) {}
422
423     virtual bool hasIntegratedCPP() const { return false; }
424
425     virtual void ConstructJob(Compilation &C, const JobAction &JA,
426                               const InputInfo &Output,
427                               const InputInfoList &Inputs,
428                               const ArgList &TCArgs,
429                               const char *LinkingOutput) const;
430   };
431 } // end namespace minix
432
433   /// auroraux -- Directly call GNU Binutils assembler and linker
434 namespace auroraux {
435   class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
436   public:
437     Assemble(const ToolChain &TC) : Tool("auroraux::Assemble", "assembler",
438                                          TC) {}
439
440     virtual bool hasIntegratedCPP() const { return false; }
441
442     virtual void ConstructJob(Compilation &C, const JobAction &JA,
443                               const InputInfo &Output,
444                               const InputInfoList &Inputs,
445                               const ArgList &TCArgs,
446                               const char *LinkingOutput) const;
447   };
448   class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
449   public:
450     Link(const ToolChain &TC) : Tool("auroraux::Link", "linker", TC) {}
451
452     virtual bool hasIntegratedCPP() const { return false; }
453
454     virtual void ConstructJob(Compilation &C, const JobAction &JA,
455                               const InputInfo &Output,
456                               const InputInfoList &Inputs,
457                               const ArgList &TCArgs,
458                               const char *LinkingOutput) const;
459   };
460 } // end namespace auroraux
461
462   /// dragonfly -- Directly call GNU Binutils assembler and linker
463 namespace dragonfly {
464   class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
465   public:
466     Assemble(const ToolChain &TC) : Tool("dragonfly::Assemble", "assembler",
467                                          TC) {}
468
469     virtual bool hasIntegratedCPP() const { return false; }
470
471     virtual void ConstructJob(Compilation &C, const JobAction &JA,
472                               const InputInfo &Output,
473                               const InputInfoList &Inputs,
474                               const ArgList &TCArgs,
475                               const char *LinkingOutput) const;
476   };
477   class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
478   public:
479     Link(const ToolChain &TC) : Tool("dragonfly::Link", "linker", TC) {}
480
481     virtual bool hasIntegratedCPP() const { return false; }
482
483     virtual void ConstructJob(Compilation &C, const JobAction &JA,
484                               const InputInfo &Output,
485                               const InputInfoList &Inputs,
486                               const ArgList &TCArgs,
487                               const char *LinkingOutput) const;
488   };
489 } // end namespace dragonfly
490
491   /// Visual studio tools.
492 namespace visualstudio {
493   class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
494   public:
495     Link(const ToolChain &TC) : Tool("visualstudio::Link", "linker", TC) {}
496
497     virtual bool hasIntegratedCPP() const { return false; }
498
499     virtual void ConstructJob(Compilation &C, const JobAction &JA,
500                               const InputInfo &Output,
501                               const InputInfoList &Inputs,
502                               const ArgList &TCArgs,
503                               const char *LinkingOutput) const;
504   };
505 } // end namespace visualstudio
506
507 } // end namespace toolchains
508 } // end namespace driver
509 } // end namespace clang
510
511 #endif // CLANG_LIB_DRIVER_TOOLS_H_