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"
16 #include "llvm/ADT/Triple.h"
17 #include "llvm/Option/Option.h"
18 #include "llvm/Support/Compiler.h"
27 namespace toolchains {
33 namespace visualstudio {
37 using llvm::opt::ArgStringList;
39 /// \brief Clang compiler tool.
40 class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
42 static const char *getBaseInputName(const llvm::opt::ArgList &Args,
43 const InputInfoList &Inputs);
44 static const char *getBaseInputStem(const llvm::opt::ArgList &Args,
45 const InputInfoList &Inputs);
46 static const char *getDependencyFileName(const llvm::opt::ArgList &Args,
47 const InputInfoList &Inputs);
50 void AddPreprocessingOptions(Compilation &C, const JobAction &JA,
52 const llvm::opt::ArgList &Args,
53 llvm::opt::ArgStringList &CmdArgs,
54 const InputInfo &Output,
55 const InputInfoList &Inputs) const;
57 void AddAArch64TargetArgs(const llvm::opt::ArgList &Args,
58 llvm::opt::ArgStringList &CmdArgs) const;
59 void AddARMTargetArgs(const llvm::opt::ArgList &Args,
60 llvm::opt::ArgStringList &CmdArgs,
61 bool KernelOrKext) const;
62 void AddARM64TargetArgs(const llvm::opt::ArgList &Args,
63 llvm::opt::ArgStringList &CmdArgs) const;
64 void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
65 llvm::opt::ArgStringList &CmdArgs) const;
66 void AddR600TargetArgs(const llvm::opt::ArgList &Args,
67 llvm::opt::ArgStringList &CmdArgs) const;
68 void AddSparcTargetArgs(const llvm::opt::ArgList &Args,
69 llvm::opt::ArgStringList &CmdArgs) const;
70 void AddSystemZTargetArgs(const llvm::opt::ArgList &Args,
71 llvm::opt::ArgStringList &CmdArgs) const;
72 void AddX86TargetArgs(const llvm::opt::ArgList &Args,
73 llvm::opt::ArgStringList &CmdArgs) const;
74 void AddHexagonTargetArgs(const llvm::opt::ArgList &Args,
75 llvm::opt::ArgStringList &CmdArgs) const;
77 enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile };
79 ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args,
80 llvm::opt::ArgStringList &cmdArgs,
81 RewriteKind rewrite) const;
83 void AddClangCLArgs(const llvm::opt::ArgList &Args,
84 llvm::opt::ArgStringList &CmdArgs) const;
86 visualstudio::Compile *getCLFallback() const;
88 mutable std::unique_ptr<visualstudio::Compile> CLFallback;
91 Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {}
93 bool hasGoodDiagnostics() const override { return true; }
94 bool hasIntegratedAssembler() const override { return true; }
95 bool hasIntegratedCPP() const override { return true; }
97 void ConstructJob(Compilation &C, const JobAction &JA,
98 const InputInfo &Output, const InputInfoList &Inputs,
99 const llvm::opt::ArgList &TCArgs,
100 const char *LinkingOutput) const override;
103 /// \brief Clang integrated assembler tool.
104 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
106 ClangAs(const ToolChain &TC) : Tool("clang::as",
107 "clang integrated assembler", TC) {}
109 bool hasGoodDiagnostics() const override { return true; }
110 bool hasIntegratedAssembler() const override { return false; }
111 bool hasIntegratedCPP() const override { return false; }
113 void ConstructJob(Compilation &C, const JobAction &JA,
114 const InputInfo &Output, const InputInfoList &Inputs,
115 const llvm::opt::ArgList &TCArgs,
116 const char *LinkingOutput) const override;
119 /// gcc - Generic GCC tool implementations.
121 class LLVM_LIBRARY_VISIBILITY Common : public Tool {
123 Common(const char *Name, const char *ShortName,
124 const ToolChain &TC) : Tool(Name, ShortName, TC) {}
126 void ConstructJob(Compilation &C, const JobAction &JA,
127 const InputInfo &Output,
128 const InputInfoList &Inputs,
129 const llvm::opt::ArgList &TCArgs,
130 const char *LinkingOutput) const override;
132 /// RenderExtraToolArgs - Render any arguments necessary to force
133 /// the particular tool mode.
135 RenderExtraToolArgs(const JobAction &JA,
136 llvm::opt::ArgStringList &CmdArgs) const = 0;
139 class LLVM_LIBRARY_VISIBILITY Preprocess : public Common {
141 Preprocess(const ToolChain &TC) : Common("gcc::Preprocess",
142 "gcc preprocessor", TC) {}
144 bool hasGoodDiagnostics() const override { return true; }
145 bool hasIntegratedCPP() const override { return false; }
147 void RenderExtraToolArgs(const JobAction &JA,
148 llvm::opt::ArgStringList &CmdArgs) const override;
151 class LLVM_LIBRARY_VISIBILITY Compile : public Common {
153 Compile(const ToolChain &TC) : Common("gcc::Compile",
154 "gcc frontend", TC) {}
156 bool hasGoodDiagnostics() const override { return true; }
157 bool hasIntegratedCPP() const override { return true; }
159 void RenderExtraToolArgs(const JobAction &JA,
160 llvm::opt::ArgStringList &CmdArgs) const override;
163 class LLVM_LIBRARY_VISIBILITY Link : public Common {
165 Link(const ToolChain &TC) : Common("gcc::Link",
166 "linker (via gcc)", TC) {}
168 bool hasIntegratedCPP() const override { return false; }
169 bool isLinkJob() const override { return true; }
171 void RenderExtraToolArgs(const JobAction &JA,
172 llvm::opt::ArgStringList &CmdArgs) const override;
174 } // end namespace gcc
177 // For Hexagon, we do not need to instantiate tools for PreProcess, PreCompile and Compile.
178 // We simply use "clang -cc1" for those actions.
179 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
181 Assemble(const ToolChain &TC) : Tool("hexagon::Assemble",
184 bool hasIntegratedCPP() const override { return false; }
186 void RenderExtraToolArgs(const JobAction &JA,
187 llvm::opt::ArgStringList &CmdArgs) const;
188 void ConstructJob(Compilation &C, const JobAction &JA,
189 const InputInfo &Output, const InputInfoList &Inputs,
190 const llvm::opt::ArgList &TCArgs,
191 const char *LinkingOutput) const override;
194 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
196 Link(const ToolChain &TC) : Tool("hexagon::Link",
199 bool hasIntegratedCPP() const override { return false; }
200 bool isLinkJob() const override { return true; }
202 virtual void RenderExtraToolArgs(const JobAction &JA,
203 llvm::opt::ArgStringList &CmdArgs) const;
204 void ConstructJob(Compilation &C, const JobAction &JA,
205 const InputInfo &Output, const InputInfoList &Inputs,
206 const llvm::opt::ArgList &TCArgs,
207 const char *LinkingOutput) const override;
209 } // end namespace hexagon.
212 StringRef getARMTargetCPU(const llvm::opt::ArgList &Args,
213 const llvm::Triple &Triple);
214 const char* getARMCPUForMArch(const llvm::opt::ArgList &Args,
215 const llvm::Triple &Triple);
216 const char* getLLVMArchSuffixForARM(StringRef CPU);
220 void getMipsCPUAndABI(const llvm::opt::ArgList &Args,
221 const llvm::Triple &Triple, StringRef &CPUName,
223 bool hasMipsAbiArg(const llvm::opt::ArgList &Args, const char *Value);
224 bool isNaN2008(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
225 bool isFPXXDefault(const llvm::Triple &Triple, StringRef CPUName,
230 llvm::Triple::ArchType getArchTypeForMachOArchName(StringRef Str);
231 void setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str);
233 class LLVM_LIBRARY_VISIBILITY MachOTool : public Tool {
234 virtual void anchor();
236 void AddMachOArch(const llvm::opt::ArgList &Args,
237 llvm::opt::ArgStringList &CmdArgs) const;
239 const toolchains::MachO &getMachOToolChain() const {
240 return reinterpret_cast<const toolchains::MachO&>(getToolChain());
244 MachOTool(const char *Name, const char *ShortName,
245 const ToolChain &TC) : Tool(Name, ShortName, TC) {}
248 class LLVM_LIBRARY_VISIBILITY Assemble : public MachOTool {
250 Assemble(const ToolChain &TC) : MachOTool("darwin::Assemble",
253 bool hasIntegratedCPP() const override { return false; }
255 void ConstructJob(Compilation &C, const JobAction &JA,
256 const InputInfo &Output, const InputInfoList &Inputs,
257 const llvm::opt::ArgList &TCArgs,
258 const char *LinkingOutput) const override;
261 class LLVM_LIBRARY_VISIBILITY Link : public MachOTool {
262 bool NeedsTempPath(const InputInfoList &Inputs) const;
263 void AddLinkArgs(Compilation &C, const llvm::opt::ArgList &Args,
264 llvm::opt::ArgStringList &CmdArgs,
265 const InputInfoList &Inputs) const;
268 Link(const ToolChain &TC) : MachOTool("darwin::Link", "linker", TC) {}
270 bool hasIntegratedCPP() const override { return false; }
271 bool isLinkJob() const override { return true; }
273 void ConstructJob(Compilation &C, const JobAction &JA,
274 const InputInfo &Output, const InputInfoList &Inputs,
275 const llvm::opt::ArgList &TCArgs,
276 const char *LinkingOutput) const override;
279 class LLVM_LIBRARY_VISIBILITY Lipo : public MachOTool {
281 Lipo(const ToolChain &TC) : MachOTool("darwin::Lipo", "lipo", TC) {}
283 bool hasIntegratedCPP() const override { return false; }
285 void ConstructJob(Compilation &C, const JobAction &JA,
286 const InputInfo &Output, const InputInfoList &Inputs,
287 const llvm::opt::ArgList &TCArgs,
288 const char *LinkingOutput) const override;
291 class LLVM_LIBRARY_VISIBILITY Dsymutil : public MachOTool {
293 Dsymutil(const ToolChain &TC) : MachOTool("darwin::Dsymutil",
296 bool hasIntegratedCPP() const override { return false; }
297 bool isDsymutilJob() const override { return true; }
299 void ConstructJob(Compilation &C, const JobAction &JA,
300 const InputInfo &Output,
301 const InputInfoList &Inputs,
302 const llvm::opt::ArgList &TCArgs,
303 const char *LinkingOutput) const override;
306 class LLVM_LIBRARY_VISIBILITY VerifyDebug : public MachOTool {
308 VerifyDebug(const ToolChain &TC) : MachOTool("darwin::VerifyDebug",
311 bool hasIntegratedCPP() const override { return false; }
313 void ConstructJob(Compilation &C, const JobAction &JA,
314 const InputInfo &Output, const InputInfoList &Inputs,
315 const llvm::opt::ArgList &TCArgs,
316 const char *LinkingOutput) const override;
321 /// openbsd -- Directly call GNU Binutils assembler and linker
323 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
325 Assemble(const ToolChain &TC) : Tool("openbsd::Assemble", "assembler",
328 bool hasIntegratedCPP() const override { return false; }
330 void ConstructJob(Compilation &C, const JobAction &JA,
331 const InputInfo &Output,
332 const InputInfoList &Inputs,
333 const llvm::opt::ArgList &TCArgs,
334 const char *LinkingOutput) const override;
336 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
338 Link(const ToolChain &TC) : Tool("openbsd::Link", "linker", TC) {}
340 bool hasIntegratedCPP() const override { return false; }
341 bool isLinkJob() const override { return true; }
343 void ConstructJob(Compilation &C, const JobAction &JA,
344 const InputInfo &Output, const InputInfoList &Inputs,
345 const llvm::opt::ArgList &TCArgs,
346 const char *LinkingOutput) const override;
348 } // end namespace openbsd
350 /// bitrig -- Directly call GNU Binutils assembler and linker
352 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
354 Assemble(const ToolChain &TC) : Tool("bitrig::Assemble", "assembler",
357 bool hasIntegratedCPP() const override { return false; }
359 void ConstructJob(Compilation &C, const JobAction &JA,
360 const InputInfo &Output, const InputInfoList &Inputs,
361 const llvm::opt::ArgList &TCArgs,
362 const char *LinkingOutput) const override;
364 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
366 Link(const ToolChain &TC) : Tool("bitrig::Link", "linker", TC) {}
368 bool hasIntegratedCPP() const override { return false; }
369 bool isLinkJob() const override { return true; }
371 void ConstructJob(Compilation &C, const JobAction &JA,
372 const InputInfo &Output, const InputInfoList &Inputs,
373 const llvm::opt::ArgList &TCArgs,
374 const char *LinkingOutput) const override;
376 } // end namespace bitrig
378 /// freebsd -- Directly call GNU Binutils assembler and linker
380 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
382 Assemble(const ToolChain &TC) : Tool("freebsd::Assemble", "assembler",
385 bool hasIntegratedCPP() const override { return false; }
387 void ConstructJob(Compilation &C, const JobAction &JA,
388 const InputInfo &Output, const InputInfoList &Inputs,
389 const llvm::opt::ArgList &TCArgs,
390 const char *LinkingOutput) const override;
392 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
394 Link(const ToolChain &TC) : Tool("freebsd::Link", "linker", TC) {}
396 bool hasIntegratedCPP() const override { return false; }
397 bool isLinkJob() const override { return true; }
399 void ConstructJob(Compilation &C, const JobAction &JA,
400 const InputInfo &Output, const InputInfoList &Inputs,
401 const llvm::opt::ArgList &TCArgs,
402 const char *LinkingOutput) const override;
404 } // end namespace freebsd
406 /// netbsd -- Directly call GNU Binutils assembler and linker
408 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
411 Assemble(const ToolChain &TC)
412 : Tool("netbsd::Assemble", "assembler", TC) {}
414 bool hasIntegratedCPP() const override { return false; }
416 void ConstructJob(Compilation &C, const JobAction &JA,
417 const InputInfo &Output, const InputInfoList &Inputs,
418 const llvm::opt::ArgList &TCArgs,
419 const char *LinkingOutput) const override;
421 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
424 Link(const ToolChain &TC)
425 : Tool("netbsd::Link", "linker", TC) {}
427 bool hasIntegratedCPP() const override { return false; }
428 bool isLinkJob() const override { return true; }
430 void ConstructJob(Compilation &C, const JobAction &JA,
431 const InputInfo &Output, const InputInfoList &Inputs,
432 const llvm::opt::ArgList &TCArgs,
433 const char *LinkingOutput) const override;
435 } // end namespace netbsd
437 /// Directly call GNU Binutils' assembler and linker.
439 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
441 Assemble(const ToolChain &TC) : Tool("GNU::Assemble", "assembler", TC) {}
443 bool hasIntegratedCPP() const override { return false; }
445 void ConstructJob(Compilation &C, const JobAction &JA,
446 const InputInfo &Output,
447 const InputInfoList &Inputs,
448 const llvm::opt::ArgList &TCArgs,
449 const char *LinkingOutput) const override;
451 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
453 Link(const ToolChain &TC) : Tool("GNU::Link", "linker", TC) {}
455 bool hasIntegratedCPP() const override { return false; }
456 bool isLinkJob() const override { return true; }
458 void ConstructJob(Compilation &C, const JobAction &JA,
459 const InputInfo &Output,
460 const InputInfoList &Inputs,
461 const llvm::opt::ArgList &TCArgs,
462 const char *LinkingOutput) const override;
465 /// minix -- Directly call GNU Binutils assembler and linker
467 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
469 Assemble(const ToolChain &TC) : Tool("minix::Assemble", "assembler",
472 bool hasIntegratedCPP() const override { return false; }
474 void ConstructJob(Compilation &C, const JobAction &JA,
475 const InputInfo &Output,
476 const InputInfoList &Inputs,
477 const llvm::opt::ArgList &TCArgs,
478 const char *LinkingOutput) const override;
480 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
482 Link(const ToolChain &TC) : Tool("minix::Link", "linker", TC) {}
484 bool hasIntegratedCPP() const override { return false; }
485 bool isLinkJob() const override { return true; }
487 void ConstructJob(Compilation &C, const JobAction &JA,
488 const InputInfo &Output,
489 const InputInfoList &Inputs,
490 const llvm::opt::ArgList &TCArgs,
491 const char *LinkingOutput) const override;
493 } // end namespace minix
495 /// solaris -- Directly call Solaris assembler and linker
497 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
499 Assemble(const ToolChain &TC) : Tool("solaris::Assemble", "assembler",
502 bool hasIntegratedCPP() const override { return false; }
504 void ConstructJob(Compilation &C, const JobAction &JA,
505 const InputInfo &Output, const InputInfoList &Inputs,
506 const llvm::opt::ArgList &TCArgs,
507 const char *LinkingOutput) const override;
509 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
511 Link(const ToolChain &TC) : Tool("solaris::Link", "linker", TC) {}
513 bool hasIntegratedCPP() const override { return false; }
514 bool isLinkJob() const override { return true; }
516 void ConstructJob(Compilation &C, const JobAction &JA,
517 const InputInfo &Output, const InputInfoList &Inputs,
518 const llvm::opt::ArgList &TCArgs,
519 const char *LinkingOutput) const override;
521 } // end namespace solaris
523 /// auroraux -- Directly call GNU Binutils assembler and linker
525 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
527 Assemble(const ToolChain &TC) : Tool("auroraux::Assemble", "assembler",
530 bool hasIntegratedCPP() const override { return false; }
532 void ConstructJob(Compilation &C, const JobAction &JA,
533 const InputInfo &Output, const InputInfoList &Inputs,
534 const llvm::opt::ArgList &TCArgs,
535 const char *LinkingOutput) const override;
537 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
539 Link(const ToolChain &TC) : Tool("auroraux::Link", "linker", TC) {}
541 bool hasIntegratedCPP() const override { return false; }
542 bool isLinkJob() const override { return true; }
544 void ConstructJob(Compilation &C, const JobAction &JA,
545 const InputInfo &Output, const InputInfoList &Inputs,
546 const llvm::opt::ArgList &TCArgs,
547 const char *LinkingOutput) const override;
549 } // end namespace auroraux
551 /// dragonfly -- Directly call GNU Binutils assembler and linker
552 namespace dragonfly {
553 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
555 Assemble(const ToolChain &TC) : Tool("dragonfly::Assemble", "assembler",
558 bool hasIntegratedCPP() const override { return false; }
560 void ConstructJob(Compilation &C, const JobAction &JA,
561 const InputInfo &Output, const InputInfoList &Inputs,
562 const llvm::opt::ArgList &TCArgs,
563 const char *LinkingOutput) const override;
565 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
567 Link(const ToolChain &TC) : Tool("dragonfly::Link", "linker", TC) {}
569 bool hasIntegratedCPP() const override { return false; }
570 bool isLinkJob() const override { return true; }
572 void ConstructJob(Compilation &C, const JobAction &JA,
573 const InputInfo &Output,
574 const InputInfoList &Inputs,
575 const llvm::opt::ArgList &TCArgs,
576 const char *LinkingOutput) const override;
578 } // end namespace dragonfly
580 /// Visual studio tools.
581 namespace visualstudio {
582 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
584 Link(const ToolChain &TC) : Tool("visualstudio::Link", "linker", TC) {}
586 bool hasIntegratedCPP() const override { return false; }
587 bool isLinkJob() const override { return true; }
589 void ConstructJob(Compilation &C, const JobAction &JA,
590 const InputInfo &Output, const InputInfoList &Inputs,
591 const llvm::opt::ArgList &TCArgs,
592 const char *LinkingOutput) const override;
595 class LLVM_LIBRARY_VISIBILITY Compile : public Tool {
597 Compile(const ToolChain &TC) : Tool("visualstudio::Compile", "compiler", TC) {}
599 bool hasIntegratedAssembler() const override { return true; }
600 bool hasIntegratedCPP() const override { return true; }
601 bool isLinkJob() const override { return false; }
603 void ConstructJob(Compilation &C, const JobAction &JA,
604 const InputInfo &Output, const InputInfoList &Inputs,
605 const llvm::opt::ArgList &TCArgs,
606 const char *LinkingOutput) const override;
608 Command *GetCommand(Compilation &C, const JobAction &JA,
609 const InputInfo &Output,
610 const InputInfoList &Inputs,
611 const llvm::opt::ArgList &TCArgs,
612 const char *LinkingOutput) const;
614 } // end namespace visualstudio
617 StringRef getARMFloatABI(const Driver &D, const llvm::opt::ArgList &Args,
618 const llvm::Triple &Triple);
621 // For XCore, we do not need to instantiate tools for PreProcess, PreCompile and Compile.
622 // We simply use "clang -cc1" for those actions.
623 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
625 Assemble(const ToolChain &TC) : Tool("XCore::Assemble",
628 bool hasIntegratedCPP() const override { return false; }
629 void ConstructJob(Compilation &C, const JobAction &JA,
630 const InputInfo &Output, const InputInfoList &Inputs,
631 const llvm::opt::ArgList &TCArgs,
632 const char *LinkingOutput) const override;
635 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
637 Link(const ToolChain &TC) : Tool("XCore::Link",
640 bool hasIntegratedCPP() const override { return false; }
641 bool isLinkJob() const override { return true; }
642 void ConstructJob(Compilation &C, const JobAction &JA,
643 const InputInfo &Output, const InputInfoList &Inputs,
644 const llvm::opt::ArgList &TCArgs,
645 const char *LinkingOutput) const override;
647 } // end namespace XCore.
650 } // end namespace toolchains
651 } // end namespace driver
652 } // end namespace clang
654 #endif // CLANG_LIB_DRIVER_TOOLS_H_