]> granicus.if.org Git - clang/blob - lib/Driver/Tools.h
Fix some Clang-tidy modernize warnings, other minor fixes.
[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 LLVM_CLANG_LIB_DRIVER_TOOLS_H
11 #define LLVM_CLANG_LIB_DRIVER_TOOLS_H
12
13 #include "clang/Basic/VersionTuple.h"
14 #include "clang/Driver/Tool.h"
15 #include "clang/Driver/Types.h"
16 #include "clang/Driver/Util.h"
17 #include "clang/Frontend/CodeGenOptions.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Option/Option.h"
20 #include "llvm/Support/Compiler.h"
21
22 namespace clang {
23 class ObjCRuntime;
24
25 namespace driver {
26 class Command;
27 class Driver;
28
29 namespace toolchains {
30 class MachO;
31 }
32
33 namespace tools {
34
35 namespace visualstudio {
36 class Compiler;
37 }
38
39 using llvm::opt::ArgStringList;
40
41 SmallString<128> getCompilerRT(const ToolChain &TC,
42                                const llvm::opt::ArgList &Args,
43                                StringRef Component, bool Shared = false);
44
45 /// \brief Clang compiler tool.
46 class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
47 public:
48   static const char *getBaseInputName(const llvm::opt::ArgList &Args,
49                                       const InputInfo &Input);
50   static const char *getBaseInputStem(const llvm::opt::ArgList &Args,
51                                       const InputInfoList &Inputs);
52   static const char *getDependencyFileName(const llvm::opt::ArgList &Args,
53                                            const InputInfoList &Inputs);
54
55 private:
56   void AddPreprocessingOptions(Compilation &C, const JobAction &JA,
57                                const Driver &D, const llvm::opt::ArgList &Args,
58                                llvm::opt::ArgStringList &CmdArgs,
59                                const InputInfo &Output,
60                                const InputInfoList &Inputs) const;
61
62   void AddAArch64TargetArgs(const llvm::opt::ArgList &Args,
63                             llvm::opt::ArgStringList &CmdArgs) const;
64   void AddARMTargetArgs(const llvm::Triple &Triple,
65                         const llvm::opt::ArgList &Args,
66                         llvm::opt::ArgStringList &CmdArgs,
67                         bool KernelOrKext) const;
68   void AddARM64TargetArgs(const llvm::opt::ArgList &Args,
69                           llvm::opt::ArgStringList &CmdArgs) const;
70   void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
71                          llvm::opt::ArgStringList &CmdArgs) const;
72   void AddPPCTargetArgs(const llvm::opt::ArgList &Args,
73                         llvm::opt::ArgStringList &CmdArgs) const;
74   void AddR600TargetArgs(const llvm::opt::ArgList &Args,
75                          llvm::opt::ArgStringList &CmdArgs) const;
76   void AddSparcTargetArgs(const llvm::opt::ArgList &Args,
77                           llvm::opt::ArgStringList &CmdArgs) const;
78   void AddSystemZTargetArgs(const llvm::opt::ArgList &Args,
79                             llvm::opt::ArgStringList &CmdArgs) const;
80   void AddX86TargetArgs(const llvm::opt::ArgList &Args,
81                         llvm::opt::ArgStringList &CmdArgs) const;
82   void AddHexagonTargetArgs(const llvm::opt::ArgList &Args,
83                             llvm::opt::ArgStringList &CmdArgs) const;
84
85   enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile };
86
87   ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args,
88                                  llvm::opt::ArgStringList &cmdArgs,
89                                  RewriteKind rewrite) const;
90
91   void AddClangCLArgs(const llvm::opt::ArgList &Args,
92                       llvm::opt::ArgStringList &CmdArgs,
93                       enum CodeGenOptions::DebugInfoKind *DebugInfoKind,
94                       bool *EmitCodeView) const;
95
96   visualstudio::Compiler *getCLFallback() const;
97
98   mutable std::unique_ptr<visualstudio::Compiler> CLFallback;
99
100 public:
101   // CAUTION! The first constructor argument ("clang") is not arbitrary,
102   // as it is for other tools. Some operations on a Tool actually test
103   // whether that tool is Clang based on the Tool's Name as a string.
104   Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC, RF_Full) {}
105
106   bool hasGoodDiagnostics() const override { return true; }
107   bool hasIntegratedAssembler() const override { return true; }
108   bool hasIntegratedCPP() const override { return true; }
109   bool canEmitIR() const override { return true; }
110
111   void ConstructJob(Compilation &C, const JobAction &JA,
112                     const InputInfo &Output, const InputInfoList &Inputs,
113                     const llvm::opt::ArgList &TCArgs,
114                     const char *LinkingOutput) const override;
115 };
116
117 /// \brief Clang integrated assembler tool.
118 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
119 public:
120   ClangAs(const ToolChain &TC)
121       : Tool("clang::as", "clang integrated assembler", TC, RF_Full) {}
122   void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
123                          llvm::opt::ArgStringList &CmdArgs) const;
124   bool hasGoodDiagnostics() const override { return true; }
125   bool hasIntegratedAssembler() const override { return false; }
126   bool hasIntegratedCPP() const override { return false; }
127
128   void ConstructJob(Compilation &C, const JobAction &JA,
129                     const InputInfo &Output, const InputInfoList &Inputs,
130                     const llvm::opt::ArgList &TCArgs,
131                     const char *LinkingOutput) const override;
132 };
133
134 /// \brief Base class for all GNU tools that provide the same behavior when
135 /// it comes to response files support
136 class LLVM_LIBRARY_VISIBILITY GnuTool : public Tool {
137   virtual void anchor();
138
139 public:
140   GnuTool(const char *Name, const char *ShortName, const ToolChain &TC)
141       : Tool(Name, ShortName, TC, RF_Full, llvm::sys::WEM_CurrentCodePage) {}
142 };
143
144 /// gcc - Generic GCC tool implementations.
145 namespace gcc {
146 class LLVM_LIBRARY_VISIBILITY Common : public GnuTool {
147 public:
148   Common(const char *Name, const char *ShortName, const ToolChain &TC)
149       : GnuTool(Name, ShortName, TC) {}
150
151   void ConstructJob(Compilation &C, const JobAction &JA,
152                     const InputInfo &Output, const InputInfoList &Inputs,
153                     const llvm::opt::ArgList &TCArgs,
154                     const char *LinkingOutput) const override;
155
156   /// RenderExtraToolArgs - Render any arguments necessary to force
157   /// the particular tool mode.
158   virtual void RenderExtraToolArgs(const JobAction &JA,
159                                    llvm::opt::ArgStringList &CmdArgs) const = 0;
160 };
161
162 class LLVM_LIBRARY_VISIBILITY Preprocessor : public Common {
163 public:
164   Preprocessor(const ToolChain &TC)
165       : Common("gcc::Preprocessor", "gcc preprocessor", TC) {}
166
167   bool hasGoodDiagnostics() const override { return true; }
168   bool hasIntegratedCPP() const override { return false; }
169
170   void RenderExtraToolArgs(const JobAction &JA,
171                            llvm::opt::ArgStringList &CmdArgs) const override;
172 };
173
174 class LLVM_LIBRARY_VISIBILITY Compiler : public Common {
175 public:
176   Compiler(const ToolChain &TC) : Common("gcc::Compiler", "gcc frontend", TC) {}
177
178   bool hasGoodDiagnostics() const override { return true; }
179   bool hasIntegratedCPP() const override { return true; }
180
181   void RenderExtraToolArgs(const JobAction &JA,
182                            llvm::opt::ArgStringList &CmdArgs) const override;
183 };
184
185 class LLVM_LIBRARY_VISIBILITY Linker : public Common {
186 public:
187   Linker(const ToolChain &TC) : Common("gcc::Linker", "linker (via gcc)", TC) {}
188
189   bool hasIntegratedCPP() const override { return false; }
190   bool isLinkJob() const override { return true; }
191
192   void RenderExtraToolArgs(const JobAction &JA,
193                            llvm::opt::ArgStringList &CmdArgs) const override;
194 };
195 } // end namespace gcc
196
197 namespace hexagon {
198 // For Hexagon, we do not need to instantiate tools for PreProcess, PreCompile
199 // and Compile.
200 // We simply use "clang -cc1" for those actions.
201 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
202 public:
203   Assembler(const ToolChain &TC)
204       : GnuTool("hexagon::Assembler", "hexagon-as", TC) {}
205
206   bool hasIntegratedCPP() const override { return false; }
207
208   void RenderExtraToolArgs(const JobAction &JA,
209                            llvm::opt::ArgStringList &CmdArgs) const;
210   void ConstructJob(Compilation &C, const JobAction &JA,
211                     const InputInfo &Output, const InputInfoList &Inputs,
212                     const llvm::opt::ArgList &TCArgs,
213                     const char *LinkingOutput) const override;
214 };
215
216 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
217 public:
218   Linker(const ToolChain &TC) : GnuTool("hexagon::Linker", "hexagon-ld", TC) {}
219
220   bool hasIntegratedCPP() const override { return false; }
221   bool isLinkJob() const override { return true; }
222
223   virtual void RenderExtraToolArgs(const JobAction &JA,
224                                    llvm::opt::ArgStringList &CmdArgs) const;
225   void ConstructJob(Compilation &C, const JobAction &JA,
226                     const InputInfo &Output, const InputInfoList &Inputs,
227                     const llvm::opt::ArgList &TCArgs,
228                     const char *LinkingOutput) const override;
229 };
230 } // end namespace hexagon.
231
232 namespace amdgpu {
233
234 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
235 public:
236   Linker(const ToolChain &TC) : GnuTool("amdgpu::Linker", "lld", TC) {}
237   bool isLinkJob() const override { return true; }
238   bool hasIntegratedCPP() const override { return false; }
239   void ConstructJob(Compilation &C, const JobAction &JA,
240                     const InputInfo &Output, const InputInfoList &Inputs,
241                     const llvm::opt::ArgList &TCArgs,
242                     const char *LinkingOutput) const override;
243 };
244
245 } // end namespace amdgpu
246
247 namespace arm {
248 std::string getARMTargetCPU(StringRef CPU, StringRef Arch,
249                             const llvm::Triple &Triple);
250 const std::string getARMArch(StringRef Arch,
251                              const llvm::Triple &Triple);
252 StringRef getARMCPUForMArch(StringRef Arch, const llvm::Triple &Triple);
253 StringRef getLLVMArchSuffixForARM(StringRef CPU, StringRef Arch,
254                                   const llvm::Triple &Triple);
255
256 void appendEBLinkFlags(const llvm::opt::ArgList &Args, ArgStringList &CmdArgs,
257                        const llvm::Triple &Triple);
258 } // end namespace arm
259
260 namespace mips {
261 typedef enum { NanLegacy = 1, Nan2008 = 2 } NanEncoding;
262
263 enum class FloatABI {
264   Invalid,
265   Soft,
266   Hard,
267 };
268
269 NanEncoding getSupportedNanEncoding(StringRef &CPU);
270 void getMipsCPUAndABI(const llvm::opt::ArgList &Args,
271                       const llvm::Triple &Triple, StringRef &CPUName,
272                       StringRef &ABIName);
273 bool hasMipsAbiArg(const llvm::opt::ArgList &Args, const char *Value);
274 bool isUCLibc(const llvm::opt::ArgList &Args);
275 bool isNaN2008(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
276 bool isFPXXDefault(const llvm::Triple &Triple, StringRef CPUName,
277                    StringRef ABIName, mips::FloatABI FloatABI);
278 bool shouldUseFPXX(const llvm::opt::ArgList &Args, const llvm::Triple &Triple,
279                    StringRef CPUName, StringRef ABIName,
280                    mips::FloatABI FloatABI);
281 } // end namespace mips
282
283 namespace ppc {
284 bool hasPPCAbiArg(const llvm::opt::ArgList &Args, const char *Value);
285 } // end namespace ppc
286
287 /// cloudabi -- Directly call GNU Binutils linker
288 namespace cloudabi {
289 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
290 public:
291   Linker(const ToolChain &TC) : GnuTool("cloudabi::Linker", "linker", TC) {}
292
293   bool hasIntegratedCPP() const override { return false; }
294   bool isLinkJob() const override { return true; }
295
296   void ConstructJob(Compilation &C, const JobAction &JA,
297                     const InputInfo &Output, const InputInfoList &Inputs,
298                     const llvm::opt::ArgList &TCArgs,
299                     const char *LinkingOutput) const override;
300 };
301 } // end namespace cloudabi
302
303 namespace darwin {
304 llvm::Triple::ArchType getArchTypeForMachOArchName(StringRef Str);
305 void setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str);
306
307 class LLVM_LIBRARY_VISIBILITY MachOTool : public Tool {
308   virtual void anchor();
309
310 protected:
311   void AddMachOArch(const llvm::opt::ArgList &Args,
312                     llvm::opt::ArgStringList &CmdArgs) const;
313
314   const toolchains::MachO &getMachOToolChain() const {
315     return reinterpret_cast<const toolchains::MachO &>(getToolChain());
316   }
317
318 public:
319   MachOTool(
320       const char *Name, const char *ShortName, const ToolChain &TC,
321       ResponseFileSupport ResponseSupport = RF_None,
322       llvm::sys::WindowsEncodingMethod ResponseEncoding = llvm::sys::WEM_UTF8,
323       const char *ResponseFlag = "@")
324       : Tool(Name, ShortName, TC, ResponseSupport, ResponseEncoding,
325              ResponseFlag) {}
326 };
327
328 class LLVM_LIBRARY_VISIBILITY Assembler : public MachOTool {
329 public:
330   Assembler(const ToolChain &TC)
331       : MachOTool("darwin::Assembler", "assembler", TC) {}
332
333   bool hasIntegratedCPP() const override { return false; }
334
335   void ConstructJob(Compilation &C, const JobAction &JA,
336                     const InputInfo &Output, const InputInfoList &Inputs,
337                     const llvm::opt::ArgList &TCArgs,
338                     const char *LinkingOutput) const override;
339 };
340
341 class LLVM_LIBRARY_VISIBILITY Linker : public MachOTool {
342   bool NeedsTempPath(const InputInfoList &Inputs) const;
343   void AddLinkArgs(Compilation &C, const llvm::opt::ArgList &Args,
344                    llvm::opt::ArgStringList &CmdArgs,
345                    const InputInfoList &Inputs) const;
346
347 public:
348   Linker(const ToolChain &TC)
349       : MachOTool("darwin::Linker", "linker", TC, RF_FileList,
350                   llvm::sys::WEM_UTF8, "-filelist") {}
351
352   bool hasIntegratedCPP() const override { return false; }
353   bool isLinkJob() const override { return true; }
354
355   void ConstructJob(Compilation &C, const JobAction &JA,
356                     const InputInfo &Output, const InputInfoList &Inputs,
357                     const llvm::opt::ArgList &TCArgs,
358                     const char *LinkingOutput) const override;
359 };
360
361 class LLVM_LIBRARY_VISIBILITY Lipo : public MachOTool {
362 public:
363   Lipo(const ToolChain &TC) : MachOTool("darwin::Lipo", "lipo", TC) {}
364
365   bool hasIntegratedCPP() const override { return false; }
366
367   void ConstructJob(Compilation &C, const JobAction &JA,
368                     const InputInfo &Output, const InputInfoList &Inputs,
369                     const llvm::opt::ArgList &TCArgs,
370                     const char *LinkingOutput) const override;
371 };
372
373 class LLVM_LIBRARY_VISIBILITY Dsymutil : public MachOTool {
374 public:
375   Dsymutil(const ToolChain &TC)
376       : MachOTool("darwin::Dsymutil", "dsymutil", TC) {}
377
378   bool hasIntegratedCPP() const override { return false; }
379   bool isDsymutilJob() const override { return true; }
380
381   void ConstructJob(Compilation &C, const JobAction &JA,
382                     const InputInfo &Output, const InputInfoList &Inputs,
383                     const llvm::opt::ArgList &TCArgs,
384                     const char *LinkingOutput) const override;
385 };
386
387 class LLVM_LIBRARY_VISIBILITY VerifyDebug : public MachOTool {
388 public:
389   VerifyDebug(const ToolChain &TC)
390       : MachOTool("darwin::VerifyDebug", "dwarfdump", TC) {}
391
392   bool hasIntegratedCPP() const override { return false; }
393
394   void ConstructJob(Compilation &C, const JobAction &JA,
395                     const InputInfo &Output, const InputInfoList &Inputs,
396                     const llvm::opt::ArgList &TCArgs,
397                     const char *LinkingOutput) const override;
398 };
399 } // end namespace darwin
400
401 /// openbsd -- Directly call GNU Binutils assembler and linker
402 namespace openbsd {
403 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
404 public:
405   Assembler(const ToolChain &TC)
406       : GnuTool("openbsd::Assembler", "assembler", TC) {}
407
408   bool hasIntegratedCPP() const override { return false; }
409
410   void ConstructJob(Compilation &C, const JobAction &JA,
411                     const InputInfo &Output, const InputInfoList &Inputs,
412                     const llvm::opt::ArgList &TCArgs,
413                     const char *LinkingOutput) const override;
414 };
415
416 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
417 public:
418   Linker(const ToolChain &TC) : GnuTool("openbsd::Linker", "linker", TC) {}
419
420   bool hasIntegratedCPP() const override { return false; }
421   bool isLinkJob() const override { return true; }
422
423   void ConstructJob(Compilation &C, const JobAction &JA,
424                     const InputInfo &Output, const InputInfoList &Inputs,
425                     const llvm::opt::ArgList &TCArgs,
426                     const char *LinkingOutput) const override;
427 };
428 } // end namespace openbsd
429
430 /// bitrig -- Directly call GNU Binutils assembler and linker
431 namespace bitrig {
432 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
433 public:
434   Assembler(const ToolChain &TC)
435       : GnuTool("bitrig::Assembler", "assembler", TC) {}
436
437   bool hasIntegratedCPP() const override { return false; }
438
439   void ConstructJob(Compilation &C, const JobAction &JA,
440                     const InputInfo &Output, const InputInfoList &Inputs,
441                     const llvm::opt::ArgList &TCArgs,
442                     const char *LinkingOutput) const override;
443 };
444
445 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
446 public:
447   Linker(const ToolChain &TC) : GnuTool("bitrig::Linker", "linker", TC) {}
448
449   bool hasIntegratedCPP() const override { return false; }
450   bool isLinkJob() const override { return true; }
451
452   void ConstructJob(Compilation &C, const JobAction &JA,
453                     const InputInfo &Output, const InputInfoList &Inputs,
454                     const llvm::opt::ArgList &TCArgs,
455                     const char *LinkingOutput) const override;
456 };
457 } // end namespace bitrig
458
459 /// freebsd -- Directly call GNU Binutils assembler and linker
460 namespace freebsd {
461 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
462 public:
463   Assembler(const ToolChain &TC)
464       : GnuTool("freebsd::Assembler", "assembler", TC) {}
465
466   bool hasIntegratedCPP() const override { return false; }
467
468   void ConstructJob(Compilation &C, const JobAction &JA,
469                     const InputInfo &Output, const InputInfoList &Inputs,
470                     const llvm::opt::ArgList &TCArgs,
471                     const char *LinkingOutput) const override;
472 };
473
474 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
475 public:
476   Linker(const ToolChain &TC) : GnuTool("freebsd::Linker", "linker", TC) {}
477
478   bool hasIntegratedCPP() const override { return false; }
479   bool isLinkJob() const override { return true; }
480
481   void ConstructJob(Compilation &C, const JobAction &JA,
482                     const InputInfo &Output, const InputInfoList &Inputs,
483                     const llvm::opt::ArgList &TCArgs,
484                     const char *LinkingOutput) const override;
485 };
486 } // end namespace freebsd
487
488 /// netbsd -- Directly call GNU Binutils assembler and linker
489 namespace netbsd {
490 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
491 public:
492   Assembler(const ToolChain &TC)
493       : GnuTool("netbsd::Assembler", "assembler", TC) {}
494
495   bool hasIntegratedCPP() const override { return false; }
496
497   void ConstructJob(Compilation &C, const JobAction &JA,
498                     const InputInfo &Output, const InputInfoList &Inputs,
499                     const llvm::opt::ArgList &TCArgs,
500                     const char *LinkingOutput) const override;
501 };
502
503 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
504 public:
505   Linker(const ToolChain &TC) : GnuTool("netbsd::Linker", "linker", TC) {}
506
507   bool hasIntegratedCPP() const override { return false; }
508   bool isLinkJob() const override { return true; }
509
510   void ConstructJob(Compilation &C, const JobAction &JA,
511                     const InputInfo &Output, const InputInfoList &Inputs,
512                     const llvm::opt::ArgList &TCArgs,
513                     const char *LinkingOutput) const override;
514 };
515 } // end namespace netbsd
516
517 /// Directly call GNU Binutils' assembler and linker.
518 namespace gnutools {
519 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
520 public:
521   Assembler(const ToolChain &TC) : GnuTool("GNU::Assembler", "assembler", TC) {}
522
523   bool hasIntegratedCPP() const override { return false; }
524
525   void ConstructJob(Compilation &C, const JobAction &JA,
526                     const InputInfo &Output, const InputInfoList &Inputs,
527                     const llvm::opt::ArgList &TCArgs,
528                     const char *LinkingOutput) const override;
529 };
530
531 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
532 public:
533   Linker(const ToolChain &TC) : GnuTool("GNU::Linker", "linker", TC) {}
534
535   bool hasIntegratedCPP() const override { return false; }
536   bool isLinkJob() const override { return true; }
537
538   void ConstructJob(Compilation &C, const JobAction &JA,
539                     const InputInfo &Output, const InputInfoList &Inputs,
540                     const llvm::opt::ArgList &TCArgs,
541                     const char *LinkingOutput) const override;
542 };
543 } // end namespace gnutools
544
545 namespace nacltools {
546 class LLVM_LIBRARY_VISIBILITY AssemblerARM : public gnutools::Assembler {
547 public:
548   AssemblerARM(const ToolChain &TC) : gnutools::Assembler(TC) {}
549
550   void ConstructJob(Compilation &C, const JobAction &JA,
551                     const InputInfo &Output, const InputInfoList &Inputs,
552                     const llvm::opt::ArgList &TCArgs,
553                     const char *LinkingOutput) const override;
554 };
555
556 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
557 public:
558   Linker(const ToolChain &TC) : Tool("NaCl::Linker", "linker", TC) {}
559
560   bool hasIntegratedCPP() const override { return false; }
561   bool isLinkJob() const override { return true; }
562
563   void ConstructJob(Compilation &C, const JobAction &JA,
564                     const InputInfo &Output, const InputInfoList &Inputs,
565                     const llvm::opt::ArgList &TCArgs,
566                     const char *LinkingOutput) const override;
567 };
568 } // end namespace nacltools
569
570 /// minix -- Directly call GNU Binutils assembler and linker
571 namespace minix {
572 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
573 public:
574   Assembler(const ToolChain &TC)
575       : GnuTool("minix::Assembler", "assembler", TC) {}
576
577   bool hasIntegratedCPP() const override { return false; }
578
579   void ConstructJob(Compilation &C, const JobAction &JA,
580                     const InputInfo &Output, const InputInfoList &Inputs,
581                     const llvm::opt::ArgList &TCArgs,
582                     const char *LinkingOutput) const override;
583 };
584
585 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
586 public:
587   Linker(const ToolChain &TC) : GnuTool("minix::Linker", "linker", TC) {}
588
589   bool hasIntegratedCPP() const override { return false; }
590   bool isLinkJob() const override { return true; }
591
592   void ConstructJob(Compilation &C, const JobAction &JA,
593                     const InputInfo &Output, const InputInfoList &Inputs,
594                     const llvm::opt::ArgList &TCArgs,
595                     const char *LinkingOutput) const override;
596 };
597 } // end namespace minix
598
599 /// solaris -- Directly call Solaris assembler and linker
600 namespace solaris {
601 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
602 public:
603   Assembler(const ToolChain &TC)
604       : Tool("solaris::Assembler", "assembler", TC) {}
605
606   bool hasIntegratedCPP() const override { return false; }
607
608   void ConstructJob(Compilation &C, const JobAction &JA,
609                     const InputInfo &Output, const InputInfoList &Inputs,
610                     const llvm::opt::ArgList &TCArgs,
611                     const char *LinkingOutput) const override;
612 };
613
614 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
615 public:
616   Linker(const ToolChain &TC) : Tool("solaris::Linker", "linker", TC) {}
617
618   bool hasIntegratedCPP() const override { return false; }
619   bool isLinkJob() const override { return true; }
620
621   void ConstructJob(Compilation &C, const JobAction &JA,
622                     const InputInfo &Output, const InputInfoList &Inputs,
623                     const llvm::opt::ArgList &TCArgs,
624                     const char *LinkingOutput) const override;
625 };
626 } // end namespace solaris
627
628 /// dragonfly -- Directly call GNU Binutils assembler and linker
629 namespace dragonfly {
630 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
631 public:
632   Assembler(const ToolChain &TC)
633       : GnuTool("dragonfly::Assembler", "assembler", TC) {}
634
635   bool hasIntegratedCPP() const override { return false; }
636
637   void ConstructJob(Compilation &C, const JobAction &JA,
638                     const InputInfo &Output, const InputInfoList &Inputs,
639                     const llvm::opt::ArgList &TCArgs,
640                     const char *LinkingOutput) const override;
641 };
642
643 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
644 public:
645   Linker(const ToolChain &TC) : GnuTool("dragonfly::Linker", "linker", TC) {}
646
647   bool hasIntegratedCPP() const override { return false; }
648   bool isLinkJob() const override { return true; }
649
650   void ConstructJob(Compilation &C, const JobAction &JA,
651                     const InputInfo &Output, const InputInfoList &Inputs,
652                     const llvm::opt::ArgList &TCArgs,
653                     const char *LinkingOutput) const override;
654 };
655 } // end namespace dragonfly
656
657 /// Visual studio tools.
658 namespace visualstudio {
659 VersionTuple getMSVCVersion(const Driver *D, const llvm::Triple &Triple,
660                             const llvm::opt::ArgList &Args, bool IsWindowsMSVC);
661
662 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
663 public:
664   Linker(const ToolChain &TC)
665       : Tool("visualstudio::Linker", "linker", TC, RF_Full,
666              llvm::sys::WEM_UTF16) {}
667
668   bool hasIntegratedCPP() const override { return false; }
669   bool isLinkJob() const override { return true; }
670
671   void ConstructJob(Compilation &C, const JobAction &JA,
672                     const InputInfo &Output, const InputInfoList &Inputs,
673                     const llvm::opt::ArgList &TCArgs,
674                     const char *LinkingOutput) const override;
675 };
676
677 class LLVM_LIBRARY_VISIBILITY Compiler : public Tool {
678 public:
679   Compiler(const ToolChain &TC)
680       : Tool("visualstudio::Compiler", "compiler", TC, RF_Full,
681              llvm::sys::WEM_UTF16) {}
682
683   bool hasIntegratedAssembler() const override { return true; }
684   bool hasIntegratedCPP() const override { return true; }
685   bool isLinkJob() const override { return false; }
686
687   void ConstructJob(Compilation &C, const JobAction &JA,
688                     const InputInfo &Output, const InputInfoList &Inputs,
689                     const llvm::opt::ArgList &TCArgs,
690                     const char *LinkingOutput) const override;
691
692   std::unique_ptr<Command> GetCommand(Compilation &C, const JobAction &JA,
693                                       const InputInfo &Output,
694                                       const InputInfoList &Inputs,
695                                       const llvm::opt::ArgList &TCArgs,
696                                       const char *LinkingOutput) const;
697 };
698 } // end namespace visualstudio
699
700 /// MinGW -- Directly call GNU Binutils assembler and linker
701 namespace MinGW {
702 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
703 public:
704   Assembler(const ToolChain &TC) : Tool("MinGW::Assemble", "assembler", TC) {}
705
706   bool hasIntegratedCPP() const override { return false; }
707
708   void ConstructJob(Compilation &C, const JobAction &JA,
709                     const InputInfo &Output, const InputInfoList &Inputs,
710                     const llvm::opt::ArgList &TCArgs,
711                     const char *LinkingOutput) const override;
712 };
713
714 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
715 public:
716   Linker(const ToolChain &TC) : Tool("MinGW::Linker", "linker", TC) {}
717
718   bool hasIntegratedCPP() const override { return false; }
719   bool isLinkJob() const override { return true; }
720
721   void ConstructJob(Compilation &C, const JobAction &JA,
722                     const InputInfo &Output, const InputInfoList &Inputs,
723                     const llvm::opt::ArgList &TCArgs,
724                     const char *LinkingOutput) const override;
725
726 private:
727   void AddLibGCC(const llvm::opt::ArgList &Args, ArgStringList &CmdArgs) const;
728 };
729 } // end namespace MinGW
730
731 namespace arm {
732 enum class FloatABI {
733   Invalid,
734   Soft,
735   SoftFP,
736   Hard,
737 };
738
739 FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args);
740 } // end namespace arm
741
742 namespace XCore {
743 // For XCore, we do not need to instantiate tools for PreProcess, PreCompile and
744 // Compile.
745 // We simply use "clang -cc1" for those actions.
746 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
747 public:
748   Assembler(const ToolChain &TC) : Tool("XCore::Assembler", "XCore-as", TC) {}
749
750   bool hasIntegratedCPP() const override { return false; }
751   void ConstructJob(Compilation &C, const JobAction &JA,
752                     const InputInfo &Output, const InputInfoList &Inputs,
753                     const llvm::opt::ArgList &TCArgs,
754                     const char *LinkingOutput) const override;
755 };
756
757 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
758 public:
759   Linker(const ToolChain &TC) : Tool("XCore::Linker", "XCore-ld", TC) {}
760
761   bool hasIntegratedCPP() const override { return false; }
762   bool isLinkJob() const override { return true; }
763   void ConstructJob(Compilation &C, const JobAction &JA,
764                     const InputInfo &Output, const InputInfoList &Inputs,
765                     const llvm::opt::ArgList &TCArgs,
766                     const char *LinkingOutput) const override;
767 };
768 } // end namespace XCore.
769
770 namespace CrossWindows {
771 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
772 public:
773   Assembler(const ToolChain &TC) : Tool("CrossWindows::Assembler", "as", TC) {}
774
775   bool hasIntegratedCPP() const override { return false; }
776
777   void ConstructJob(Compilation &C, const JobAction &JA,
778                     const InputInfo &Output, const InputInfoList &Inputs,
779                     const llvm::opt::ArgList &TCArgs,
780                     const char *LinkingOutput) const override;
781 };
782
783 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
784 public:
785   Linker(const ToolChain &TC)
786       : Tool("CrossWindows::Linker", "ld", TC, RF_Full) {}
787
788   bool hasIntegratedCPP() const override { return false; }
789   bool isLinkJob() const override { return true; }
790
791   void ConstructJob(Compilation &C, const JobAction &JA,
792                     const InputInfo &Output, const InputInfoList &Inputs,
793                     const llvm::opt::ArgList &TCArgs,
794                     const char *LinkingOutput) const override;
795 };
796 } // end namespace CrossWindows
797
798 /// SHAVE tools -- Directly call moviCompile and moviAsm
799 namespace SHAVE {
800 class LLVM_LIBRARY_VISIBILITY Compiler : public Tool {
801 public:
802   Compiler(const ToolChain &TC) : Tool("moviCompile", "movicompile", TC) {}
803
804   bool hasIntegratedCPP() const override { return true; }
805
806   void ConstructJob(Compilation &C, const JobAction &JA,
807                     const InputInfo &Output, const InputInfoList &Inputs,
808                     const llvm::opt::ArgList &TCArgs,
809                     const char *LinkingOutput) const override;
810 };
811
812 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
813 public:
814   Assembler(const ToolChain &TC) : Tool("moviAsm", "moviAsm", TC) {}
815
816   bool hasIntegratedCPP() const override { return false; } // not sure.
817
818   void ConstructJob(Compilation &C, const JobAction &JA,
819                     const InputInfo &Output, const InputInfoList &Inputs,
820                     const llvm::opt::ArgList &TCArgs,
821                     const char *LinkingOutput) const override;
822 };
823 } // end namespace SHAVE
824
825 /// The Myriad toolchain uses tools that are in two different namespaces.
826 /// The Compiler and Assembler as defined above are in the SHAVE namespace,
827 /// whereas the linker, which accepts code for a mixture of Sparc and SHAVE,
828 /// is in the Myriad namespace.
829 namespace Myriad {
830 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
831 public:
832   Linker(const ToolChain &TC) : GnuTool("shave::Linker", "ld", TC) {}
833   bool hasIntegratedCPP() const override { return false; }
834   bool isLinkJob() const override { return true; }
835   void ConstructJob(Compilation &C, const JobAction &JA,
836                     const InputInfo &Output, const InputInfoList &Inputs,
837                     const llvm::opt::ArgList &TCArgs,
838                     const char *LinkingOutput) const override;
839 };
840 } // end namespace Myriad
841
842 namespace PS4cpu {
843 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
844 public:
845   Assemble(const ToolChain &TC)
846       : Tool("PS4cpu::Assemble", "assembler", TC, RF_Full) {}
847
848   bool hasIntegratedCPP() const override { return false; }
849
850   void ConstructJob(Compilation &C, const JobAction &JA,
851                     const InputInfo &Output,
852                     const InputInfoList &Inputs,
853                     const llvm::opt::ArgList &TCArgs,
854                     const char *LinkingOutput) const override;
855 };
856
857 class LLVM_LIBRARY_VISIBILITY Link : public Tool {
858 public:
859   Link(const ToolChain &TC) : Tool("PS4cpu::Link", "linker", TC, RF_Full) {}
860
861   bool hasIntegratedCPP() const override { return false; }
862   bool isLinkJob() const override { return true; }
863
864   void ConstructJob(Compilation &C, const JobAction &JA,
865                     const InputInfo &Output,
866                     const InputInfoList &Inputs,
867                     const llvm::opt::ArgList &TCArgs,
868                     const char *LinkingOutput) const override;
869 };
870 } // end namespace PS4cpu
871
872 } // end namespace tools
873 } // end namespace driver
874 } // end namespace clang
875
876 #endif // LLVM_CLANG_LIB_DRIVER_TOOLS_H