1 //===--- Clang.h - Clang Tool and 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_Clang_H 10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_Clang_H 11 12 #include "MSVC.h" 13 #include "clang/Basic/DebugInfoOptions.h" 14 #include "clang/Driver/Driver.h" 15 #include "clang/Driver/Tool.h" 16 #include "clang/Driver/Types.h" 17 #include "llvm/ADT/Triple.h" 18 #include "llvm/Option/Option.h" 19 #include "llvm/Support/raw_ostream.h" 20 21 namespace clang { 22 class ObjCRuntime; 23 namespace driver { 24 25 namespace tools { 26 27 /// Clang compiler tool. 28 class LLVM_LIBRARY_VISIBILITY Clang : public Tool { 29 public: 30 static const char *getBaseInputName(const llvm::opt::ArgList &Args, 31 const InputInfo &Input); 32 static const char *getBaseInputStem(const llvm::opt::ArgList &Args, 33 const InputInfoList &Inputs); 34 static const char *getDependencyFileName(const llvm::opt::ArgList &Args, 35 const InputInfoList &Inputs); 36 37 private: 38 void AddPreprocessingOptions(Compilation &C, const JobAction &JA, 39 const Driver &D, const llvm::opt::ArgList &Args, 40 llvm::opt::ArgStringList &CmdArgs, 41 const InputInfo &Output, 42 const InputInfoList &Inputs) const; 43 44 void RenderTargetOptions(const llvm::Triple &EffectiveTriple, 45 const llvm::opt::ArgList &Args, bool KernelOrKext, 46 llvm::opt::ArgStringList &CmdArgs) const; 47 48 void AddAArch64TargetArgs(const llvm::opt::ArgList &Args, 49 llvm::opt::ArgStringList &CmdArgs) const; 50 void AddARMTargetArgs(const llvm::Triple &Triple, 51 const llvm::opt::ArgList &Args, 52 llvm::opt::ArgStringList &CmdArgs, 53 bool KernelOrKext) const; 54 void AddARM64TargetArgs(const llvm::opt::ArgList &Args, 55 llvm::opt::ArgStringList &CmdArgs) const; 56 void AddMIPSTargetArgs(const llvm::opt::ArgList &Args, 57 llvm::opt::ArgStringList &CmdArgs) const; 58 void AddPPCTargetArgs(const llvm::opt::ArgList &Args, 59 llvm::opt::ArgStringList &CmdArgs) const; 60 void AddR600TargetArgs(const llvm::opt::ArgList &Args, 61 llvm::opt::ArgStringList &CmdArgs) const; 62 void AddRISCVTargetArgs(const llvm::opt::ArgList &Args, 63 llvm::opt::ArgStringList &CmdArgs) const; 64 void AddSparcTargetArgs(const llvm::opt::ArgList &Args, 65 llvm::opt::ArgStringList &CmdArgs) const; 66 void AddSystemZTargetArgs(const llvm::opt::ArgList &Args, 67 llvm::opt::ArgStringList &CmdArgs) const; 68 void AddX86TargetArgs(const llvm::opt::ArgList &Args, 69 llvm::opt::ArgStringList &CmdArgs) const; 70 void AddHexagonTargetArgs(const llvm::opt::ArgList &Args, 71 llvm::opt::ArgStringList &CmdArgs) const; 72 void AddLanaiTargetArgs(const llvm::opt::ArgList &Args, 73 llvm::opt::ArgStringList &CmdArgs) const; 74 void AddWebAssemblyTargetArgs(const llvm::opt::ArgList &Args, 75 llvm::opt::ArgStringList &CmdArgs) const; 76 void AddVETargetArgs(const llvm::opt::ArgList &Args, 77 llvm::opt::ArgStringList &CmdArgs) const; 78 79 enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile }; 80 81 ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args, 82 const InputInfoList &inputs, 83 llvm::opt::ArgStringList &cmdArgs, 84 RewriteKind rewrite) const; 85 86 void AddClangCLArgs(const llvm::opt::ArgList &Args, types::ID InputType, 87 llvm::opt::ArgStringList &CmdArgs, 88 codegenoptions::DebugInfoKind *DebugInfoKind, 89 bool *EmitCodeView) const; 90 91 visualstudio::Compiler *getCLFallback() const; 92 93 mutable std::unique_ptr<visualstudio::Compiler> CLFallback; 94 95 mutable std::unique_ptr<llvm::raw_fd_ostream> CompilationDatabase = nullptr; 96 void DumpCompilationDatabase(Compilation &C, StringRef Filename, 97 StringRef Target, 98 const InputInfo &Output, const InputInfo &Input, 99 const llvm::opt::ArgList &Args) const; 100 101 void DumpCompilationDatabaseFragmentToDir( 102 StringRef Dir, Compilation &C, StringRef Target, const InputInfo &Output, 103 const InputInfo &Input, const llvm::opt::ArgList &Args) const; 104 105 public: 106 Clang(const ToolChain &TC); 107 ~Clang() override; 108 109 bool hasGoodDiagnostics() const override { return true; } 110 bool hasIntegratedAssembler() const override { return true; } 111 bool hasIntegratedCPP() const override { return true; } 112 bool canEmitIR() const override { return true; } 113 114 void ConstructJob(Compilation &C, const JobAction &JA, 115 const InputInfo &Output, const InputInfoList &Inputs, 116 const llvm::opt::ArgList &TCArgs, 117 const char *LinkingOutput) const override; 118 }; 119 120 /// Clang integrated assembler tool. 121 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool { 122 public: 123 ClangAs(const ToolChain &TC) 124 : Tool("clang::as", "clang integrated assembler", TC) {} 125 void AddMIPSTargetArgs(const llvm::opt::ArgList &Args, 126 llvm::opt::ArgStringList &CmdArgs) const; 127 void AddX86TargetArgs(const llvm::opt::ArgList &Args, 128 llvm::opt::ArgStringList &CmdArgs) const; 129 void AddRISCVTargetArgs(const llvm::opt::ArgList &Args, 130 llvm::opt::ArgStringList &CmdArgs) const; 131 bool hasGoodDiagnostics() const override { return true; } 132 bool hasIntegratedAssembler() const override { return false; } 133 bool hasIntegratedCPP() const override { return false; } 134 135 void ConstructJob(Compilation &C, const JobAction &JA, 136 const InputInfo &Output, const InputInfoList &Inputs, 137 const llvm::opt::ArgList &TCArgs, 138 const char *LinkingOutput) const override; 139 }; 140 141 /// Offload bundler tool. 142 class LLVM_LIBRARY_VISIBILITY OffloadBundler final : public Tool { 143 public: 144 OffloadBundler(const ToolChain &TC) 145 : Tool("offload bundler", "clang-offload-bundler", TC) {} 146 147 bool hasIntegratedCPP() const override { return false; } 148 void ConstructJob(Compilation &C, const JobAction &JA, 149 const InputInfo &Output, const InputInfoList &Inputs, 150 const llvm::opt::ArgList &TCArgs, 151 const char *LinkingOutput) const override; 152 void ConstructJobMultipleOutputs(Compilation &C, const JobAction &JA, 153 const InputInfoList &Outputs, 154 const InputInfoList &Inputs, 155 const llvm::opt::ArgList &TCArgs, 156 const char *LinkingOutput) const override; 157 }; 158 159 /// Offload wrapper tool. 160 class LLVM_LIBRARY_VISIBILITY OffloadWrapper final : public Tool { 161 public: 162 OffloadWrapper(const ToolChain &TC) 163 : Tool("offload wrapper", "clang-offload-wrapper", TC) {} 164 165 bool hasIntegratedCPP() const override { return false; } 166 void ConstructJob(Compilation &C, const JobAction &JA, 167 const InputInfo &Output, const InputInfoList &Inputs, 168 const llvm::opt::ArgList &TCArgs, 169 const char *LinkingOutput) const override; 170 }; 171 172 } // end namespace tools 173 174 } // end namespace driver 175 } // end namespace clang 176 177 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CLANG_H 178