xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/MinGW.h (revision 85868e8a1daeaae7a0e48effb2ea2310ae3b02c6)
1 //===--- MinGW.h - MinGW ToolChain Implementations --------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MINGW_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MINGW_H
11 
12 #include "Cuda.h"
13 #include "Gnu.h"
14 #include "clang/Driver/Tool.h"
15 #include "clang/Driver/ToolChain.h"
16 
17 namespace clang {
18 namespace driver {
19 namespace tools {
20 
21 /// MinGW -- Directly call GNU Binutils assembler and linker
22 namespace MinGW {
23 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
24 public:
25   Assembler(const ToolChain &TC) : Tool("MinGW::Assemble", "assembler", TC) {}
26 
27   bool hasIntegratedCPP() const override { return false; }
28 
29   void ConstructJob(Compilation &C, const JobAction &JA,
30                     const InputInfo &Output, const InputInfoList &Inputs,
31                     const llvm::opt::ArgList &TCArgs,
32                     const char *LinkingOutput) const override;
33 };
34 
35 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
36 public:
37   Linker(const ToolChain &TC)
38       : Tool("MinGW::Linker", "linker", TC, Tool::RF_Full) {}
39 
40   bool hasIntegratedCPP() const override { return false; }
41   bool isLinkJob() const override { return true; }
42 
43   void ConstructJob(Compilation &C, const JobAction &JA,
44                     const InputInfo &Output, const InputInfoList &Inputs,
45                     const llvm::opt::ArgList &TCArgs,
46                     const char *LinkingOutput) const override;
47 
48 private:
49   void AddLibGCC(const llvm::opt::ArgList &Args,
50                  llvm::opt::ArgStringList &CmdArgs) const;
51 };
52 } // end namespace MinGW
53 } // end namespace tools
54 
55 namespace toolchains {
56 
57 class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain {
58 public:
59   MinGW(const Driver &D, const llvm::Triple &Triple,
60         const llvm::opt::ArgList &Args);
61 
62   bool HasNativeLLVMSupport() const override;
63 
64   bool IsIntegratedAssemblerDefault() const override;
65   bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
66   bool isPICDefault() const override;
67   bool isPIEDefault() const override;
68   bool isPICDefaultForced() const override;
69 
70   SanitizerMask getSupportedSanitizers() const override;
71 
72   llvm::ExceptionHandling GetExceptionModel(
73       const llvm::opt::ArgList &Args) const override;
74 
75   void
76   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
77                             llvm::opt::ArgStringList &CC1Args) const override;
78   void AddClangCXXStdlibIncludeArgs(
79       const llvm::opt::ArgList &DriverArgs,
80       llvm::opt::ArgStringList &CC1Args) const override;
81 
82   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
83                           llvm::opt::ArgStringList &CC1Args) const override;
84 
85   void printVerboseInfo(raw_ostream &OS) const override;
86 
87 protected:
88   Tool *getTool(Action::ActionClass AC) const override;
89   Tool *buildLinker() const override;
90   Tool *buildAssembler() const override;
91 
92 private:
93   CudaInstallationDetector CudaInstallation;
94 
95   std::string Base;
96   std::string GccLibDir;
97   std::string Ver;
98   std::string Arch;
99   mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocessor;
100   mutable std::unique_ptr<tools::gcc::Compiler> Compiler;
101   void findGccLibDir();
102   llvm::ErrorOr<std::string> findGcc();
103   llvm::ErrorOr<std::string> findClangRelativeSysroot();
104 
105   bool NativeLLVMSupport;
106 };
107 
108 } // end namespace toolchains
109 } // end namespace driver
110 } // end namespace clang
111 
112 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MINGW_H
113