clang  15.0.0git
Clang.h
Go to the documentation of this file.
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"
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  // Indicates whether this instance has integrated backend using
30  // internal LLVM infrastructure.
31  bool HasBackend;
32 
33 public:
34  static const char *getBaseInputName(const llvm::opt::ArgList &Args,
35  const InputInfo &Input);
36  static const char *getBaseInputStem(const llvm::opt::ArgList &Args,
37  const InputInfoList &Inputs);
38  static const char *getDependencyFileName(const llvm::opt::ArgList &Args,
39  const InputInfoList &Inputs);
40 
41 private:
42  void AddPreprocessingOptions(Compilation &C, const JobAction &JA,
43  const Driver &D, const llvm::opt::ArgList &Args,
44  llvm::opt::ArgStringList &CmdArgs,
45  const InputInfo &Output,
46  const InputInfoList &Inputs) const;
47 
48  void RenderTargetOptions(const llvm::Triple &EffectiveTriple,
49  const llvm::opt::ArgList &Args, bool KernelOrKext,
50  llvm::opt::ArgStringList &CmdArgs) const;
51 
52  void AddAArch64TargetArgs(const llvm::opt::ArgList &Args,
53  llvm::opt::ArgStringList &CmdArgs) const;
54  void AddARMTargetArgs(const llvm::Triple &Triple,
55  const llvm::opt::ArgList &Args,
56  llvm::opt::ArgStringList &CmdArgs,
57  bool KernelOrKext) const;
58  void AddARM64TargetArgs(const llvm::opt::ArgList &Args,
59  llvm::opt::ArgStringList &CmdArgs) const;
60  void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
61  llvm::opt::ArgStringList &CmdArgs) const;
62  void AddPPCTargetArgs(const llvm::opt::ArgList &Args,
63  llvm::opt::ArgStringList &CmdArgs) const;
64  void AddR600TargetArgs(const llvm::opt::ArgList &Args,
65  llvm::opt::ArgStringList &CmdArgs) const;
66  void AddRISCVTargetArgs(const llvm::opt::ArgList &Args,
67  llvm::opt::ArgStringList &CmdArgs) const;
68  void AddSparcTargetArgs(const llvm::opt::ArgList &Args,
69  llvm::opt::ArgStringList &CmdArgs) const;
70  void AddSystemZTargetArgs(const llvm::opt::ArgList &Args,
71  llvm::opt::ArgStringList &CmdArgs) const;
72  void AddX86TargetArgs(const llvm::opt::ArgList &Args,
73  llvm::opt::ArgStringList &CmdArgs) const;
74  void AddHexagonTargetArgs(const llvm::opt::ArgList &Args,
75  llvm::opt::ArgStringList &CmdArgs) const;
76  void AddLanaiTargetArgs(const llvm::opt::ArgList &Args,
77  llvm::opt::ArgStringList &CmdArgs) const;
78  void AddWebAssemblyTargetArgs(const llvm::opt::ArgList &Args,
79  llvm::opt::ArgStringList &CmdArgs) const;
80  void AddVETargetArgs(const llvm::opt::ArgList &Args,
81  llvm::opt::ArgStringList &CmdArgs) const;
82 
83  enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile };
84 
85  ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args,
86  const InputInfoList &inputs,
87  llvm::opt::ArgStringList &cmdArgs,
88  RewriteKind rewrite) const;
89 
90  void AddClangCLArgs(const llvm::opt::ArgList &Args, types::ID InputType,
91  llvm::opt::ArgStringList &CmdArgs,
93  bool *EmitCodeView) const;
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, bool HasIntegratedBackend = true);
107  ~Clang() override;
108 
109  bool hasGoodDiagnostics() const override { return true; }
110  bool hasIntegratedAssembler() const override { return true; }
111  bool hasIntegratedBackend() const override { return HasBackend; }
112  bool hasIntegratedCPP() const override { return true; }
113  bool canEmitIR() const override { return true; }
114 
115  void ConstructJob(Compilation &C, const JobAction &JA,
116  const InputInfo &Output, const InputInfoList &Inputs,
117  const llvm::opt::ArgList &TCArgs,
118  const char *LinkingOutput) const override;
119 };
120 
121 /// Clang integrated assembler tool.
122 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
123 public:
124  ClangAs(const ToolChain &TC)
125  : Tool("clang::as", "clang integrated assembler", TC) {}
126  void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
127  llvm::opt::ArgStringList &CmdArgs) const;
128  void AddX86TargetArgs(const llvm::opt::ArgList &Args,
129  llvm::opt::ArgStringList &CmdArgs) const;
130  void AddRISCVTargetArgs(const llvm::opt::ArgList &Args,
131  llvm::opt::ArgStringList &CmdArgs) const;
132  bool hasGoodDiagnostics() const override { return true; }
133  bool hasIntegratedAssembler() const override { return false; }
134  bool hasIntegratedCPP() const override { return false; }
135 
136  void ConstructJob(Compilation &C, const JobAction &JA,
137  const InputInfo &Output, const InputInfoList &Inputs,
138  const llvm::opt::ArgList &TCArgs,
139  const char *LinkingOutput) const override;
140 };
141 
142 /// Offload bundler tool.
143 class LLVM_LIBRARY_VISIBILITY OffloadBundler final : public Tool {
144 public:
146  : Tool("offload bundler", "clang-offload-bundler", TC) {}
147 
148  bool hasIntegratedCPP() const override { return false; }
149  void ConstructJob(Compilation &C, const JobAction &JA,
150  const InputInfo &Output, const InputInfoList &Inputs,
151  const llvm::opt::ArgList &TCArgs,
152  const char *LinkingOutput) const override;
153  void ConstructJobMultipleOutputs(Compilation &C, const JobAction &JA,
154  const InputInfoList &Outputs,
155  const InputInfoList &Inputs,
156  const llvm::opt::ArgList &TCArgs,
157  const char *LinkingOutput) const override;
158 };
159 
160 /// Offload wrapper tool.
161 class LLVM_LIBRARY_VISIBILITY OffloadWrapper final : public Tool {
162 public:
164  : Tool("offload wrapper", "clang-offload-wrapper", TC) {}
165 
166  bool hasIntegratedCPP() const override { return false; }
167  void ConstructJob(Compilation &C, const JobAction &JA,
168  const InputInfo &Output, const InputInfoList &Inputs,
169  const llvm::opt::ArgList &TCArgs,
170  const char *LinkingOutput) const override;
171 };
172 
173 /// Offload binary tool.
174 class LLVM_LIBRARY_VISIBILITY OffloadPackager final : public Tool {
175 public:
177  : Tool("Offload::Packager", "clang-offload-packager", TC) {}
178 
179  bool hasIntegratedCPP() const override { return false; }
180  void ConstructJob(Compilation &C, const JobAction &JA,
181  const InputInfo &Output, const InputInfoList &Inputs,
182  const llvm::opt::ArgList &TCArgs,
183  const char *LinkingOutput) const override;
184 };
185 
186 /// Linker wrapper tool.
187 class LLVM_LIBRARY_VISIBILITY LinkerWrapper final : public Tool {
188  const Tool *Linker;
189 
190 public:
191  LinkerWrapper(const ToolChain &TC, const Tool *Linker)
192  : Tool("Offload::Linker", "linker", TC), Linker(Linker) {}
193 
194  bool hasIntegratedCPP() const override { return false; }
195  void ConstructJob(Compilation &C, const JobAction &JA,
196  const InputInfo &Output, const InputInfoList &Inputs,
197  const llvm::opt::ArgList &TCArgs,
198  const char *LinkingOutput) const override;
199 };
200 
201 } // end namespace tools
202 
203 } // end namespace driver
204 } // end namespace clang
205 
206 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CLANG_H
clang::driver::tools::OffloadPackager
Offload binary tool.
Definition: Clang.h:174
clang::driver::tools::OffloadBundler::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:148
clang::driver::tools::OffloadWrapper::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:166
clang::driver::tools::OffloadBundler::OffloadBundler
OffloadBundler(const ToolChain &TC)
Definition: Clang.h:145
Driver.h
clang::driver::tools::Clang::hasGoodDiagnostics
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Clang.h:109
llvm::SmallVector
Definition: LLVM.h:38
clang::MultiVersionKind::Target
@ Target
clang::driver::tools::ClangAs::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:134
Filename
StringRef Filename
Definition: Format.cpp:2551
clang::driver::tools::OffloadWrapper::OffloadWrapper
OffloadWrapper(const ToolChain &TC)
Definition: Clang.h:163
clang::driver::tools::ClangAs
Clang integrated assembler tool.
Definition: Clang.h:122
clang::driver::tools::LinkerWrapper
Linker wrapper tool.
Definition: Clang.h:187
clang::driver::tools::Clang::hasIntegratedBackend
bool hasIntegratedBackend() const override
Definition: Clang.h:111
MSVC.h
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
clang::driver::tools::LinkerWrapper::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:194
clang::driver::tools::OffloadPackager::OffloadPackager
OffloadPackager(const ToolChain &TC)
Definition: Clang.h:176
clang::driver::tools::OffloadWrapper
Offload wrapper tool.
Definition: Clang.h:161
Tool.h
clang::driver::tools::Clang::canEmitIR
bool canEmitIR() const override
Definition: Clang.h:113
clang::driver::tools::Clang
Clang compiler tool.
Definition: Clang.h:28
clang::driver::tools::ClangAs::ClangAs
ClangAs(const ToolChain &TC)
Definition: Clang.h:124
clang::driver::tools::ClangAs::hasGoodDiagnostics
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Clang.h:132
clang::driver::tools::ClangAs::hasIntegratedAssembler
bool hasIntegratedAssembler() const override
Definition: Clang.h:133
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
clang::driver::tools::LinkerWrapper::LinkerWrapper
LinkerWrapper(const ToolChain &TC, const Tool *Linker)
Definition: Clang.h:191
clang::driver::types::ID
ID
Definition: Types.h:23
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
clang::driver::tools::OffloadBundler
Offload bundler tool.
Definition: Clang.h:143
clang::ObjCRuntime
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
clang
Definition: CalledOnceCheck.h:17
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:71
DebugInfoOptions.h
clang::codegenoptions::DebugInfoKind
DebugInfoKind
Definition: DebugInfoOptions.h:20
Types.h
clang::driver::tools::OffloadPackager::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:179
clang::driver::tools::Clang::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:112
clang::driver::JobAction
Definition: Action.h:395
clang::driver::tools::Clang::hasIntegratedAssembler
bool hasIntegratedAssembler() const override
Definition: Clang.h:110