Clang.h 8.5 KB

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