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