clang  14.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 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,
89  bool *EmitCodeView) const;
90 
91  mutable std::unique_ptr<llvm::raw_fd_ostream> CompilationDatabase = nullptr;
92  void DumpCompilationDatabase(Compilation &C, StringRef Filename,
93  StringRef Target,
94  const InputInfo &Output, const InputInfo &Input,
95  const llvm::opt::ArgList &Args) const;
96 
97  void DumpCompilationDatabaseFragmentToDir(
98  StringRef Dir, Compilation &C, StringRef Target, const InputInfo &Output,
99  const InputInfo &Input, const llvm::opt::ArgList &Args) const;
100 
101 public:
102  Clang(const ToolChain &TC);
103  ~Clang() override;
104 
105  bool hasGoodDiagnostics() const override { return true; }
106  bool hasIntegratedAssembler() const override { return true; }
107  bool hasIntegratedCPP() const override { return true; }
108  bool canEmitIR() const override { return true; }
109 
110  void ConstructJob(Compilation &C, const JobAction &JA,
111  const InputInfo &Output, const InputInfoList &Inputs,
112  const llvm::opt::ArgList &TCArgs,
113  const char *LinkingOutput) const override;
114 };
115 
116 /// Clang integrated assembler tool.
117 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
118 public:
119  ClangAs(const ToolChain &TC)
120  : Tool("clang::as", "clang integrated assembler", TC) {}
121  void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
122  llvm::opt::ArgStringList &CmdArgs) const;
123  void AddX86TargetArgs(const llvm::opt::ArgList &Args,
124  llvm::opt::ArgStringList &CmdArgs) const;
125  void AddRISCVTargetArgs(const llvm::opt::ArgList &Args,
126  llvm::opt::ArgStringList &CmdArgs) const;
127  bool hasGoodDiagnostics() const override { return true; }
128  bool hasIntegratedAssembler() const override { return false; }
129  bool hasIntegratedCPP() const override { return false; }
130 
131  void ConstructJob(Compilation &C, const JobAction &JA,
132  const InputInfo &Output, const InputInfoList &Inputs,
133  const llvm::opt::ArgList &TCArgs,
134  const char *LinkingOutput) const override;
135 };
136 
137 /// Offload bundler tool.
138 class LLVM_LIBRARY_VISIBILITY OffloadBundler final : public Tool {
139 public:
141  : Tool("offload bundler", "clang-offload-bundler", TC) {}
142 
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  void ConstructJobMultipleOutputs(Compilation &C, const JobAction &JA,
149  const InputInfoList &Outputs,
150  const InputInfoList &Inputs,
151  const llvm::opt::ArgList &TCArgs,
152  const char *LinkingOutput) const override;
153 };
154 
155 /// Offload wrapper tool.
156 class LLVM_LIBRARY_VISIBILITY OffloadWrapper final : public Tool {
157 public:
159  : Tool("offload wrapper", "clang-offload-wrapper", 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 } // end namespace tools
169 
170 } // end namespace driver
171 } // end namespace clang
172 
173 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CLANG_H
clang::driver::tools::OffloadBundler::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:143
clang::driver::tools::OffloadWrapper::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:161
clang::driver::tools::OffloadBundler::OffloadBundler
OffloadBundler(const ToolChain &TC)
Definition: Clang.h:140
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:105
llvm::SmallVector
Definition: LLVM.h:38
clang::MultiVersionKind::Target
@ Target
clang::driver::tools::ClangAs::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:129
Filename
StringRef Filename
Definition: Format.cpp:2379
clang::driver::tools::OffloadWrapper::OffloadWrapper
OffloadWrapper(const ToolChain &TC)
Definition: Clang.h:158
clang::driver::tools::ClangAs
Clang integrated assembler tool.
Definition: Clang.h:117
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::OffloadWrapper
Offload wrapper tool.
Definition: Clang.h:156
Tool.h
clang::driver::tools::Clang::canEmitIR
bool canEmitIR() const override
Definition: Clang.h:108
clang::driver::tools::Clang
Clang compiler tool.
Definition: Clang.h:28
clang::driver::tools::ClangAs::ClangAs
ClangAs(const ToolChain &TC)
Definition: Clang.h:119
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:127
clang::driver::tools::ClangAs::hasIntegratedAssembler
bool hasIntegratedAssembler() const override
Definition: Clang.h:128
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
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:138
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:59
DebugInfoOptions.h
clang::codegenoptions::DebugInfoKind
DebugInfoKind
Definition: DebugInfoOptions.h:20
Types.h
clang::driver::tools::Clang::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Clang.h:107
clang::driver::JobAction
Definition: Action.h:380
clang::driver::tools::Clang::hasIntegratedAssembler
bool hasIntegratedAssembler() const override
Definition: Clang.h:106