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