clang 17.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"
13#include "clang/Driver/Driver.h"
14#include "clang/Driver/Tool.h"
15#include "clang/Driver/Types.h"
16#include "llvm/Frontend/Debug/Options.h"
17#include "llvm/Option/Option.h"
18#include "llvm/Support/raw_ostream.h"
19#include "llvm/TargetParser/Triple.h"
20
21namespace clang {
22class ObjCRuntime;
23namespace driver {
24
25namespace tools {
26
27/// Clang compiler tool.
28class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
29 // Indicates whether this instance has integrated backend using
30 // internal LLVM infrastructure.
31 bool HasBackend;
32
33public:
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
41private:
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 AddLoongArchTargetArgs(const llvm::opt::ArgList &Args,
61 llvm::opt::ArgStringList &CmdArgs) const;
62 void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
63 llvm::opt::ArgStringList &CmdArgs) const;
64 void AddPPCTargetArgs(const llvm::opt::ArgList &Args,
65 llvm::opt::ArgStringList &CmdArgs) const;
66 void AddR600TargetArgs(const llvm::opt::ArgList &Args,
67 llvm::opt::ArgStringList &CmdArgs) const;
68 void AddRISCVTargetArgs(const llvm::opt::ArgList &Args,
69 llvm::opt::ArgStringList &CmdArgs) const;
70 void AddSparcTargetArgs(const llvm::opt::ArgList &Args,
71 llvm::opt::ArgStringList &CmdArgs) const;
72 void AddSystemZTargetArgs(const llvm::opt::ArgList &Args,
73 llvm::opt::ArgStringList &CmdArgs) const;
74 void AddX86TargetArgs(const llvm::opt::ArgList &Args,
75 llvm::opt::ArgStringList &CmdArgs) const;
76 void AddHexagonTargetArgs(const llvm::opt::ArgList &Args,
77 llvm::opt::ArgStringList &CmdArgs) const;
78 void AddLanaiTargetArgs(const llvm::opt::ArgList &Args,
79 llvm::opt::ArgStringList &CmdArgs) const;
80 void AddWebAssemblyTargetArgs(const llvm::opt::ArgList &Args,
81 llvm::opt::ArgStringList &CmdArgs) const;
82 void AddVETargetArgs(const llvm::opt::ArgList &Args,
83 llvm::opt::ArgStringList &CmdArgs) const;
84
85 enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile };
86
87 ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args,
88 const InputInfoList &inputs,
89 llvm::opt::ArgStringList &cmdArgs,
90 RewriteKind rewrite) const;
91
92 void AddClangCLArgs(const llvm::opt::ArgList &Args, types::ID InputType,
93 llvm::opt::ArgStringList &CmdArgs,
94 llvm::codegenoptions::DebugInfoKind *DebugInfoKind,
95 bool *EmitCodeView) const;
96
97 mutable std::unique_ptr<llvm::raw_fd_ostream> CompilationDatabase = nullptr;
98 void DumpCompilationDatabase(Compilation &C, StringRef Filename,
99 StringRef Target,
100 const InputInfo &Output, const InputInfo &Input,
101 const llvm::opt::ArgList &Args) const;
102
103 void DumpCompilationDatabaseFragmentToDir(
104 StringRef Dir, Compilation &C, StringRef Target, const InputInfo &Output,
105 const InputInfo &Input, const llvm::opt::ArgList &Args) const;
106
107public:
108 Clang(const ToolChain &TC, bool HasIntegratedBackend = true);
109 ~Clang() override;
110
111 bool hasGoodDiagnostics() const override { return true; }
112 bool hasIntegratedAssembler() const override { return true; }
113 bool hasIntegratedBackend() const override { return HasBackend; }
114 bool hasIntegratedCPP() const override { return true; }
115 bool canEmitIR() const override { return true; }
116
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
123/// Clang integrated assembler tool.
124class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
125public:
127 : Tool("clang::as", "clang integrated assembler", TC) {}
128 void AddLoongArchTargetArgs(const llvm::opt::ArgList &Args,
129 llvm::opt::ArgStringList &CmdArgs) const;
130 void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
131 llvm::opt::ArgStringList &CmdArgs) const;
132 void AddX86TargetArgs(const llvm::opt::ArgList &Args,
133 llvm::opt::ArgStringList &CmdArgs) const;
134 void AddRISCVTargetArgs(const llvm::opt::ArgList &Args,
135 llvm::opt::ArgStringList &CmdArgs) const;
136 bool hasGoodDiagnostics() const override { return true; }
137 bool hasIntegratedAssembler() const override { return false; }
138 bool hasIntegratedCPP() const override { return false; }
139
140 void ConstructJob(Compilation &C, const JobAction &JA,
141 const InputInfo &Output, const InputInfoList &Inputs,
142 const llvm::opt::ArgList &TCArgs,
143 const char *LinkingOutput) const override;
144};
145
146/// Offload bundler tool.
147class LLVM_LIBRARY_VISIBILITY OffloadBundler final : public Tool {
148public:
150 : Tool("offload bundler", "clang-offload-bundler", TC) {}
151
152 bool hasIntegratedCPP() const override { return false; }
153 void ConstructJob(Compilation &C, const JobAction &JA,
154 const InputInfo &Output, const InputInfoList &Inputs,
155 const llvm::opt::ArgList &TCArgs,
156 const char *LinkingOutput) const override;
157 void ConstructJobMultipleOutputs(Compilation &C, const JobAction &JA,
158 const InputInfoList &Outputs,
159 const InputInfoList &Inputs,
160 const llvm::opt::ArgList &TCArgs,
161 const char *LinkingOutput) const override;
162};
163
164/// Offload binary tool.
165class LLVM_LIBRARY_VISIBILITY OffloadPackager final : public Tool {
166public:
168 : Tool("Offload::Packager", "clang-offload-packager", TC) {}
169
170 bool hasIntegratedCPP() const override { return false; }
171 void ConstructJob(Compilation &C, const JobAction &JA,
172 const InputInfo &Output, const InputInfoList &Inputs,
173 const llvm::opt::ArgList &TCArgs,
174 const char *LinkingOutput) const override;
175};
176
177/// Linker wrapper tool.
178class LLVM_LIBRARY_VISIBILITY LinkerWrapper final : public Tool {
179 const Tool *Linker;
180
181public:
182 LinkerWrapper(const ToolChain &TC, const Tool *Linker)
183 : Tool("Offload::Linker", "linker", TC), Linker(Linker) {}
184
185 bool hasIntegratedCPP() const override { return false; }
186 void ConstructJob(Compilation &C, const JobAction &JA,
187 const InputInfo &Output, const InputInfoList &Inputs,
188 const llvm::opt::ArgList &TCArgs,
189 const char *LinkingOutput) const override;
190};
191
193
195 const llvm::opt::ArgList &Args,
196 llvm::opt::Arg *&Arg);
197
198} // end namespace tools
199
200} // end namespace driver
201} // end namespace clang
202
203#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CLANG_H
StringRef Filename
Definition: Format.cpp:2792
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
Clang integrated assembler tool.
Definition: Clang.h:124
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Clang.h:136
bool hasIntegratedCPP() const override
Definition: Clang.h:138
ClangAs(const ToolChain &TC)
Definition: Clang.h:126
bool hasIntegratedAssembler() const override
Definition: Clang.h:137
Clang compiler tool.
Definition: Clang.h:28
bool hasIntegratedBackend() const override
Definition: Clang.h:113
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Clang.h:111
bool canEmitIR() const override
Definition: Clang.h:115
bool hasIntegratedCPP() const override
Definition: Clang.h:114
bool hasIntegratedAssembler() const override
Definition: Clang.h:112
Linker wrapper tool.
Definition: Clang.h:178
bool hasIntegratedCPP() const override
Definition: Clang.h:185
LinkerWrapper(const ToolChain &TC, const Tool *Linker)
Definition: Clang.h:182
Offload bundler tool.
Definition: Clang.h:147
bool hasIntegratedCPP() const override
Definition: Clang.h:152
OffloadBundler(const ToolChain &TC)
Definition: Clang.h:149
Offload binary tool.
Definition: Clang.h:165
OffloadPackager(const ToolChain &TC)
Definition: Clang.h:167
bool hasIntegratedCPP() const override
Definition: Clang.h:170
DwarfFissionKind getDebugFissionKind(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::Arg *&Arg)