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