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