clang 18.0.0git
FrontendOptions.h
Go to the documentation of this file.
1//===- FrontendOptions.h ----------------------------------------*- 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_FRONTEND_FRONTENDOPTIONS_H
10#define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
11
17#include "llvm/ADT/StringRef.h"
18#include "llvm/Support/MemoryBuffer.h"
19#include <cassert>
20#include <map>
21#include <memory>
22#include <optional>
23#include <string>
24#include <vector>
25
26namespace llvm {
27
28class MemoryBuffer;
29
30} // namespace llvm
31
32namespace clang {
33
34namespace frontend {
35
37 /// Parse ASTs and list Decl nodes.
39
40 /// Parse ASTs and dump them.
42
43 /// Parse ASTs and print them.
45
46 /// Parse ASTs and view them in Graphviz.
48
49 /// Dump the compiler configuration.
51
52 /// Dump out raw tokens.
54
55 /// Dump out preprocessed tokens.
57
58 /// Emit a .s file.
60
61 /// Emit a .bc file.
63
64 /// Translate input source into HTML.
66
67 /// Emit a .ll file.
69
70 /// Generate LLVM IR, but do not emit anything.
72
73 /// Generate machine code, but don't emit anything.
75
76 /// Emit a .o file.
78
79 // Extract API information
81
82 /// Parse and apply any fixits to the source.
84
85 /// Generate pre-compiled module from a module map.
87
88 /// Generate pre-compiled module from a C++ module interface file.
90
91 /// Generate a C++20 header unit module from a header file.
93
94 /// Generate pre-compiled header.
96
97 /// Generate Interface Stub Files.
99
100 /// Only execute frontend initialization.
102
103 /// Dump information about a module file.
105
106 /// Load and verify that a PCH file is usable.
108
109 /// Parse and perform semantic analysis.
111
112 /// Run a plugin action, \see ActionName.
114
115 /// Print the "preamble" of the input file
117
118 /// -E mode.
120
121 /// Expand macros but not \#includes.
123
124 /// ObjC->C Rewriter.
126
127 /// Rewriter playground
129
130 /// Run one or more source code analyses.
132
133 /// Dump template instantiations
135
136 /// Run migrator.
138
139 /// Just lex, no output.
141
142 /// Print the output of the dependency directives source minimizer.
145
146} // namespace frontend
147
148/// The kind of a file that we've been handed as an input.
150private:
151 Language Lang;
152 unsigned Fmt : 3;
153 unsigned Preprocessed : 1;
154 unsigned HeaderUnit : 3;
155 unsigned IsHeader : 1;
156
157public:
158 /// The input file format.
159 enum Format {
163 };
164
165 // If we are building a header unit, what kind it is; this affects whether
166 // we look for the file in the user or system include search paths before
167 // flagging a missing input.
173 };
174
176 bool PP = false, HeaderUnitKind HU = HeaderUnit_None,
177 bool HD = false)
178 : Lang(L), Fmt(F), Preprocessed(PP), HeaderUnit(HU), IsHeader(HD) {}
179
180 Language getLanguage() const { return static_cast<Language>(Lang); }
181 Format getFormat() const { return static_cast<Format>(Fmt); }
183 return static_cast<HeaderUnitKind>(HeaderUnit);
184 }
185 bool isPreprocessed() const { return Preprocessed; }
186 bool isHeader() const { return IsHeader; }
187 bool isHeaderUnit() const { return HeaderUnit != HeaderUnit_None; }
188
189 /// Is the input kind fully-unknown?
190 bool isUnknown() const { return Lang == Language::Unknown && Fmt == Source; }
191
192 /// Is the language of the input some dialect of Objective-C?
193 bool isObjectiveC() const {
194 return Lang == Language::ObjC || Lang == Language::ObjCXX;
195 }
196
199 isHeader());
200 }
201
204 getHeaderUnitKind(), true);
205 }
206
209 isHeader());
210 }
211
214 isHeader());
215 }
216};
217
218/// An input file for the front end.
220 /// The file name, or "-" to read from standard input.
221 std::string File;
222
223 /// The input, if it comes from a buffer rather than a file. This object
224 /// does not own the buffer, and the caller is responsible for ensuring
225 /// that it outlives any users.
226 std::optional<llvm::MemoryBufferRef> Buffer;
227
228 /// The kind of input, e.g., C source, AST file, LLVM IR.
229 InputKind Kind;
230
231 /// Whether we're dealing with a 'system' input (vs. a 'user' input).
232 bool IsSystem = false;
233
234public:
235 FrontendInputFile() = default;
236 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
237 : File(File.str()), Kind(Kind), IsSystem(IsSystem) {}
238 FrontendInputFile(llvm::MemoryBufferRef Buffer, InputKind Kind,
239 bool IsSystem = false)
240 : Buffer(Buffer), Kind(Kind), IsSystem(IsSystem) {}
241
242 InputKind getKind() const { return Kind; }
243 bool isSystem() const { return IsSystem; }
244
245 bool isEmpty() const { return File.empty() && Buffer == std::nullopt; }
246 bool isFile() const { return !isBuffer(); }
247 bool isBuffer() const { return Buffer != std::nullopt; }
248 bool isPreprocessed() const { return Kind.isPreprocessed(); }
249 bool isHeader() const { return Kind.isHeader(); }
251 return Kind.getHeaderUnitKind();
252 }
253
254 StringRef getFile() const {
255 assert(isFile());
256 return File;
257 }
258
259 llvm::MemoryBufferRef getBuffer() const {
260 assert(isBuffer());
261 return *Buffer;
262 }
263};
264
265/// FrontendOptions - Options for controlling the behavior of the frontend.
267public:
268 /// Disable memory freeing on exit.
269 unsigned DisableFree : 1;
270
271 /// When generating PCH files, instruct the AST writer to create relocatable
272 /// PCH files.
273 unsigned RelocatablePCH : 1;
274
275 /// Show the -help text.
276 unsigned ShowHelp : 1;
277
278 /// Show frontend performance metrics and statistics.
279 unsigned ShowStats : 1;
280
281 unsigned AppendStats : 1;
282
283 /// print the supported cpus for the current target
284 unsigned PrintSupportedCPUs : 1;
285
286 /// Print the supported extensions for the current target.
288
289 /// Show the -version text.
290 unsigned ShowVersion : 1;
291
292 /// Apply fixes even if there are unfixable errors.
293 unsigned FixWhatYouCan : 1;
294
295 /// Apply fixes only for warnings.
296 unsigned FixOnlyWarnings : 1;
297
298 /// Apply fixes and recompile.
299 unsigned FixAndRecompile : 1;
300
301 /// Apply fixes to temporary files.
302 unsigned FixToTemporaries : 1;
303
304 /// Emit ARC errors even if the migrator can fix them.
306
307 /// Skip over function bodies to speed up parsing in cases you do not need
308 /// them (e.g. with code completion).
309 unsigned SkipFunctionBodies : 1;
310
311 /// Whether we can use the global module index if available.
313
314 /// Whether we can generate the global module index if needed.
316
317 /// Whether we include declaration dumps in AST dumps.
318 unsigned ASTDumpDecls : 1;
319
320 /// Whether we deserialize all decls when forming AST dumps.
321 unsigned ASTDumpAll : 1;
322
323 /// Whether we include lookup table dumps in AST dumps.
324 unsigned ASTDumpLookups : 1;
325
326 /// Whether we include declaration type dumps in AST dumps.
327 unsigned ASTDumpDeclTypes : 1;
328
329 /// Whether we are performing an implicit module build.
331
332 /// Whether to use a filesystem lock when building implicit modules.
334
335 /// Whether we should embed all used files into the PCM file.
337
338 /// Whether timestamps should be written to the produced PCH file.
339 unsigned IncludeTimestamps : 1;
340
341 /// Should a temporary file be used during compilation.
342 unsigned UseTemporary : 1;
343
344 /// When using -emit-module, treat the modulemap as a system module.
345 unsigned IsSystemModule : 1;
346
347 /// Output (and read) PCM files regardless of compiler errors.
349
350 /// Whether to share the FileManager when building modules.
352
354
355 /// Specifies the output format of the AST.
357
358 enum {
364
365 enum {
367
368 /// Enable migration to modern ObjC literals.
370
371 /// Enable migration to modern ObjC subscripting.
373
374 /// Enable migration to modern ObjC readonly property.
376
377 /// Enable migration to modern ObjC readwrite property.
379
380 /// Enable migration to modern ObjC property.
382
383 /// Enable annotation of ObjCMethods of all kinds.
385
386 /// Enable migration of ObjC methods to 'instancetype'.
388
389 /// Enable migration to NS_ENUM/NS_OPTIONS macros.
391
392 /// Enable migration to add conforming protocols.
394
395 /// prefer 'atomic' property over 'nonatomic'.
397
398 /// annotate property with NS_RETURNS_INNER_POINTER
400
401 /// use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
403
404 /// Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
406
407 /// Enable converting setter/getter expressions to property-dot syntx.
409
417 };
420
421 std::string MTMigrateDir;
423
424 /// The input kind, either specified via -x argument or deduced from the input
425 /// file name.
427
428 /// The input files and their types.
430
431 /// When the input is a module map, the original module map file from which
432 /// that map was inferred, if any (for umbrella modules).
433 std::string OriginalModuleMap;
434
435 /// The output file, if any.
436 std::string OutputFile;
437
438 /// If given, the new suffix for fix-it rewritten files.
439 std::string FixItSuffix;
440
441 /// If given, filter dumped AST Decl nodes by this substring.
442 std::string ASTDumpFilter;
443
444 /// If given, enable code completion at the provided location.
446
447 /// The frontend action to perform.
449
450 /// The name of the action to run when using a plugin action.
451 std::string ActionName;
452
453 // Currently this is only used as part of the `-extract-api` action.
454 /// The name of the product the input files belong too.
455 std::string ProductName;
456
457 // Currently this is only used as part of the `-extract-api` action.
458 // A comma seperated list of files providing a list of APIs to
459 // ignore when extracting documentation.
460 std::vector<std::string> ExtractAPIIgnoresFileList;
461
462 // Currently this is only used as part of the `-emit-symbol-graph`
463 // action.
464 // Location of output directory where symbol graph information would
465 // be dumped
467
468 /// Args to pass to the plugins
469 std::map<std::string, std::vector<std::string>> PluginArgs;
470
471 /// The list of plugin actions to run in addition to the normal action.
472 std::vector<std::string> AddPluginActions;
473
474 /// The list of plugins to load.
475 std::vector<std::string> Plugins;
476
477 /// The list of module file extensions.
478 std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
479
480 /// The list of module map files to load before processing the input.
481 std::vector<std::string> ModuleMapFiles;
482
483 /// The list of additional prebuilt module files to load before
484 /// processing the input.
485 std::vector<std::string> ModuleFiles;
486
487 /// The list of files to embed into the compiled module file.
488 std::vector<std::string> ModulesEmbedFiles;
489
490 /// The list of AST files to merge.
491 std::vector<std::string> ASTMergeFiles;
492
493 /// A list of arguments to forward to LLVM's option processing; this
494 /// should only be used for debugging and experimental features.
495 std::vector<std::string> LLVMArgs;
496
497 /// File name of the file that will provide record layouts
498 /// (in the format produced by -fdump-record-layouts).
500
501 /// Auxiliary triple for CUDA/HIP compilation.
502 std::string AuxTriple;
503
504 /// Auxiliary target CPU for CUDA/HIP compilation.
505 std::optional<std::string> AuxTargetCPU;
506
507 /// Auxiliary target features for CUDA/HIP compilation.
508 std::optional<std::vector<std::string>> AuxTargetFeatures;
509
510 /// Filename to write statistics to.
511 std::string StatsFile;
512
513 /// Minimum time granularity (in microseconds) traced by time profiler.
515
516 /// Path which stores the output files for -ftime-trace
517 std::string TimeTracePath;
518
519public:
532
533 /// getInputKindForExtension - Return the appropriate input kind for a file
534 /// extension. For example, "c" would return Language::C.
535 ///
536 /// \return The input kind for the extension, or Language::Unknown if the
537 /// extension is not recognized.
538 static InputKind getInputKindForExtension(StringRef Extension);
539};
540
541} // namespace clang
542
543#endif // LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
Options controlling the behavior of code completion.
An input file for the front end.
llvm::MemoryBufferRef getBuffer() const
FrontendInputFile(llvm::MemoryBufferRef Buffer, InputKind Kind, bool IsSystem=false)
InputKind getKind() const
StringRef getFile() const
InputKind::HeaderUnitKind getHeaderUnitKind() const
FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem=false)
FrontendOptions - Options for controlling the behavior of the frontend.
InputKind DashX
The input kind, either specified via -x argument or deduced from the input file name.
unsigned BuildingImplicitModule
Whether we are performing an implicit module build.
unsigned TimeTraceGranularity
Minimum time granularity (in microseconds) traced by time profiler.
std::string ObjCMTAllowListPath
std::vector< std::string > ModuleFiles
The list of additional prebuilt module files to load before processing the input.
unsigned AllowPCMWithCompilerErrors
Output (and read) PCM files regardless of compiler errors.
unsigned SkipFunctionBodies
Skip over function bodies to speed up parsing in cases you do not need them (e.g.
unsigned IncludeTimestamps
Whether timestamps should be written to the produced PCH file.
std::map< std::string, std::vector< std::string > > PluginArgs
Args to pass to the plugins.
unsigned BuildingImplicitModuleUsesLock
Whether to use a filesystem lock when building implicit modules.
unsigned ModulesShareFileManager
Whether to share the FileManager when building modules.
std::string ASTDumpFilter
If given, filter dumped AST Decl nodes by this substring.
unsigned ASTDumpLookups
Whether we include lookup table dumps in AST dumps.
unsigned UseTemporary
Should a temporary file be used during compilation.
CodeCompleteOptions CodeCompleteOpts
unsigned IsSystemModule
When using -emit-module, treat the modulemap as a system module.
unsigned PrintSupportedCPUs
print the supported cpus for the current target
unsigned FixToTemporaries
Apply fixes to temporary files.
unsigned PrintSupportedExtensions
Print the supported extensions for the current target.
std::vector< std::string > LLVMArgs
A list of arguments to forward to LLVM's option processing; this should only be used for debugging an...
unsigned ShowHelp
Show the -help text.
std::string TimeTracePath
Path which stores the output files for -ftime-trace.
unsigned FixAndRecompile
Apply fixes and recompile.
unsigned FixOnlyWarnings
Apply fixes only for warnings.
ASTDumpOutputFormat ASTDumpFormat
Specifies the output format of the AST.
std::optional< std::string > AuxTargetCPU
Auxiliary target CPU for CUDA/HIP compilation.
std::string StatsFile
Filename to write statistics to.
std::string OutputFile
The output file, if any.
unsigned ShowStats
Show frontend performance metrics and statistics.
std::string ActionName
The name of the action to run when using a plugin action.
std::vector< std::shared_ptr< ModuleFileExtension > > ModuleFileExtensions
The list of module file extensions.
ParsedSourceLocation CodeCompletionAt
If given, enable code completion at the provided location.
std::string FixItSuffix
If given, the new suffix for fix-it rewritten files.
std::string ARCMTMigrateReportOut
std::string OriginalModuleMap
When the input is a module map, the original module map file from which that map was inferred,...
std::vector< std::string > ModulesEmbedFiles
The list of files to embed into the compiled module file.
unsigned ShowVersion
Show the -version text.
unsigned ARCMTMigrateEmitARCErrors
Emit ARC errors even if the migrator can fix them.
enum clang::FrontendOptions::@191 ARCMTAction
std::string ProductName
The name of the product the input files belong too.
unsigned ModulesEmbedAllFiles
Whether we should embed all used files into the PCM file.
std::vector< std::string > AddPluginActions
The list of plugin actions to run in addition to the normal action.
unsigned ASTDumpDeclTypes
Whether we include declaration type dumps in AST dumps.
unsigned FixWhatYouCan
Apply fixes even if there are unfixable errors.
static InputKind getInputKindForExtension(StringRef Extension)
getInputKindForExtension - Return the appropriate input kind for a file extension.
std::string SymbolGraphOutputDir
std::vector< std::string > ASTMergeFiles
The list of AST files to merge.
std::vector< std::string > Plugins
The list of plugins to load.
unsigned ASTDumpAll
Whether we deserialize all decls when forming AST dumps.
unsigned GenerateGlobalModuleIndex
Whether we can generate the global module index if needed.
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
unsigned DisableFree
Disable memory freeing on exit.
@ ObjCMT_Instancetype
Enable migration of ObjC methods to 'instancetype'.
@ ObjCMT_DesignatedInitializer
Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
@ ObjCMT_Annotation
Enable annotation of ObjCMethods of all kinds.
@ ObjCMT_PropertyDotSyntax
Enable converting setter/getter expressions to property-dot syntx.
@ ObjCMT_ProtocolConformance
Enable migration to add conforming protocols.
@ ObjCMT_NsMacros
Enable migration to NS_ENUM/NS_OPTIONS macros.
@ ObjCMT_AtomicProperty
prefer 'atomic' property over 'nonatomic'.
@ ObjCMT_Literals
Enable migration to modern ObjC literals.
@ ObjCMT_ReadonlyProperty
Enable migration to modern ObjC readonly property.
@ ObjCMT_Subscripting
Enable migration to modern ObjC subscripting.
@ ObjCMT_NsAtomicIOSOnlyProperty
use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
@ ObjCMT_Property
Enable migration to modern ObjC property.
@ ObjCMT_ReadwriteProperty
Enable migration to modern ObjC readwrite property.
@ ObjCMT_ReturnsInnerPointerProperty
annotate property with NS_RETURNS_INNER_POINTER
SmallVector< FrontendInputFile, 0 > Inputs
The input files and their types.
frontend::ActionKind ProgramAction
The frontend action to perform.
std::optional< std::vector< std::string > > AuxTargetFeatures
Auxiliary target features for CUDA/HIP compilation.
std::string OverrideRecordLayoutsFile
File name of the file that will provide record layouts (in the format produced by -fdump-record-layou...
std::vector< std::string > ExtractAPIIgnoresFileList
std::string AuxTriple
Auxiliary triple for CUDA/HIP compilation.
unsigned UseGlobalModuleIndex
Whether we can use the global module index if available.
std::vector< std::string > ModuleMapFiles
The list of module map files to load before processing the input.
unsigned ASTDumpDecls
Whether we include declaration dumps in AST dumps.
The kind of a file that we've been handed as an input.
bool isPreprocessed() const
InputKind withHeaderUnit(HeaderUnitKind HU) const
bool isHeaderUnit() const
bool isUnknown() const
Is the input kind fully-unknown?
bool isObjectiveC() const
Is the language of the input some dialect of Objective-C?
constexpr InputKind(Language L=Language::Unknown, Format F=Source, bool PP=false, HeaderUnitKind HU=HeaderUnit_None, bool HD=false)
Format
The input file format.
InputKind getPreprocessed() const
bool isHeader() const
Format getFormat() const
HeaderUnitKind getHeaderUnitKind() const
InputKind getHeader() const
InputKind withFormat(Format F) const
Language getLanguage() const
@ GenerateHeaderUnit
Generate a C++20 header unit module from a header file.
@ VerifyPCH
Load and verify that a PCH file is usable.
@ PrintPreprocessedInput
-E mode.
@ RewriteTest
Rewriter playground.
@ ParseSyntaxOnly
Parse and perform semantic analysis.
@ TemplightDump
Dump template instantiations.
@ EmitBC
Emit a .bc file.
@ GenerateModuleInterface
Generate pre-compiled module from a C++ module interface file.
@ EmitLLVM
Emit a .ll file.
@ PrintPreamble
Print the "preamble" of the input file.
@ MigrateSource
Run migrator.
@ InitOnly
Only execute frontend initialization.
@ ASTView
Parse ASTs and view them in Graphviz.
@ PluginAction
Run a plugin action,.
@ EmitObj
Emit a .o file.
@ DumpRawTokens
Dump out raw tokens.
@ PrintDependencyDirectivesSourceMinimizerOutput
Print the output of the dependency directives source minimizer.
@ RewriteObjC
ObjC->C Rewriter.
@ RunPreprocessorOnly
Just lex, no output.
@ ModuleFileInfo
Dump information about a module file.
@ DumpCompilerOptions
Dump the compiler configuration.
@ RunAnalysis
Run one or more source code analyses.
@ ASTPrint
Parse ASTs and print them.
@ GenerateInterfaceStubs
Generate Interface Stub Files.
@ ASTDump
Parse ASTs and dump them.
@ DumpTokens
Dump out preprocessed tokens.
@ FixIt
Parse and apply any fixits to the source.
@ EmitAssembly
Emit a .s file.
@ EmitCodeGenOnly
Generate machine code, but don't emit anything.
@ RewriteMacros
Expand macros but not #includes.
@ EmitHTML
Translate input source into HTML.
@ GeneratePCH
Generate pre-compiled header.
@ EmitLLVMOnly
Generate LLVM IR, but do not emit anything.
@ GenerateModule
Generate pre-compiled module from a module map.
@ ASTDeclList
Parse ASTs and list Decl nodes.
ASTDumpOutputFormat
Used to specify the format for printing AST dump information.
@ ADOF_Default
Language
The language for the input, used to select and validate the language standard and possible actions.
Definition: LangStandard.h:23
YAML serialization mapping.
Definition: Dominators.h:30
#define true
Definition: stdbool.h:21
#define false
Definition: stdbool.h:22
A source location that has been parsed on the command line.