Tools.h revision 223017
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(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.
76namespace 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
154namespace 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 AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
182                           const InputInfoList &Inputs,
183                           const ArgStringList &OutputArgs) const;
184    void AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
185                           const InputInfoList &Inputs,
186                           const ArgStringList &OutputArgs) const;
187    void AddCPPUniqueOptionsArgs(const ArgList &Args,
188                                 ArgStringList &CmdArgs,
189                                 const InputInfoList &Inputs) const;
190    void AddCPPArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
191
192  public:
193    CC1(const char *Name, const char *ShortName,
194        const ToolChain &TC) : DarwinTool(Name, ShortName, TC) {}
195
196    virtual bool hasGoodDiagnostics() const { return true; }
197    virtual bool hasIntegratedCPP() const { return true; }
198  };
199
200  class LLVM_LIBRARY_VISIBILITY Preprocess : public CC1  {
201  public:
202    Preprocess(const ToolChain &TC) : CC1("darwin::Preprocess",
203                                          "gcc preprocessor", TC) {}
204
205    virtual void ConstructJob(Compilation &C, const JobAction &JA,
206                              const InputInfo &Output,
207                              const InputInfoList &Inputs,
208                              const ArgList &TCArgs,
209                              const char *LinkingOutput) const;
210  };
211
212  class LLVM_LIBRARY_VISIBILITY Compile : public CC1  {
213  public:
214    Compile(const ToolChain &TC) : CC1("darwin::Compile", "gcc frontend", TC) {}
215
216    virtual void ConstructJob(Compilation &C, const JobAction &JA,
217                              const InputInfo &Output,
218                              const InputInfoList &Inputs,
219                              const ArgList &TCArgs,
220                              const char *LinkingOutput) const;
221  };
222
223  class LLVM_LIBRARY_VISIBILITY Assemble : public DarwinTool  {
224  public:
225    Assemble(const ToolChain &TC) : DarwinTool("darwin::Assemble",
226                                               "assembler", TC) {}
227
228    virtual bool hasIntegratedCPP() const { return false; }
229
230    virtual void ConstructJob(Compilation &C, const JobAction &JA,
231                              const InputInfo &Output,
232                              const InputInfoList &Inputs,
233                              const ArgList &TCArgs,
234                              const char *LinkingOutput) const;
235  };
236
237  class LLVM_LIBRARY_VISIBILITY Link : public DarwinTool  {
238    void AddLinkArgs(Compilation &C, const ArgList &Args,
239                     ArgStringList &CmdArgs) const;
240
241  public:
242    Link(const ToolChain &TC) : DarwinTool("darwin::Link", "linker", TC) {}
243
244    virtual bool hasIntegratedCPP() const { return false; }
245
246    virtual void ConstructJob(Compilation &C, const JobAction &JA,
247                              const InputInfo &Output,
248                              const InputInfoList &Inputs,
249                              const ArgList &TCArgs,
250                              const char *LinkingOutput) const;
251  };
252
253  class LLVM_LIBRARY_VISIBILITY Lipo : public DarwinTool  {
254  public:
255    Lipo(const ToolChain &TC) : DarwinTool("darwin::Lipo", "lipo", TC) {}
256
257    virtual bool hasIntegratedCPP() const { return false; }
258
259    virtual void ConstructJob(Compilation &C, const JobAction &JA,
260                              const InputInfo &Output,
261                              const InputInfoList &Inputs,
262                              const ArgList &TCArgs,
263                              const char *LinkingOutput) const;
264  };
265
266  class LLVM_LIBRARY_VISIBILITY Dsymutil : public DarwinTool  {
267  public:
268    Dsymutil(const ToolChain &TC) : DarwinTool("darwin::Dsymutil",
269                                               "dsymutil", TC) {}
270
271    virtual bool hasIntegratedCPP() const { return false; }
272
273    virtual void ConstructJob(Compilation &C, const JobAction &JA,
274                              const InputInfo &Output,
275                              const InputInfoList &Inputs,
276                              const ArgList &TCArgs,
277                              const char *LinkingOutput) const;
278  };
279}
280
281  /// openbsd -- Directly call GNU Binutils assembler and linker
282namespace openbsd {
283  class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
284  public:
285    Assemble(const ToolChain &TC) : Tool("openbsd::Assemble", "assembler",
286                                         TC) {}
287
288    virtual bool hasIntegratedCPP() const { return false; }
289
290    virtual void ConstructJob(Compilation &C, const JobAction &JA,
291                              const InputInfo &Output,
292                              const InputInfoList &Inputs,
293                              const ArgList &TCArgs,
294                              const char *LinkingOutput) const;
295  };
296  class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
297  public:
298    Link(const ToolChain &TC) : Tool("openbsd::Link", "linker", TC) {}
299
300    virtual bool hasIntegratedCPP() const { return false; }
301
302    virtual void ConstructJob(Compilation &C, const JobAction &JA,
303                              const InputInfo &Output,
304                              const InputInfoList &Inputs,
305                              const ArgList &TCArgs,
306                              const char *LinkingOutput) const;
307  };
308} // end namespace openbsd
309
310  /// freebsd -- Directly call GNU Binutils assembler and linker
311namespace freebsd {
312  class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
313  public:
314    Assemble(const ToolChain &TC) : Tool("freebsd::Assemble", "assembler",
315                                         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  class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
326  public:
327    Link(const ToolChain &TC) : Tool("freebsd::Link", "linker", TC) {}
328
329    virtual bool hasIntegratedCPP() const { return false; }
330
331    virtual void ConstructJob(Compilation &C, const JobAction &JA,
332                              const InputInfo &Output,
333                              const InputInfoList &Inputs,
334                              const ArgList &TCArgs,
335                              const char *LinkingOutput) const;
336  };
337} // end namespace freebsd
338
339  /// netbsd -- Directly call GNU Binutils assembler and linker
340namespace netbsd {
341  class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
342  private:
343    const llvm::Triple ToolTriple;
344
345  public:
346    Assemble(const ToolChain &TC, const llvm::Triple &ToolTriple)
347      : Tool("netbsd::Assemble", "assembler", TC), ToolTriple(ToolTriple) {}
348
349    virtual bool hasIntegratedCPP() const { return false; }
350
351    virtual void ConstructJob(Compilation &C, const JobAction &JA,
352                              const InputInfo &Output,
353                              const InputInfoList &Inputs,
354                              const ArgList &TCArgs,
355                              const char *LinkingOutput) const;
356  };
357  class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
358  private:
359    const llvm::Triple ToolTriple;
360
361  public:
362    Link(const ToolChain &TC, const llvm::Triple &ToolTriple)
363      : Tool("netbsd::Ling", "linker", TC), ToolTriple(ToolTriple) {}
364
365    virtual bool hasIntegratedCPP() const { return false; }
366
367    virtual void ConstructJob(Compilation &C, const JobAction &JA,
368                              const InputInfo &Output,
369                              const InputInfoList &Inputs,
370                              const ArgList &TCArgs,
371                              const char *LinkingOutput) const;
372  };
373} // end namespace netbsd
374
375  /// linux -- Directly call GNU Binutils assembler and linker
376namespace linuxtools {
377  class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
378  public:
379    Assemble(const ToolChain &TC) : Tool("linux::Assemble", "assembler",
380                                         TC) {}
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  class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
391  public:
392    Link(const ToolChain &TC) : Tool("linux::Link", "linker", TC) {}
393
394    virtual bool hasIntegratedCPP() const { return false; }
395
396    virtual void ConstructJob(Compilation &C, const JobAction &JA,
397                              const InputInfo &Output,
398                              const InputInfoList &Inputs,
399                              const ArgList &TCArgs,
400                              const char *LinkingOutput) const;
401  };
402}
403  /// minix -- Directly call GNU Binutils assembler and linker
404namespace minix {
405  class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
406  public:
407    Assemble(const ToolChain &TC) : Tool("minix::Assemble", "assembler",
408                                         TC) {}
409
410    virtual bool hasIntegratedCPP() const { return false; }
411
412    virtual void ConstructJob(Compilation &C, const JobAction &JA,
413                              const InputInfo &Output,
414                              const InputInfoList &Inputs,
415                              const ArgList &TCArgs,
416                              const char *LinkingOutput) const;
417  };
418  class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
419  public:
420    Link(const ToolChain &TC) : Tool("minix::Link", "linker", TC) {}
421
422    virtual bool hasIntegratedCPP() const { return false; }
423
424    virtual void ConstructJob(Compilation &C, const JobAction &JA,
425                              const InputInfo &Output,
426                              const InputInfoList &Inputs,
427                              const ArgList &TCArgs,
428                              const char *LinkingOutput) const;
429  };
430} // end namespace minix
431
432  /// auroraux -- Directly call GNU Binutils assembler and linker
433namespace auroraux {
434  class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
435  public:
436    Assemble(const ToolChain &TC) : Tool("auroraux::Assemble", "assembler",
437                                         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  class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
448  public:
449    Link(const ToolChain &TC) : Tool("auroraux::Link", "linker", TC) {}
450
451    virtual bool hasIntegratedCPP() const { return false; }
452
453    virtual void ConstructJob(Compilation &C, const JobAction &JA,
454                              const InputInfo &Output,
455                              const InputInfoList &Inputs,
456                              const ArgList &TCArgs,
457                              const char *LinkingOutput) const;
458  };
459} // end namespace auroraux
460
461  /// dragonfly -- Directly call GNU Binutils assembler and linker
462namespace dragonfly {
463  class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
464  public:
465    Assemble(const ToolChain &TC) : Tool("dragonfly::Assemble", "assembler",
466                                         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  class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
477  public:
478    Link(const ToolChain &TC) : Tool("dragonfly::Link", "linker", TC) {}
479
480    virtual bool hasIntegratedCPP() const { return false; }
481
482    virtual void ConstructJob(Compilation &C, const JobAction &JA,
483                              const InputInfo &Output,
484                              const InputInfoList &Inputs,
485                              const ArgList &TCArgs,
486                              const char *LinkingOutput) const;
487  };
488} // end namespace dragonfly
489
490  /// Visual studio tools.
491namespace visualstudio {
492  class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
493  public:
494    Link(const ToolChain &TC) : Tool("visualstudio::Link", "linker", TC) {}
495
496    virtual bool hasIntegratedCPP() const { return false; }
497
498    virtual void ConstructJob(Compilation &C, const JobAction &JA,
499                              const InputInfo &Output,
500                              const InputInfoList &Inputs,
501                              const ArgList &TCArgs,
502                              const char *LinkingOutput) const;
503  };
504} // end namespace visualstudio
505
506} // end namespace toolchains
507} // end namespace driver
508} // end namespace clang
509
510#endif // CLANG_LIB_DRIVER_TOOLS_H_
511