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(Compilation &C,
35 ArgStringList &CmdArgs,
36 const InputInfo &Output,
37 const InputInfoList &Inputs) const;
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 void AddHexagonTargetArgs (const ArgList &Args, ArgStringList &CmdArgs) const;
47 Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {}
49 virtual bool hasGoodDiagnostics() const { return true; }
50 virtual bool hasIntegratedAssembler() const { return true; }
51 virtual bool hasIntegratedCPP() const { return true; }
53 virtual void ConstructJob(Compilation &C, const JobAction &JA,
54 const InputInfo &Output,
55 const InputInfoList &Inputs,
56 const ArgList &TCArgs,
57 const char *LinkingOutput) const;
60 /// \brief Clang integrated assembler tool.
61 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
63 ClangAs(const ToolChain &TC) : Tool("clang::as",
64 "clang integrated assembler", TC) {}
66 virtual bool hasGoodDiagnostics() const { return true; }
67 virtual bool hasIntegratedAssembler() const { return false; }
68 virtual bool hasIntegratedCPP() const { return false; }
70 virtual void ConstructJob(Compilation &C, const JobAction &JA,
71 const InputInfo &Output,
72 const InputInfoList &Inputs,
73 const ArgList &TCArgs,
74 const char *LinkingOutput) const;
77 /// gcc - Generic GCC tool implementations.
79 class LLVM_LIBRARY_VISIBILITY Common : public Tool {
81 Common(const char *Name, const char *ShortName,
82 const ToolChain &TC) : Tool(Name, ShortName, TC) {}
84 virtual void ConstructJob(Compilation &C, const JobAction &JA,
85 const InputInfo &Output,
86 const InputInfoList &Inputs,
87 const ArgList &TCArgs,
88 const char *LinkingOutput) const;
90 /// RenderExtraToolArgs - Render any arguments necessary to force
91 /// the particular tool mode.
92 virtual void RenderExtraToolArgs(const JobAction &JA,
93 ArgStringList &CmdArgs) const = 0;
97 class LLVM_LIBRARY_VISIBILITY Preprocess : public Common {
99 Preprocess(const ToolChain &TC) : Common("gcc::Preprocess",
100 "gcc preprocessor", TC) {}
102 virtual bool hasGoodDiagnostics() const { return true; }
103 virtual bool hasIntegratedCPP() const { return false; }
105 virtual void RenderExtraToolArgs(const JobAction &JA,
106 ArgStringList &CmdArgs) const;
109 class LLVM_LIBRARY_VISIBILITY Precompile : public Common {
111 Precompile(const ToolChain &TC) : Common("gcc::Precompile",
112 "gcc precompile", TC) {}
114 virtual bool hasGoodDiagnostics() const { return true; }
115 virtual bool hasIntegratedCPP() const { return true; }
117 virtual void RenderExtraToolArgs(const JobAction &JA,
118 ArgStringList &CmdArgs) const;
121 class LLVM_LIBRARY_VISIBILITY Compile : public Common {
123 Compile(const ToolChain &TC) : Common("gcc::Compile",
124 "gcc frontend", TC) {}
126 virtual bool hasGoodDiagnostics() const { return true; }
127 virtual bool hasIntegratedCPP() const { return true; }
129 virtual void RenderExtraToolArgs(const JobAction &JA,
130 ArgStringList &CmdArgs) const;
133 class LLVM_LIBRARY_VISIBILITY Assemble : public Common {
135 Assemble(const ToolChain &TC) : Common("gcc::Assemble",
136 "assembler (via gcc)", TC) {}
138 virtual bool hasIntegratedCPP() const { return false; }
140 virtual void RenderExtraToolArgs(const JobAction &JA,
141 ArgStringList &CmdArgs) const;
144 class LLVM_LIBRARY_VISIBILITY Link : public Common {
146 Link(const ToolChain &TC) : Common("gcc::Link",
147 "linker (via gcc)", TC) {}
149 virtual bool hasIntegratedCPP() const { return false; }
151 virtual void RenderExtraToolArgs(const JobAction &JA,
152 ArgStringList &CmdArgs) const;
154 } // end namespace gcc
157 // For Hexagon, we do not need to instantiate tools for PreProcess, PreCompile and Compile.
158 // We simply use "clang -cc1" for those actions.
159 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
161 Assemble(const ToolChain &TC) : Tool("hexagon::Assemble",
164 virtual bool hasIntegratedCPP() const { return false; }
166 virtual void RenderExtraToolArgs(const JobAction &JA,
167 ArgStringList &CmdArgs) const;
168 virtual void ConstructJob(Compilation &C, const JobAction &JA,
169 const InputInfo &Output,
170 const InputInfoList &Inputs,
171 const ArgList &TCArgs,
172 const char *LinkingOutput) const;
175 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
177 Link(const ToolChain &TC) : Tool("hexagon::Link",
180 virtual bool hasIntegratedCPP() const { return false; }
182 virtual void RenderExtraToolArgs(const JobAction &JA,
183 ArgStringList &CmdArgs) const;
184 virtual void ConstructJob(Compilation &C, const JobAction &JA,
185 const InputInfo &Output,
186 const InputInfoList &Inputs,
187 const ArgList &TCArgs,
188 const char *LinkingOutput) const;
190 } // end namespace hexagon.
194 class LLVM_LIBRARY_VISIBILITY DarwinTool : public Tool {
196 void AddDarwinArch(const ArgList &Args, ArgStringList &CmdArgs) const;
198 const toolchains::Darwin &getDarwinToolChain() const {
199 return reinterpret_cast<const toolchains::Darwin&>(getToolChain());
203 DarwinTool(const char *Name, const char *ShortName,
204 const ToolChain &TC) : Tool(Name, ShortName, TC) {}
207 class LLVM_LIBRARY_VISIBILITY CC1 : public DarwinTool {
209 static const char *getBaseInputName(const ArgList &Args,
210 const InputInfoList &Input);
211 static const char *getBaseInputStem(const ArgList &Args,
212 const InputInfoList &Input);
213 static const char *getDependencyFileName(const ArgList &Args,
214 const InputInfoList &Inputs);
217 const char *getCC1Name(types::ID Type) const;
219 void AddCC1Args(const ArgList &Args, ArgStringList &CmdArgs) const;
220 void RemoveCC1UnsupportedArgs(ArgStringList &CmdArgs) const;
221 void AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
222 const InputInfoList &Inputs,
223 const ArgStringList &OutputArgs) const;
224 void AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
225 const InputInfoList &Inputs,
226 const ArgStringList &OutputArgs) const;
227 void AddCPPUniqueOptionsArgs(const ArgList &Args,
228 ArgStringList &CmdArgs,
229 const InputInfoList &Inputs) const;
230 void AddCPPArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
233 CC1(const char *Name, const char *ShortName,
234 const ToolChain &TC) : DarwinTool(Name, ShortName, TC) {}
236 virtual bool hasGoodDiagnostics() const { return true; }
237 virtual bool hasIntegratedCPP() const { return true; }
240 class LLVM_LIBRARY_VISIBILITY Preprocess : public CC1 {
242 Preprocess(const ToolChain &TC) : CC1("darwin::Preprocess",
243 "gcc preprocessor", TC) {}
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;
252 class LLVM_LIBRARY_VISIBILITY Compile : public CC1 {
254 Compile(const ToolChain &TC) : CC1("darwin::Compile", "gcc frontend", TC) {}
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;
263 class LLVM_LIBRARY_VISIBILITY Assemble : public DarwinTool {
265 Assemble(const ToolChain &TC) : DarwinTool("darwin::Assemble",
268 virtual bool hasIntegratedCPP() const { return false; }
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;
277 class LLVM_LIBRARY_VISIBILITY Link : public DarwinTool {
278 void AddLinkArgs(Compilation &C, const ArgList &Args,
279 ArgStringList &CmdArgs) const;
282 Link(const ToolChain &TC) : DarwinTool("darwin::Link", "linker", TC) {}
284 virtual bool hasIntegratedCPP() const { return false; }
286 virtual void ConstructJob(Compilation &C, const JobAction &JA,
287 const InputInfo &Output,
288 const InputInfoList &Inputs,
289 const ArgList &TCArgs,
290 const char *LinkingOutput) const;
293 class LLVM_LIBRARY_VISIBILITY Lipo : public DarwinTool {
295 Lipo(const ToolChain &TC) : DarwinTool("darwin::Lipo", "lipo", TC) {}
297 virtual bool hasIntegratedCPP() const { return false; }
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;
306 class LLVM_LIBRARY_VISIBILITY Dsymutil : public DarwinTool {
308 Dsymutil(const ToolChain &TC) : DarwinTool("darwin::Dsymutil",
311 virtual bool hasIntegratedCPP() const { return false; }
313 virtual void ConstructJob(Compilation &C, const JobAction &JA,
314 const InputInfo &Output,
315 const InputInfoList &Inputs,
316 const ArgList &TCArgs,
317 const char *LinkingOutput) const;
320 class LLVM_LIBRARY_VISIBILITY VerifyDebug : public DarwinTool {
322 VerifyDebug(const ToolChain &TC) : DarwinTool("darwin::VerifyDebug",
325 virtual bool hasIntegratedCPP() const { return false; }
327 virtual void ConstructJob(Compilation &C, const JobAction &JA,
328 const InputInfo &Output,
329 const InputInfoList &Inputs,
330 const ArgList &TCArgs,
331 const char *LinkingOutput) const;
336 /// openbsd -- Directly call GNU Binutils assembler and linker
338 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
340 Assemble(const ToolChain &TC) : Tool("openbsd::Assemble", "assembler",
343 virtual bool hasIntegratedCPP() const { return false; }
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;
351 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
353 Link(const ToolChain &TC) : Tool("openbsd::Link", "linker", TC) {}
355 virtual bool hasIntegratedCPP() const { return false; }
357 virtual void ConstructJob(Compilation &C, const JobAction &JA,
358 const InputInfo &Output,
359 const InputInfoList &Inputs,
360 const ArgList &TCArgs,
361 const char *LinkingOutput) const;
363 } // end namespace openbsd
365 /// freebsd -- Directly call GNU Binutils assembler and linker
367 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
369 Assemble(const ToolChain &TC) : Tool("freebsd::Assemble", "assembler",
372 virtual bool hasIntegratedCPP() const { return false; }
374 virtual void ConstructJob(Compilation &C, const JobAction &JA,
375 const InputInfo &Output,
376 const InputInfoList &Inputs,
377 const ArgList &TCArgs,
378 const char *LinkingOutput) const;
380 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
382 Link(const ToolChain &TC) : Tool("freebsd::Link", "linker", TC) {}
384 virtual bool hasIntegratedCPP() const { return false; }
386 virtual void ConstructJob(Compilation &C, const JobAction &JA,
387 const InputInfo &Output,
388 const InputInfoList &Inputs,
389 const ArgList &TCArgs,
390 const char *LinkingOutput) const;
392 } // end namespace freebsd
394 /// netbsd -- Directly call GNU Binutils assembler and linker
396 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
398 const llvm::Triple ToolTriple;
401 Assemble(const ToolChain &TC, const llvm::Triple &ToolTriple)
402 : Tool("netbsd::Assemble", "assembler", TC), ToolTriple(ToolTriple) {}
404 virtual bool hasIntegratedCPP() const { return false; }
406 virtual void ConstructJob(Compilation &C, const JobAction &JA,
407 const InputInfo &Output,
408 const InputInfoList &Inputs,
409 const ArgList &TCArgs,
410 const char *LinkingOutput) const;
412 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
414 const llvm::Triple ToolTriple;
417 Link(const ToolChain &TC, const llvm::Triple &ToolTriple)
418 : Tool("netbsd::Link", "linker", TC), ToolTriple(ToolTriple) {}
420 virtual bool hasIntegratedCPP() const { return false; }
422 virtual void ConstructJob(Compilation &C, const JobAction &JA,
423 const InputInfo &Output,
424 const InputInfoList &Inputs,
425 const ArgList &TCArgs,
426 const char *LinkingOutput) const;
428 } // end namespace netbsd
430 /// linux -- Directly call GNU Binutils assembler and linker
431 namespace linuxtools {
432 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
434 Assemble(const ToolChain &TC) : Tool("linux::Assemble", "assembler",
437 virtual bool hasIntegratedCPP() const { return false; }
439 virtual void ConstructJob(Compilation &C, const JobAction &JA,
440 const InputInfo &Output,
441 const InputInfoList &Inputs,
442 const ArgList &TCArgs,
443 const char *LinkingOutput) const;
445 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
447 Link(const ToolChain &TC) : Tool("linux::Link", "linker", TC) {}
449 virtual bool hasIntegratedCPP() const { return false; }
451 virtual void ConstructJob(Compilation &C, const JobAction &JA,
452 const InputInfo &Output,
453 const InputInfoList &Inputs,
454 const ArgList &TCArgs,
455 const char *LinkingOutput) const;
458 /// minix -- Directly call GNU Binutils assembler and linker
460 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
462 Assemble(const ToolChain &TC) : Tool("minix::Assemble", "assembler",
465 virtual bool hasIntegratedCPP() const { return false; }
467 virtual void ConstructJob(Compilation &C, const JobAction &JA,
468 const InputInfo &Output,
469 const InputInfoList &Inputs,
470 const ArgList &TCArgs,
471 const char *LinkingOutput) const;
473 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
475 Link(const ToolChain &TC) : Tool("minix::Link", "linker", TC) {}
477 virtual bool hasIntegratedCPP() const { return false; }
479 virtual void ConstructJob(Compilation &C, const JobAction &JA,
480 const InputInfo &Output,
481 const InputInfoList &Inputs,
482 const ArgList &TCArgs,
483 const char *LinkingOutput) const;
485 } // end namespace minix
487 /// auroraux -- Directly call GNU Binutils assembler and linker
489 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
491 Assemble(const ToolChain &TC) : Tool("auroraux::Assemble", "assembler",
494 virtual bool hasIntegratedCPP() const { return false; }
496 virtual void ConstructJob(Compilation &C, const JobAction &JA,
497 const InputInfo &Output,
498 const InputInfoList &Inputs,
499 const ArgList &TCArgs,
500 const char *LinkingOutput) const;
502 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
504 Link(const ToolChain &TC) : Tool("auroraux::Link", "linker", TC) {}
506 virtual bool hasIntegratedCPP() const { return false; }
508 virtual void ConstructJob(Compilation &C, const JobAction &JA,
509 const InputInfo &Output,
510 const InputInfoList &Inputs,
511 const ArgList &TCArgs,
512 const char *LinkingOutput) const;
514 } // end namespace auroraux
516 /// dragonfly -- Directly call GNU Binutils assembler and linker
517 namespace dragonfly {
518 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
520 Assemble(const ToolChain &TC) : Tool("dragonfly::Assemble", "assembler",
523 virtual bool hasIntegratedCPP() const { return false; }
525 virtual void ConstructJob(Compilation &C, const JobAction &JA,
526 const InputInfo &Output,
527 const InputInfoList &Inputs,
528 const ArgList &TCArgs,
529 const char *LinkingOutput) const;
531 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
533 Link(const ToolChain &TC) : Tool("dragonfly::Link", "linker", TC) {}
535 virtual bool hasIntegratedCPP() const { return false; }
537 virtual void ConstructJob(Compilation &C, const JobAction &JA,
538 const InputInfo &Output,
539 const InputInfoList &Inputs,
540 const ArgList &TCArgs,
541 const char *LinkingOutput) const;
543 } // end namespace dragonfly
545 /// Visual studio tools.
546 namespace visualstudio {
547 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
549 Link(const ToolChain &TC) : Tool("visualstudio::Link", "linker", TC) {}
551 virtual bool hasIntegratedCPP() const { return false; }
553 virtual void ConstructJob(Compilation &C, const JobAction &JA,
554 const InputInfo &Output,
555 const InputInfoList &Inputs,
556 const ArgList &TCArgs,
557 const char *LinkingOutput) const;
559 } // end namespace visualstudio
561 } // end namespace toolchains
562 } // end namespace driver
563 } // end namespace clang
565 #endif // CLANG_LIB_DRIVER_TOOLS_H_