1 //===--- Tools.h - Tool Implementations -------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_LIB_DRIVER_TOOLS_H_
11 #define CLANG_LIB_DRIVER_TOOLS_H_
13 #include "clang/Driver/Tool.h"
14 #include "clang/Driver/Types.h"
15 #include "clang/Driver/Util.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Support/Compiler.h"
24 namespace toolchains {
30 /// \brief Clang compiler tool.
31 class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
32 void AddPreprocessingOptions(const Driver &D,
34 ArgStringList &CmdArgs,
35 const InputInfo &Output,
36 const InputInfoList &Inputs) const;
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;
45 Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {}
47 virtual bool hasGoodDiagnostics() const { return true; }
48 virtual bool hasIntegratedAssembler() const { return true; }
49 virtual bool hasIntegratedCPP() const { return true; }
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;
58 /// \brief Clang integrated assembler tool.
59 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
61 ClangAs(const ToolChain &TC) : Tool("clang::as",
62 "clang integrated assembler", TC) {}
64 virtual bool hasGoodDiagnostics() const { return true; }
65 virtual bool hasIntegratedAssembler() const { return false; }
66 virtual bool hasIntegratedCPP() const { return false; }
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;
75 /// gcc - Generic GCC tool implementations.
77 class LLVM_LIBRARY_VISIBILITY Common : public Tool {
79 Common(const char *Name, const char *ShortName,
80 const ToolChain &TC) : Tool(Name, ShortName, TC) {}
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;
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;
95 class LLVM_LIBRARY_VISIBILITY Preprocess : public Common {
97 Preprocess(const ToolChain &TC) : Common("gcc::Preprocess",
98 "gcc preprocessor", TC) {}
100 virtual bool hasGoodDiagnostics() const { return true; }
101 virtual bool hasIntegratedCPP() const { return false; }
103 virtual void RenderExtraToolArgs(const JobAction &JA,
104 ArgStringList &CmdArgs) const;
107 class LLVM_LIBRARY_VISIBILITY Precompile : public Common {
109 Precompile(const ToolChain &TC) : Common("gcc::Precompile",
110 "gcc precompile", TC) {}
112 virtual bool hasGoodDiagnostics() const { return true; }
113 virtual bool hasIntegratedCPP() const { return true; }
115 virtual void RenderExtraToolArgs(const JobAction &JA,
116 ArgStringList &CmdArgs) const;
119 class LLVM_LIBRARY_VISIBILITY Compile : public Common {
121 Compile(const ToolChain &TC) : Common("gcc::Compile",
122 "gcc frontend", TC) {}
124 virtual bool hasGoodDiagnostics() const { return true; }
125 virtual bool hasIntegratedCPP() const { return true; }
127 virtual void RenderExtraToolArgs(const JobAction &JA,
128 ArgStringList &CmdArgs) const;
131 class LLVM_LIBRARY_VISIBILITY Assemble : public Common {
133 Assemble(const ToolChain &TC) : Common("gcc::Assemble",
134 "assembler (via gcc)", TC) {}
136 virtual bool hasIntegratedCPP() const { return false; }
138 virtual void RenderExtraToolArgs(const JobAction &JA,
139 ArgStringList &CmdArgs) const;
142 class LLVM_LIBRARY_VISIBILITY Link : public Common {
144 Link(const ToolChain &TC) : Common("gcc::Link",
145 "linker (via gcc)", TC) {}
147 virtual bool hasIntegratedCPP() const { return false; }
149 virtual void RenderExtraToolArgs(const JobAction &JA,
150 ArgStringList &CmdArgs) const;
152 } // end namespace gcc
155 class LLVM_LIBRARY_VISIBILITY DarwinTool : public Tool {
157 void AddDarwinArch(const ArgList &Args, ArgStringList &CmdArgs) const;
159 const toolchains::Darwin &getDarwinToolChain() const {
160 return reinterpret_cast<const toolchains::Darwin&>(getToolChain());
164 DarwinTool(const char *Name, const char *ShortName,
165 const ToolChain &TC) : Tool(Name, ShortName, TC) {}
168 class LLVM_LIBRARY_VISIBILITY CC1 : public DarwinTool {
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);
178 const char *getCC1Name(types::ID Type) const;
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;
194 CC1(const char *Name, const char *ShortName,
195 const ToolChain &TC) : DarwinTool(Name, ShortName, TC) {}
197 virtual bool hasGoodDiagnostics() const { return true; }
198 virtual bool hasIntegratedCPP() const { return true; }
201 class LLVM_LIBRARY_VISIBILITY Preprocess : public CC1 {
203 Preprocess(const ToolChain &TC) : CC1("darwin::Preprocess",
204 "gcc preprocessor", TC) {}
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;
213 class LLVM_LIBRARY_VISIBILITY Compile : public CC1 {
215 Compile(const ToolChain &TC) : CC1("darwin::Compile", "gcc frontend", TC) {}
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;
224 class LLVM_LIBRARY_VISIBILITY Assemble : public DarwinTool {
226 Assemble(const ToolChain &TC) : DarwinTool("darwin::Assemble",
229 virtual bool hasIntegratedCPP() const { return false; }
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;
238 class LLVM_LIBRARY_VISIBILITY Link : public DarwinTool {
239 void AddLinkArgs(Compilation &C, const ArgList &Args,
240 ArgStringList &CmdArgs) const;
243 Link(const ToolChain &TC) : DarwinTool("darwin::Link", "linker", TC) {}
245 virtual bool hasIntegratedCPP() const { return false; }
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;
254 class LLVM_LIBRARY_VISIBILITY Lipo : public DarwinTool {
256 Lipo(const ToolChain &TC) : DarwinTool("darwin::Lipo", "lipo", TC) {}
258 virtual bool hasIntegratedCPP() const { return false; }
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;
267 class LLVM_LIBRARY_VISIBILITY Dsymutil : public DarwinTool {
269 Dsymutil(const ToolChain &TC) : DarwinTool("darwin::Dsymutil",
272 virtual bool hasIntegratedCPP() const { return false; }
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;
282 /// openbsd -- Directly call GNU Binutils assembler and linker
284 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
286 Assemble(const ToolChain &TC) : Tool("openbsd::Assemble", "assembler",
289 virtual bool hasIntegratedCPP() const { return false; }
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;
297 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
299 Link(const ToolChain &TC) : Tool("openbsd::Link", "linker", TC) {}
301 virtual bool hasIntegratedCPP() const { return false; }
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;
309 } // end namespace openbsd
311 /// freebsd -- Directly call GNU Binutils assembler and linker
313 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
315 Assemble(const ToolChain &TC) : Tool("freebsd::Assemble", "assembler",
318 virtual bool hasIntegratedCPP() const { return false; }
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;
326 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
328 Link(const ToolChain &TC) : Tool("freebsd::Link", "linker", TC) {}
330 virtual bool hasIntegratedCPP() const { return false; }
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;
338 } // end namespace freebsd
340 /// netbsd -- Directly call GNU Binutils assembler and linker
342 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
344 const llvm::Triple ToolTriple;
347 Assemble(const ToolChain &TC, const llvm::Triple &ToolTriple)
348 : Tool("netbsd::Assemble", "assembler", TC), ToolTriple(ToolTriple) {}
350 virtual bool hasIntegratedCPP() const { return false; }
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;
358 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
360 const llvm::Triple ToolTriple;
363 Link(const ToolChain &TC, const llvm::Triple &ToolTriple)
364 : Tool("netbsd::Link", "linker", TC), ToolTriple(ToolTriple) {}
366 virtual bool hasIntegratedCPP() const { return false; }
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;
374 } // end namespace netbsd
376 /// linux -- Directly call GNU Binutils assembler and linker
377 namespace linuxtools {
378 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
380 Assemble(const ToolChain &TC) : Tool("linux::Assemble", "assembler",
383 virtual bool hasIntegratedCPP() const { return false; }
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;
391 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
393 Link(const ToolChain &TC) : Tool("linux::Link", "linker", TC) {}
395 virtual bool hasIntegratedCPP() const { return false; }
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;
404 /// minix -- Directly call GNU Binutils assembler and linker
406 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
408 Assemble(const ToolChain &TC) : Tool("minix::Assemble", "assembler",
411 virtual bool hasIntegratedCPP() const { return false; }
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;
419 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
421 Link(const ToolChain &TC) : Tool("minix::Link", "linker", TC) {}
423 virtual bool hasIntegratedCPP() const { return false; }
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;
431 } // end namespace minix
433 /// auroraux -- Directly call GNU Binutils assembler and linker
435 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
437 Assemble(const ToolChain &TC) : Tool("auroraux::Assemble", "assembler",
440 virtual bool hasIntegratedCPP() const { return false; }
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;
448 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
450 Link(const ToolChain &TC) : Tool("auroraux::Link", "linker", TC) {}
452 virtual bool hasIntegratedCPP() const { return false; }
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;
460 } // end namespace auroraux
462 /// dragonfly -- Directly call GNU Binutils assembler and linker
463 namespace dragonfly {
464 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
466 Assemble(const ToolChain &TC) : Tool("dragonfly::Assemble", "assembler",
469 virtual bool hasIntegratedCPP() const { return false; }
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;
477 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
479 Link(const ToolChain &TC) : Tool("dragonfly::Link", "linker", TC) {}
481 virtual bool hasIntegratedCPP() const { return false; }
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;
489 } // end namespace dragonfly
491 /// Visual studio tools.
492 namespace visualstudio {
493 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
495 Link(const ToolChain &TC) : Tool("visualstudio::Link", "linker", TC) {}
497 virtual bool hasIntegratedCPP() const { return false; }
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;
505 } // end namespace visualstudio
507 } // end namespace toolchains
508 } // end namespace driver
509 } // end namespace clang
511 #endif // CLANG_LIB_DRIVER_TOOLS_H_