clang 24.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 AddAMDGPUTargetArgs(const llvm::opt::ArgList &Args,
55 llvm::opt::ArgStringList &CmdArgs) const;
56 void AddARMTargetArgs(const llvm::Triple &Triple,
57 const llvm::opt::ArgList &Args,
58 llvm::opt::ArgStringList &CmdArgs,
59 bool KernelOrKext) 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 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) const;
92
93 mutable std::unique_ptr<llvm::raw_fd_ostream> CompilationDatabase = nullptr;
94 void DumpCompilationDatabase(Compilation &C, StringRef Filename,
95 StringRef Target,
96 const InputInfo &Output, const InputInfo &Input,
97 const llvm::opt::ArgList &Args) const;
98
99 void DumpCompilationDatabaseFragmentToDir(
100 StringRef Dir, Compilation &C, StringRef Target, const InputInfo &Output,
101 const InputInfo &Input, const llvm::opt::ArgList &Args) const;
102
103public:
104 Clang(const ToolChain &TC, bool HasIntegratedBackend = true);
105 ~Clang() override;
106
107 bool hasGoodDiagnostics() const override { return true; }
108 bool hasIntegratedAssembler() const override { return true; }
109 bool hasIntegratedBackend() const override { return HasBackend; }
110 bool hasIntegratedCPP() const override { return true; }
111 bool canEmitIR() const override { return true; }
112
113 void ConstructJob(Compilation &C, const JobAction &JA,
114 const InputInfo &Output, const InputInfoList &Inputs,
115 const llvm::opt::ArgList &TCArgs,
116 const char *LinkingOutput) const override;
117};
118
119/// Clang integrated assembler tool.
120class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
121public:
123 : Tool("clang::as", "clang integrated assembler", TC) {}
124 void AddLoongArchTargetArgs(const llvm::opt::ArgList &Args,
125 llvm::opt::ArgStringList &CmdArgs) const;
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.
143class LLVM_LIBRARY_VISIBILITY OffloadBundler final : public Tool {
144public:
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};
154
155/// Offload binary tool.
156class LLVM_LIBRARY_VISIBILITY OffloadPackager final : public Tool {
157public:
159 : Tool("Offload::Packager", "llvm-offload-binary", TC) {}
160
161 bool hasIntegratedCPP() const override { return false; }
162 void ConstructJob(Compilation &C, const JobAction &JA,
163 const InputInfo &Output, const InputInfoList &Inputs,
164 const llvm::opt::ArgList &TCArgs,
165 const char *LinkingOutput) const override;
166};
167
168/// Linker wrapper tool.
169class LLVM_LIBRARY_VISIBILITY LinkerWrapper final : public Tool {
170 const Tool *Linker;
171
172public:
173 LinkerWrapper(const ToolChain &TC, const Tool *Linker)
174 : Tool("Offload::Linker", "linker", TC), Linker(Linker) {}
175
176 bool hasIntegratedCPP() const override { return false; }
177 void ConstructJob(Compilation &C, const JobAction &JA,
178 const InputInfo &Output, const InputInfoList &Inputs,
179 const llvm::opt::ArgList &TCArgs,
180 const char *LinkingOutput) const override;
181};
182
183// Calculate the output path of the module file when compiling a module unit
184// with the `-fmodule-output` option or `-fmodule-output=` option specified.
185// The behavior is:
186// - If `-fmodule-output=` is specfied, then the module file is
187// writing to the value.
188// - Otherwise if the output object file of the module unit is specified, the
189// output path
190// of the module file should be the same with the output object file except
191// the corresponding suffix. This requires both `-o` and `-c` are specified.
192// - Otherwise, the output path of the module file will be the same with the
193// input with the corresponding suffix.
195getCXX20NamedModuleOutputPath(const llvm::opt::ArgList &Args,
196 const char *BaseInput);
197
198} // end namespace tools
199
200} // end namespace driver
201} // end namespace clang
202
203#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CLANG_H
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:46
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:93
InputInfo - Wrapper for information about an input source.
Definition InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:92
Tool(const char *Name, const char *ShortName, const ToolChain &TC)
Definition Tool.cpp:13
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition Clang.h:132
bool hasIntegratedCPP() const override
Definition Clang.h:134
ClangAs(const ToolChain &TC)
Definition Clang.h:122
bool hasIntegratedAssembler() const override
Definition Clang.h:133
static const char * getBaseInputName(const llvm::opt::ArgList &Args, const InputInfo &Input)
Definition Clang.cpp:9243
Clang(const ToolChain &TC, bool HasIntegratedBackend=true)
Definition Clang.cpp:8731
static const char * getDependencyFileName(const llvm::opt::ArgList &Args, const InputInfoList &Inputs)
Definition Clang.cpp:9258
static const char * getBaseInputStem(const llvm::opt::ArgList &Args, const InputInfoList &Inputs)
Definition Clang.cpp:9248
bool hasIntegratedBackend() const override
Definition Clang.h:109
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition Clang.h:107
bool canEmitIR() const override
Definition Clang.h:111
bool hasIntegratedCPP() const override
Definition Clang.h:110
bool hasIntegratedAssembler() const override
Definition Clang.h:108
bool hasIntegratedCPP() const override
Definition Clang.h:176
LinkerWrapper(const ToolChain &TC, const Tool *Linker)
Definition Clang.h:173
bool hasIntegratedCPP() const override
Definition Clang.h:148
OffloadBundler(const ToolChain &TC)
Definition Clang.h:145
OffloadPackager(const ToolChain &TC)
Definition Clang.h:158
bool hasIntegratedCPP() const override
Definition Clang.h:161
llvm::SmallString< 256 > getCXX20NamedModuleOutputPath(const llvm::opt::ArgList &Args, const char *BaseInput)
SmallVector< InputInfo, 4 > InputInfoList
Definition Driver.h:49
Top level wrappers for InstallAPI frontend operations.