clang 19.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 standard C++ module interface unit.
90
91 /// Generate reduced module interface for a standard C++ module interface
92 /// unit.
94
95 /// Generate a C++20 header unit module from a header file.
97
98 /// Generate pre-compiled header.
100
101 /// Generate Interface Stub Files.
103
104 /// Only execute frontend initialization.
106
107 /// Dump information about a module file.
109
110 /// Load and verify that a PCH file is usable.
112
113 /// Parse and perform semantic analysis.
115
116 /// Run a plugin action, \see ActionName.
118
119 /// Print the "preamble" of the input file
121
122 /// -E mode.
124
125 /// Expand macros but not \#includes.
127
128 /// ObjC->C Rewriter.
130
131 /// Rewriter playground
133
134 /// Run one or more source code analyses.
136
137 /// Dump template instantiations
139
140 /// Run migrator.
142
143 /// Just lex, no output.
145
146 /// Print the output of the dependency directives source minimizer.
149
150} // namespace frontend
151
152/// The kind of a file that we've been handed as an input.
154public:
155 /// The input file format.
156 enum Format {
160 };
161
162 // If we are building a header unit, what kind it is; this affects whether
163 // we look for the file in the user or system include search paths before
164 // flagging a missing input.
170 };
171
172private:
173 Language Lang;
174 LLVM_PREFERRED_TYPE(Format)
175 unsigned Fmt : 3;
176 LLVM_PREFERRED_TYPE(bool)
177 unsigned Preprocessed : 1;
178 LLVM_PREFERRED_TYPE(HeaderUnitKind)
179 unsigned HeaderUnit : 3;
180 LLVM_PREFERRED_TYPE(bool)
181 unsigned IsHeader : 1;
182
183public:
185 bool PP = false, HeaderUnitKind HU = HeaderUnit_None,
186 bool HD = false)
187 : Lang(L), Fmt(F), Preprocessed(PP), HeaderUnit(HU), IsHeader(HD) {}
188
189 Language getLanguage() const { return static_cast<Language>(Lang); }
190 Format getFormat() const { return static_cast<Format>(Fmt); }
192 return static_cast<HeaderUnitKind>(HeaderUnit);
193 }
194 bool isPreprocessed() const { return Preprocessed; }
195 bool isHeader() const { return IsHeader; }
196 bool isHeaderUnit() const { return HeaderUnit != HeaderUnit_None; }
197
198 /// Is the input kind fully-unknown?
199 bool isUnknown() const { return Lang == Language::Unknown && Fmt == Source; }
200
201 /// Is the language of the input some dialect of Objective-C?
202 bool isObjectiveC() const {
203 return Lang == Language::ObjC || Lang == Language::ObjCXX;
204 }
205
208 isHeader());
209 }
210
213 getHeaderUnitKind(), true);
214 }
215
218 isHeader());
219 }
220
223 isHeader());
224 }
225};
226
227/// An input file for the front end.
229 /// The file name, or "-" to read from standard input.
230 std::string File;
231
232 /// The input, if it comes from a buffer rather than a file. This object
233 /// does not own the buffer, and the caller is responsible for ensuring
234 /// that it outlives any users.
235 std::optional<llvm::MemoryBufferRef> Buffer;
236
237 /// The kind of input, e.g., C source, AST file, LLVM IR.
238 InputKind Kind;
239
240 /// Whether we're dealing with a 'system' input (vs. a 'user' input).
241 bool IsSystem = false;
242
243public:
244 FrontendInputFile() = default;
245 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
246 : File(File.str()), Kind(Kind), IsSystem(IsSystem) {}
247 FrontendInputFile(llvm::MemoryBufferRef Buffer, InputKind Kind,
248 bool IsSystem = false)
249 : Buffer(Buffer), Kind(Kind), IsSystem(IsSystem) {}
250
251 InputKind getKind() const { return Kind; }
252 bool isSystem() const { return IsSystem; }
253
254 bool isEmpty() const { return File.empty() && Buffer == std::nullopt; }
255 bool isFile() const { return !isBuffer(); }
256 bool isBuffer() const { return Buffer != std::nullopt; }
257 bool isPreprocessed() const { return Kind.isPreprocessed(); }
258 bool isHeader() const { return Kind.isHeader(); }
260 return Kind.getHeaderUnitKind();
261 }
262
263 StringRef getFile() const {
264 assert(isFile());
265 return File;
266 }
267
268 llvm::MemoryBufferRef getBuffer() const {
269 assert(isBuffer());
270 return *Buffer;
271 }
272};
273
274/// FrontendOptions - Options for controlling the behavior of the frontend.
276public:
277 /// Disable memory freeing on exit.
278 LLVM_PREFERRED_TYPE(bool)
280
281 /// When generating PCH files, instruct the AST writer to create relocatable
282 /// PCH files.
283 LLVM_PREFERRED_TYPE(bool)
284 unsigned RelocatablePCH : 1;
285
286 /// Show the -help text.
287 LLVM_PREFERRED_TYPE(bool)
288 unsigned ShowHelp : 1;
289
290 /// Show frontend performance metrics and statistics.
291 LLVM_PREFERRED_TYPE(bool)
292 unsigned ShowStats : 1;
293
294 LLVM_PREFERRED_TYPE(bool)
295 unsigned AppendStats : 1;
296
297 /// print the supported cpus for the current target
298 LLVM_PREFERRED_TYPE(bool)
299 unsigned PrintSupportedCPUs : 1;
300
301 /// Print the supported extensions for the current target.
302 LLVM_PREFERRED_TYPE(bool)
304
305 /// Show the -version text.
306 LLVM_PREFERRED_TYPE(bool)
307 unsigned ShowVersion : 1;
308
309 /// Apply fixes even if there are unfixable errors.
310 LLVM_PREFERRED_TYPE(bool)
311 unsigned FixWhatYouCan : 1;
312
313 /// Apply fixes only for warnings.
314 LLVM_PREFERRED_TYPE(bool)
315 unsigned FixOnlyWarnings : 1;
316
317 /// Apply fixes and recompile.
318 LLVM_PREFERRED_TYPE(bool)
319 unsigned FixAndRecompile : 1;
320
321 /// Apply fixes to temporary files.
322 LLVM_PREFERRED_TYPE(bool)
323 unsigned FixToTemporaries : 1;
324
325 /// Emit ARC errors even if the migrator can fix them.
326 LLVM_PREFERRED_TYPE(bool)
328
329 /// Skip over function bodies to speed up parsing in cases you do not need
330 /// them (e.g. with code completion).
331 LLVM_PREFERRED_TYPE(bool)
332 unsigned SkipFunctionBodies : 1;
333
334 /// Whether we can use the global module index if available.
335 LLVM_PREFERRED_TYPE(bool)
337
338 /// Whether we can generate the global module index if needed.
339 LLVM_PREFERRED_TYPE(bool)
341
342 /// Whether we include declaration dumps in AST dumps.
343 LLVM_PREFERRED_TYPE(bool)
344 unsigned ASTDumpDecls : 1;
345
346 /// Whether we deserialize all decls when forming AST dumps.
347 LLVM_PREFERRED_TYPE(bool)
348 unsigned ASTDumpAll : 1;
349
350 /// Whether we include lookup table dumps in AST dumps.
351 LLVM_PREFERRED_TYPE(bool)
352 unsigned ASTDumpLookups : 1;
353
354 /// Whether we include declaration type dumps in AST dumps.
355 LLVM_PREFERRED_TYPE(bool)
356 unsigned ASTDumpDeclTypes : 1;
357
358 /// Whether we are performing an implicit module build.
359 LLVM_PREFERRED_TYPE(bool)
361
362 /// Whether to use a filesystem lock when building implicit modules.
363 LLVM_PREFERRED_TYPE(bool)
365
366 /// Whether we should embed all used files into the PCM file.
367 LLVM_PREFERRED_TYPE(bool)
369
370 /// Whether timestamps should be written to the produced PCH file.
371 LLVM_PREFERRED_TYPE(bool)
372 unsigned IncludeTimestamps : 1;
373
374 /// Should a temporary file be used during compilation.
375 LLVM_PREFERRED_TYPE(bool)
376 unsigned UseTemporary : 1;
377
378 /// When using -emit-module, treat the modulemap as a system module.
379 LLVM_PREFERRED_TYPE(bool)
380 unsigned IsSystemModule : 1;
381
382 /// Output (and read) PCM files regardless of compiler errors.
383 LLVM_PREFERRED_TYPE(bool)
385
386 /// Whether to share the FileManager when building modules.
387 LLVM_PREFERRED_TYPE(bool)
389
391
392 /// Specifies the output format of the AST.
394
395 enum {
401
402 enum {
404
405 /// Enable migration to modern ObjC literals.
407
408 /// Enable migration to modern ObjC subscripting.
410
411 /// Enable migration to modern ObjC readonly property.
413
414 /// Enable migration to modern ObjC readwrite property.
416
417 /// Enable migration to modern ObjC property.
419
420 /// Enable annotation of ObjCMethods of all kinds.
422
423 /// Enable migration of ObjC methods to 'instancetype'.
425
426 /// Enable migration to NS_ENUM/NS_OPTIONS macros.
428
429 /// Enable migration to add conforming protocols.
431
432 /// prefer 'atomic' property over 'nonatomic'.
434
435 /// annotate property with NS_RETURNS_INNER_POINTER
437
438 /// use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
440
441 /// Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
443
444 /// Enable converting setter/getter expressions to property-dot syntx.
446
454 };
457
458 std::string MTMigrateDir;
460
461 /// The input kind, either specified via -x argument or deduced from the input
462 /// file name.
464
465 /// The input files and their types.
467
468 /// When the input is a module map, the original module map file from which
469 /// that map was inferred, if any (for umbrella modules).
470 std::string OriginalModuleMap;
471
472 /// The output file, if any.
473 std::string OutputFile;
474
475 /// If given, the new suffix for fix-it rewritten files.
476 std::string FixItSuffix;
477
478 /// If given, filter dumped AST Decl nodes by this substring.
479 std::string ASTDumpFilter;
480
481 /// If given, enable code completion at the provided location.
483
484 /// The frontend action to perform.
486
487 /// The name of the action to run when using a plugin action.
488 std::string ActionName;
489
490 // Currently this is only used as part of the `-extract-api` action.
491 /// The name of the product the input files belong too.
492 std::string ProductName;
493
494 // Currently this is only used as part of the `-extract-api` action.
495 // A comma seperated list of files providing a list of APIs to
496 // ignore when extracting documentation.
497 std::vector<std::string> ExtractAPIIgnoresFileList;
498
499 // Currently this is only used as part of the `-emit-symbol-graph`
500 // action.
501 // Location of output directory where symbol graph information would
502 // be dumped
504
505 /// Args to pass to the plugins
506 std::map<std::string, std::vector<std::string>> PluginArgs;
507
508 /// The list of plugin actions to run in addition to the normal action.
509 std::vector<std::string> AddPluginActions;
510
511 /// The list of plugins to load.
512 std::vector<std::string> Plugins;
513
514 /// The list of module file extensions.
515 std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
516
517 /// The list of module map files to load before processing the input.
518 std::vector<std::string> ModuleMapFiles;
519
520 /// The list of additional prebuilt module files to load before
521 /// processing the input.
522 std::vector<std::string> ModuleFiles;
523
524 /// The list of files to embed into the compiled module file.
525 std::vector<std::string> ModulesEmbedFiles;
526
527 /// The list of AST files to merge.
528 std::vector<std::string> ASTMergeFiles;
529
530 /// A list of arguments to forward to LLVM's option processing; this
531 /// should only be used for debugging and experimental features.
532 std::vector<std::string> LLVMArgs;
533
534 /// File name of the file that will provide record layouts
535 /// (in the format produced by -fdump-record-layouts).
537
538 /// Auxiliary triple for CUDA/HIP compilation.
539 std::string AuxTriple;
540
541 /// Auxiliary target CPU for CUDA/HIP compilation.
542 std::optional<std::string> AuxTargetCPU;
543
544 /// Auxiliary target features for CUDA/HIP compilation.
545 std::optional<std::vector<std::string>> AuxTargetFeatures;
546
547 /// Filename to write statistics to.
548 std::string StatsFile;
549
550 /// Minimum time granularity (in microseconds) traced by time profiler.
552
553 /// Path which stores the output files for -ftime-trace
554 std::string TimeTracePath;
555
556public:
569
570 /// getInputKindForExtension - Return the appropriate input kind for a file
571 /// extension. For example, "c" would return Language::C.
572 ///
573 /// \return The input kind for the extension, or Language::Unknown if the
574 /// extension is not recognized.
575 static InputKind getInputKindForExtension(StringRef Extension);
576};
577
578} // namespace clang
579
580#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
@ 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
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.
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.
enum clang::FrontendOptions::@193 ARCMTAction
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
unsigned DisableFree
Disable memory freeing on exit.
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 standard C++ module interface unit.
@ 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.
@ GenerateReducedModuleInterface
Generate reduced module interface for a standard C++ module interface unit.
@ 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.
The JSON file list parser is used to communicate input to InstallAPI.
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.