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