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