]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Driver/ToolChains.h
MFV r225523, r282431:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Driver / ToolChains.h
1 //===--- ToolChains.h - ToolChain 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_TOOLCHAINS_H
11 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
12
13 #include "Tools.h"
14 #include "clang/Basic/VersionTuple.h"
15 #include "clang/Driver/Action.h"
16 #include "clang/Driver/Multilib.h"
17 #include "clang/Driver/ToolChain.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/Support/Compiler.h"
21 #include <set>
22 #include <vector>
23
24 namespace clang {
25 namespace driver {
26 namespace toolchains {
27
28 /// Generic_GCC - A tool chain using the 'gcc' command to perform
29 /// all subcommands; this relies on gcc translating the majority of
30 /// command line options.
31 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
32 protected:
33   /// \brief Struct to store and manipulate GCC versions.
34   ///
35   /// We rely on assumptions about the form and structure of GCC version
36   /// numbers: they consist of at most three '.'-separated components, and each
37   /// component is a non-negative integer except for the last component. For
38   /// the last component we are very flexible in order to tolerate release
39   /// candidates or 'x' wildcards.
40   ///
41   /// Note that the ordering established among GCCVersions is based on the
42   /// preferred version string to use. For example we prefer versions without
43   /// a hard-coded patch number to those with a hard coded patch number.
44   ///
45   /// Currently this doesn't provide any logic for textual suffixes to patches
46   /// in the way that (for example) Debian's version format does. If that ever
47   /// becomes necessary, it can be added.
48   struct GCCVersion {
49     /// \brief The unparsed text of the version.
50     std::string Text;
51
52     /// \brief The parsed major, minor, and patch numbers.
53     int Major, Minor, Patch;
54
55     /// \brief The text of the parsed major, and major+minor versions.
56     std::string MajorStr, MinorStr;
57
58     /// \brief Any textual suffix on the patch number.
59     std::string PatchSuffix;
60
61     static GCCVersion Parse(StringRef VersionText);
62     bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch,
63                      StringRef RHSPatchSuffix = StringRef()) const;
64     bool operator<(const GCCVersion &RHS) const {
65       return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix);
66     }
67     bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
68     bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
69     bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
70   };
71
72   /// \brief This is a class to find a viable GCC installation for Clang to
73   /// use.
74   ///
75   /// This class tries to find a GCC installation on the system, and report
76   /// information about it. It starts from the host information provided to the
77   /// Driver, and has logic for fuzzing that where appropriate.
78   class GCCInstallationDetector {
79     bool IsValid;
80     llvm::Triple GCCTriple;
81
82     // FIXME: These might be better as path objects.
83     std::string GCCInstallPath;
84     std::string GCCParentLibPath;
85
86     /// The primary multilib appropriate for the given flags.
87     Multilib SelectedMultilib;
88     /// On Biarch systems, this corresponds to the default multilib when
89     /// targeting the non-default multilib. Otherwise, it is empty.
90     llvm::Optional<Multilib> BiarchSibling;
91
92     GCCVersion Version;
93
94     // We retain the list of install paths that were considered and rejected in
95     // order to print out detailed information in verbose mode.
96     std::set<std::string> CandidateGCCInstallPaths;
97
98     /// The set of multilibs that the detected installation supports.
99     MultilibSet Multilibs;
100
101   public:
102     GCCInstallationDetector() : IsValid(false) {}
103     void init(const Driver &D, const llvm::Triple &TargetTriple,
104                             const llvm::opt::ArgList &Args);
105
106     /// \brief Check whether we detected a valid GCC install.
107     bool isValid() const { return IsValid; }
108
109     /// \brief Get the GCC triple for the detected install.
110     const llvm::Triple &getTriple() const { return GCCTriple; }
111
112     /// \brief Get the detected GCC installation path.
113     StringRef getInstallPath() const { return GCCInstallPath; }
114
115     /// \brief Get the detected GCC parent lib path.
116     StringRef getParentLibPath() const { return GCCParentLibPath; }
117
118     /// \brief Get the detected Multilib
119     const Multilib &getMultilib() const { return SelectedMultilib; }
120
121     /// \brief Get the whole MultilibSet
122     const MultilibSet &getMultilibs() const { return Multilibs; }
123
124     /// Get the biarch sibling multilib (if it exists).
125     /// \return true iff such a sibling exists
126     bool getBiarchSibling(Multilib &M) const;
127
128     /// \brief Get the detected GCC version string.
129     const GCCVersion &getVersion() const { return Version; }
130
131     /// \brief Print information about the detected GCC installation.
132     void print(raw_ostream &OS) const;
133
134   private:
135     static void
136     CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
137                              const llvm::Triple &BiarchTriple,
138                              SmallVectorImpl<StringRef> &LibDirs,
139                              SmallVectorImpl<StringRef> &TripleAliases,
140                              SmallVectorImpl<StringRef> &BiarchLibDirs,
141                              SmallVectorImpl<StringRef> &BiarchTripleAliases);
142
143     void ScanLibDirForGCCTriple(const llvm::Triple &TargetArch,
144                                 const llvm::opt::ArgList &Args,
145                                 const std::string &LibDir,
146                                 StringRef CandidateTriple,
147                                 bool NeedsBiarchSuffix = false);
148   };
149
150   GCCInstallationDetector GCCInstallation;
151
152 public:
153   Generic_GCC(const Driver &D, const llvm::Triple &Triple,
154               const llvm::opt::ArgList &Args);
155   ~Generic_GCC();
156
157   void printVerboseInfo(raw_ostream &OS) const override;
158
159   bool IsUnwindTablesDefault() const override;
160   bool isPICDefault() const override;
161   bool isPIEDefault() const override;
162   bool isPICDefaultForced() const override;
163   bool IsIntegratedAssemblerDefault() const override;
164
165 protected:
166   Tool *getTool(Action::ActionClass AC) const override;
167   Tool *buildAssembler() const override;
168   Tool *buildLinker() const override;
169
170   /// \name ToolChain Implementation Helper Functions
171   /// @{
172
173   /// \brief Check whether the target triple's architecture is 64-bits.
174   bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
175
176   /// \brief Check whether the target triple's architecture is 32-bits.
177   bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
178
179   /// @}
180
181 private:
182   mutable std::unique_ptr<tools::gcc::Preprocess> Preprocess;
183   mutable std::unique_ptr<tools::gcc::Compile> Compile;
184 };
185
186 class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
187 protected:
188   Tool *buildAssembler() const override;
189   Tool *buildLinker() const override;
190   Tool *getTool(Action::ActionClass AC) const override;
191 private:
192   mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
193   mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;
194   mutable std::unique_ptr<tools::darwin::VerifyDebug> VerifyDebug;
195
196 public:
197   MachO(const Driver &D, const llvm::Triple &Triple,
198              const llvm::opt::ArgList &Args);
199   ~MachO();
200
201   /// @name MachO specific toolchain API
202   /// {
203
204   /// Get the "MachO" arch name for a particular compiler invocation. For
205   /// example, Apple treats different ARM variations as distinct architectures.
206   StringRef getMachOArchName(const llvm::opt::ArgList &Args) const;
207
208
209   /// Add the linker arguments to link the ARC runtime library.
210   virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
211                               llvm::opt::ArgStringList &CmdArgs) const {}
212
213   /// Add the linker arguments to link the compiler runtime library.
214   virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
215                                      llvm::opt::ArgStringList &CmdArgs) const;
216
217   virtual void
218   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
219                          llvm::opt::ArgStringList &CmdArgs) const {}
220
221   virtual void addMinVersionArgs(const llvm::opt::ArgList &Args,
222                                  llvm::opt::ArgStringList &CmdArgs) const {}
223
224   /// On some iOS platforms, kernel and kernel modules were built statically. Is
225   /// this such a target?
226   virtual bool isKernelStatic() const {
227     return false;
228   }
229
230   /// Is the target either iOS or an iOS simulator?
231   bool isTargetIOSBased() const {
232     return false;
233   }
234
235   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
236                          llvm::opt::ArgStringList &CmdArgs,
237                          StringRef DarwinLibName,
238                          bool AlwaysLink = false,
239                          bool IsEmbedded = false,
240                          bool AddRPath = false) const;
241
242   /// }
243   /// @name ToolChain Implementation
244   /// {
245
246   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
247                                           types::ID InputType) const override;
248
249   types::ID LookupTypeForExtension(const char *Ext) const override;
250
251   bool HasNativeLLVMSupport() const override;
252
253   llvm::opt::DerivedArgList *
254   TranslateArgs(const llvm::opt::DerivedArgList &Args,
255                 const char *BoundArch) const override;
256
257   bool IsBlocksDefault() const override {
258     // Always allow blocks on Apple; users interested in versioning are
259     // expected to use /usr/include/Block.h.
260     return true;
261   }
262   bool IsIntegratedAssemblerDefault() const override {
263     // Default integrated assembler to on for Apple's MachO targets.
264     return true;
265   }
266
267   bool IsMathErrnoDefault() const override {
268     return false;
269   }
270
271   bool IsEncodeExtendedBlockSignatureDefault() const override {
272     return true;
273   }
274
275   bool IsObjCNonFragileABIDefault() const override {
276     // Non-fragile ABI is default for everything but i386.
277     return getTriple().getArch() != llvm::Triple::x86;
278   }
279
280   bool UseObjCMixedDispatch() const override {
281     return true;
282   }
283
284   bool IsUnwindTablesDefault() const override;
285
286   RuntimeLibType GetDefaultRuntimeLibType() const override {
287     return ToolChain::RLT_CompilerRT;
288   }
289
290   bool isPICDefault() const override;
291   bool isPIEDefault() const override;
292   bool isPICDefaultForced() const override;
293
294   bool SupportsProfiling() const override;
295
296   bool SupportsObjCGC() const override {
297     return false;
298   }
299
300   bool UseDwarfDebugFlags() const override;
301
302   bool UseSjLjExceptions() const override {
303     return false;
304   }
305
306   /// }
307 };
308
309   /// Darwin - The base Darwin tool chain.
310 class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
311 public:
312   /// The host version.
313   unsigned DarwinVersion[3];
314
315   /// Whether the information on the target has been initialized.
316   //
317   // FIXME: This should be eliminated. What we want to do is make this part of
318   // the "default target for arguments" selection process, once we get out of
319   // the argument translation business.
320   mutable bool TargetInitialized;
321
322   enum DarwinPlatformKind {
323     MacOS,
324     IPhoneOS,
325     IPhoneOSSimulator
326   };
327
328   mutable DarwinPlatformKind TargetPlatform;
329
330   /// The OS version we are targeting.
331   mutable VersionTuple TargetVersion;
332
333 private:
334   /// The default macosx-version-min of this tool chain; empty until
335   /// initialized.
336   std::string MacosxVersionMin;
337
338   /// The default ios-version-min of this tool chain; empty until
339   /// initialized.
340   std::string iOSVersionMin;
341
342 private:
343   void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
344
345 public:
346   Darwin(const Driver &D, const llvm::Triple &Triple,
347          const llvm::opt::ArgList &Args);
348   ~Darwin();
349
350   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
351                                           types::ID InputType) const override;
352
353   /// @name Apple Specific Toolchain Implementation
354   /// {
355
356   void
357   addMinVersionArgs(const llvm::opt::ArgList &Args,
358                     llvm::opt::ArgStringList &CmdArgs) const override;
359
360   void
361   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
362                          llvm::opt::ArgStringList &CmdArgs) const override;
363
364   bool isKernelStatic() const override {
365     return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0) ||
366            getTriple().getArch() == llvm::Triple::aarch64;
367   }
368
369 protected:
370   /// }
371   /// @name Darwin specific Toolchain functions
372   /// {
373
374   // FIXME: Eliminate these ...Target functions and derive separate tool chains
375   // for these targets and put version in constructor.
376   void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
377                  unsigned Micro) const {
378     // FIXME: For now, allow reinitialization as long as values don't
379     // change. This will go away when we move away from argument translation.
380     if (TargetInitialized && TargetPlatform == Platform &&
381         TargetVersion == VersionTuple(Major, Minor, Micro))
382       return;
383
384     assert(!TargetInitialized && "Target already initialized!");
385     TargetInitialized = true;
386     TargetPlatform = Platform;
387     TargetVersion = VersionTuple(Major, Minor, Micro);
388   }
389
390   bool isTargetIPhoneOS() const {
391     assert(TargetInitialized && "Target not initialized!");
392     return TargetPlatform == IPhoneOS;
393   }
394
395   bool isTargetIOSSimulator() const {
396     assert(TargetInitialized && "Target not initialized!");
397     return TargetPlatform == IPhoneOSSimulator;
398   }
399
400   bool isTargetIOSBased() const {
401     assert(TargetInitialized && "Target not initialized!");
402     return isTargetIPhoneOS() || isTargetIOSSimulator();
403   }
404
405   bool isTargetMacOS() const {
406     return TargetPlatform == MacOS;
407   }
408
409   bool isTargetInitialized() const { return TargetInitialized; }
410
411   VersionTuple getTargetVersion() const {
412     assert(TargetInitialized && "Target not initialized!");
413     return TargetVersion;
414   }
415
416   bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
417     assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
418     return TargetVersion < VersionTuple(V0, V1, V2);
419   }
420
421   bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
422     assert(isTargetMacOS() && "Unexpected call for non OS X target!");
423     return TargetVersion < VersionTuple(V0, V1, V2);
424   }
425
426 public:
427   /// }
428   /// @name ToolChain Implementation
429   /// {
430
431   // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
432   // most development is done against SDKs, so compiling for a different
433   // architecture should not get any special treatment.
434   bool isCrossCompiling() const override { return false; }
435
436   llvm::opt::DerivedArgList *
437   TranslateArgs(const llvm::opt::DerivedArgList &Args,
438                 const char *BoundArch) const override;
439
440   ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
441   bool hasBlocksRuntime() const override;
442
443   bool UseObjCMixedDispatch() const override {
444     // This is only used with the non-fragile ABI and non-legacy dispatch.
445
446     // Mixed dispatch is used everywhere except OS X before 10.6.
447     return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
448   }
449
450   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
451     // Stack protectors default to on for user code on 10.5,
452     // and for everything in 10.6 and beyond
453     if (isTargetIOSBased())
454       return 1;
455     else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
456       return 1;
457     else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
458       return 1;
459
460     return 0;
461   }
462
463   bool SupportsObjCGC() const override;
464
465   void CheckObjCARC() const override;
466
467   bool UseSjLjExceptions() const override;
468 };
469
470 /// DarwinClang - The Darwin toolchain used by Clang.
471 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
472 public:
473   DarwinClang(const Driver &D, const llvm::Triple &Triple,
474               const llvm::opt::ArgList &Args);
475
476   /// @name Apple ToolChain Implementation
477   /// {
478
479   void
480   AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
481                         llvm::opt::ArgStringList &CmdArgs) const override;
482
483   void
484   AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
485                       llvm::opt::ArgStringList &CmdArgs) const override;
486
487   void
488   AddCCKextLibArgs(const llvm::opt::ArgList &Args,
489                    llvm::opt::ArgStringList &CmdArgs) const override;
490
491   virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args)
492                                                       const override;
493
494   void
495   AddLinkARCArgs(const llvm::opt::ArgList &Args,
496                  llvm::opt::ArgStringList &CmdArgs) const override;
497   /// }
498 };
499
500 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
501   virtual void anchor();
502 public:
503   Generic_ELF(const Driver &D, const llvm::Triple &Triple,
504               const llvm::opt::ArgList &Args)
505       : Generic_GCC(D, Triple, Args) {}
506
507   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
508                              llvm::opt::ArgStringList &CC1Args) const override;
509 };
510
511 class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
512 public:
513   Solaris(const Driver &D, const llvm::Triple &Triple,
514           const llvm::opt::ArgList &Args);
515
516   bool IsIntegratedAssemblerDefault() const override { return true; }
517 protected:
518   Tool *buildAssembler() const override;
519   Tool *buildLinker() const override;
520
521 };
522
523
524 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
525 public:
526   OpenBSD(const Driver &D, const llvm::Triple &Triple,
527           const llvm::opt::ArgList &Args);
528
529   bool IsMathErrnoDefault() const override { return false; }
530   bool IsObjCNonFragileABIDefault() const override { return true; }
531   bool isPIEDefault() const override { return true; }
532
533   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
534     return 2;
535   }
536
537 protected:
538   Tool *buildAssembler() const override;
539   Tool *buildLinker() const override;
540 };
541
542 class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
543 public:
544   Bitrig(const Driver &D, const llvm::Triple &Triple,
545          const llvm::opt::ArgList &Args);
546
547   bool IsMathErrnoDefault() const override { return false; }
548   bool IsObjCNonFragileABIDefault() const override { return true; }
549
550   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
551   void
552   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
553                               llvm::opt::ArgStringList &CC1Args) const override;
554   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
555                            llvm::opt::ArgStringList &CmdArgs) const override;
556   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
557      return 1;
558   }
559
560 protected:
561   Tool *buildAssembler() const override;
562   Tool *buildLinker() const override;
563 };
564
565 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
566 public:
567   FreeBSD(const Driver &D, const llvm::Triple &Triple,
568           const llvm::opt::ArgList &Args);
569   bool HasNativeLLVMSupport() const override;
570
571   bool IsMathErrnoDefault() const override { return false; }
572   bool IsObjCNonFragileABIDefault() const override { return true; }
573
574   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
575   void
576   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
577                                llvm::opt::ArgStringList &CC1Args) const override;
578
579   bool UseSjLjExceptions() const override;
580   bool isPIEDefault() const override;
581 protected:
582   Tool *buildAssembler() const override;
583   Tool *buildLinker() const override;
584 };
585
586 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
587 public:
588   NetBSD(const Driver &D, const llvm::Triple &Triple,
589          const llvm::opt::ArgList &Args);
590
591   bool IsMathErrnoDefault() const override { return false; }
592   bool IsObjCNonFragileABIDefault() const override { return true; }
593
594   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
595
596   void
597   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
598                               llvm::opt::ArgStringList &CC1Args) const override;
599   bool IsUnwindTablesDefault() const override {
600     return true;
601   }
602
603 protected:
604   Tool *buildAssembler() const override;
605   Tool *buildLinker() const override;
606 };
607
608 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
609 public:
610   Minix(const Driver &D, const llvm::Triple &Triple,
611         const llvm::opt::ArgList &Args);
612
613 protected:
614   Tool *buildAssembler() const override;
615   Tool *buildLinker() const override;
616 };
617
618 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
619 public:
620   DragonFly(const Driver &D, const llvm::Triple &Triple,
621             const llvm::opt::ArgList &Args);
622
623   bool IsMathErrnoDefault() const override { return false; }
624
625 protected:
626   Tool *buildAssembler() const override;
627   Tool *buildLinker() const override;
628 };
629
630 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
631 public:
632   Linux(const Driver &D, const llvm::Triple &Triple,
633         const llvm::opt::ArgList &Args);
634
635   bool HasNativeLLVMSupport() const override;
636
637   void
638   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
639                             llvm::opt::ArgStringList &CC1Args) const override;
640   void
641   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
642                                llvm::opt::ArgStringList &CC1Args) const override;
643   bool isPIEDefault() const override;
644
645   std::string Linker;
646   std::vector<std::string> ExtraOpts;
647
648 protected:
649   Tool *buildAssembler() const override;
650   Tool *buildLinker() const override;
651
652 private:
653   static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
654                                        StringRef GCCTriple,
655                                        StringRef GCCMultiarchTriple,
656                                        StringRef TargetMultiarchTriple,
657                                        Twine IncludeSuffix,
658                                        const llvm::opt::ArgList &DriverArgs,
659                                        llvm::opt::ArgStringList &CC1Args);
660
661   std::string computeSysRoot() const;
662 };
663
664 class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
665 protected:
666   GCCVersion GCCLibAndIncVersion;
667   Tool *buildAssembler() const override;
668   Tool *buildLinker() const override;
669
670 public:
671   Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
672              const llvm::opt::ArgList &Args);
673   ~Hexagon_TC();
674
675   void
676   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
677                             llvm::opt::ArgStringList &CC1Args) const override;
678   void
679   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
680                               llvm::opt::ArgStringList &CC1Args) const override;
681   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
682
683   StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
684
685   static std::string GetGnuDir(const std::string &InstalledDir,
686                                const llvm::opt::ArgList &Args);
687
688   static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
689 };
690
691 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
692 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
693 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
694 public:
695   TCEToolChain(const Driver &D, const llvm::Triple &Triple,
696                const llvm::opt::ArgList &Args);
697   ~TCEToolChain();
698
699   bool IsMathErrnoDefault() const override;
700   bool isPICDefault() const override;
701   bool isPIEDefault() const override;
702   bool isPICDefaultForced() const override;
703 };
704
705 class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
706 public:
707   MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
708                 const llvm::opt::ArgList &Args);
709
710   bool IsIntegratedAssemblerDefault() const override;
711   bool IsUnwindTablesDefault() const override;
712   bool isPICDefault() const override;
713   bool isPIEDefault() const override;
714   bool isPICDefaultForced() const override;
715
716   void
717   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
718                             llvm::opt::ArgStringList &CC1Args) const override;
719   void
720   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
721                                llvm::opt::ArgStringList &CC1Args) const override;
722
723   bool getWindowsSDKDir(std::string &path, int &major, int &minor) const;
724   bool getWindowsSDKLibraryPath(std::string &path) const;
725   bool getVisualStudioInstallDir(std::string &path) const;
726   bool getVisualStudioBinariesFolder(const char *clangProgramPath,
727                                      std::string &path) const;
728
729 protected:
730   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
731                                      llvm::opt::ArgStringList &CC1Args,
732                                      const std::string &folder,
733                                      const char *subfolder) const;
734
735   Tool *buildLinker() const override;
736   Tool *buildAssembler() const override;
737 };
738
739 class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
740 public:
741   CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
742                         const llvm::opt::ArgList &Args);
743
744   bool IsIntegratedAssemblerDefault() const override { return true; }
745   bool IsUnwindTablesDefault() const override;
746   bool isPICDefault() const override;
747   bool isPIEDefault() const override;
748   bool isPICDefaultForced() const override;
749
750   unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
751     return 0;
752   }
753
754   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
755                                  llvm::opt::ArgStringList &CC1Args)
756       const override;
757   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
758                                     llvm::opt::ArgStringList &CC1Args)
759       const override;
760   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
761                            llvm::opt::ArgStringList &CmdArgs) const override;
762
763 protected:
764   Tool *buildLinker() const override;
765   Tool *buildAssembler() const override;
766 };
767
768 class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
769 public:
770   XCore(const Driver &D, const llvm::Triple &Triple,
771           const llvm::opt::ArgList &Args);
772 protected:
773   Tool *buildAssembler() const override;
774   Tool *buildLinker() const override;
775 public:
776   bool isPICDefault() const override;
777   bool isPIEDefault() const override;
778   bool isPICDefaultForced() const override;
779   bool SupportsProfiling() const override;
780   bool hasBlocksRuntime() const override;
781   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
782                     llvm::opt::ArgStringList &CC1Args) const override;
783   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
784                              llvm::opt::ArgStringList &CC1Args) const override;
785   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
786                        llvm::opt::ArgStringList &CC1Args) const override;
787   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
788                            llvm::opt::ArgStringList &CmdArgs) const override;
789 };
790
791 } // end namespace toolchains
792 } // end namespace driver
793 } // end namespace clang
794
795 #endif