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 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.
150public:
151 /// The input file format.
152 enum Format {
156 };
157
158 // If we are building a header unit, what kind it is; this affects whether
159 // we look for the file in the user or system include search paths before
160 // flagging a missing input.
166 };
167
168private:
169 Language Lang;
170 LLVM_PREFERRED_TYPE(Format)
171 unsigned Fmt : 3;
172 LLVM_PREFERRED_TYPE(bool)
173 unsigned Preprocessed : 1;
174 LLVM_PREFERRED_TYPE(HeaderUnitKind)
175 unsigned HeaderUnit : 3;
176 LLVM_PREFERRED_TYPE(bool)
177 unsigned IsHeader : 1;
178
179public:
181 bool PP = false, HeaderUnitKind HU = HeaderUnit_None,
182 bool HD = false)
183 : Lang(L), Fmt(F), Preprocessed(PP), HeaderUnit(HU), IsHeader(HD) {}
184
185 Language getLanguage() const { return static_cast<Language>(Lang); }
186 Format getFormat() const { return static_cast<Format>(Fmt); }
188 return static_cast<HeaderUnitKind>(HeaderUnit);
189 }
190 bool isPreprocessed() const { return Preprocessed; }
191 bool isHeader() const { return IsHeader; }
192 bool isHeaderUnit() const { return HeaderUnit != HeaderUnit_None; }
193
194 /// Is the input kind fully-unknown?
195 bool isUnknown() const { return Lang == Language::Unknown && Fmt == Source; }
196
197 /// Is the language of the input some dialect of Objective-C?
198 bool isObjectiveC() const {
199 return Lang == Language::ObjC || Lang == Language::ObjCXX;
200 }
201
204 isHeader());
205 }
206
209 getHeaderUnitKind(), true);
210 }
211
214 isHeader());
215 }
216
219 isHeader());
220 }
221};
222
223/// An input file for the front end.
225 /// The file name, or "-" to read from standard input.
226 std::string File;
227
228 /// The input, if it comes from a buffer rather than a file. This object
229 /// does not own the buffer, and the caller is responsible for ensuring
230 /// that it outlives any users.
231 std::optional<llvm::MemoryBufferRef> Buffer;
232
233 /// The kind of input, e.g., C source, AST file, LLVM IR.
234 InputKind Kind;
235
236 /// Whether we're dealing with a 'system' input (vs. a 'user' input).
237 bool IsSystem = false;
238
239public:
240 FrontendInputFile() = default;
241 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
242 : File(File.str()), Kind(Kind), IsSystem(IsSystem) {}
243 FrontendInputFile(llvm::MemoryBufferRef Buffer, InputKind Kind,
244 bool IsSystem = false)
245 : Buffer(Buffer), Kind(Kind), IsSystem(IsSystem) {}
246
247 InputKind getKind() const { return Kind; }
248 bool isSystem() const { return IsSystem; }
249
250 bool isEmpty() const { return File.empty() && Buffer == std::nullopt; }
251 bool isFile() const { return !isBuffer(); }
252 bool isBuffer() const { return Buffer != std::nullopt; }
253 bool isPreprocessed() const { return Kind.isPreprocessed(); }
254 bool isHeader() const { return Kind.isHeader(); }
256 return Kind.getHeaderUnitKind();
257 }
258
259 StringRef getFile() const {
260 assert(isFile());
261 return File;
262 }
263
264 llvm::MemoryBufferRef getBuffer() const {
265 assert(isBuffer());
266 return *Buffer;
267 }
268};
269
270/// FrontendOptions - Options for controlling the behavior of the frontend.
272public:
273 /// Disable memory freeing on exit.
274 LLVM_PREFERRED_TYPE(bool)
276
277 /// When generating PCH files, instruct the AST writer to create relocatable
278 /// PCH files.
279 LLVM_PREFERRED_TYPE(bool)
280 unsigned RelocatablePCH : 1;
281
282 /// Show the -help text.
283 LLVM_PREFERRED_TYPE(bool)
284 unsigned ShowHelp : 1;
285
286 /// Show frontend performance metrics and statistics.
287 LLVM_PREFERRED_TYPE(bool)
288 unsigned ShowStats : 1;
289
290 LLVM_PREFERRED_TYPE(bool)
291 unsigned AppendStats : 1;
292
293 /// print the supported cpus for the current target
294 LLVM_PREFERRED_TYPE(bool)
295 unsigned PrintSupportedCPUs : 1;
296
297 /// Print the supported extensions for the current target.
298 LLVM_PREFERRED_TYPE(bool)
300
301 /// Show the -version text.
302 LLVM_PREFERRED_TYPE(bool)
303 unsigned ShowVersion : 1;
304
305 /// Apply fixes even if there are unfixable errors.
306 LLVM_PREFERRED_TYPE(bool)
307 unsigned FixWhatYouCan : 1;
308
309 /// Apply fixes only for warnings.
310 LLVM_PREFERRED_TYPE(bool)
311 unsigned FixOnlyWarnings : 1;
312
313 /// Apply fixes and recompile.
314 LLVM_PREFERRED_TYPE(bool)
315 unsigned FixAndRecompile : 1;
316
317 /// Apply fixes to temporary files.
318 LLVM_PREFERRED_TYPE(bool)
319 unsigned FixToTemporaries : 1;
320
321 /// Emit ARC errors even if the migrator can fix them.
322 LLVM_PREFERRED_TYPE(bool)
324
325 /// Skip over function bodies to speed up parsing in cases you do not need
326 /// them (e.g. with code completion).
327 LLVM_PREFERRED_TYPE(bool)
328 unsigned SkipFunctionBodies : 1;
329
330 /// Whether we can use the global module index if available.
331 LLVM_PREFERRED_TYPE(bool)
333
334 /// Whether we can generate the global module index if needed.
335 LLVM_PREFERRED_TYPE(bool)
337
338 /// Whether we include declaration dumps in AST dumps.
339 LLVM_PREFERRED_TYPE(bool)
340 unsigned ASTDumpDecls : 1;
341
342 /// Whether we deserialize all decls when forming AST dumps.
343 LLVM_PREFERRED_TYPE(bool)
344 unsigned ASTDumpAll : 1;
345
346 /// Whether we include lookup table dumps in AST dumps.
347 LLVM_PREFERRED_TYPE(bool)
348 unsigned ASTDumpLookups : 1;
349
350 /// Whether we include declaration type dumps in AST dumps.
351 LLVM_PREFERRED_TYPE(bool)
352 unsigned ASTDumpDeclTypes : 1;
353
354 /// Whether we are performing an implicit module build.
355 LLVM_PREFERRED_TYPE(bool)
357
358 /// Whether to use a filesystem lock when building implicit modules.
359 LLVM_PREFERRED_TYPE(bool)
361
362 /// Whether we should embed all used files into the PCM file.
363 LLVM_PREFERRED_TYPE(bool)
365
366 /// Whether timestamps should be written to the produced PCH file.
367 LLVM_PREFERRED_TYPE(bool)
368 unsigned IncludeTimestamps : 1;
369
370 /// Should a temporary file be used during compilation.
371 LLVM_PREFERRED_TYPE(bool)
372 unsigned UseTemporary : 1;
373
374 /// When using -emit-module, treat the modulemap as a system module.
375 LLVM_PREFERRED_TYPE(bool)
376 unsigned IsSystemModule : 1;
377
378 /// Output (and read) PCM files regardless of compiler errors.
379 LLVM_PREFERRED_TYPE(bool)
381
382 /// Whether to share the FileManager when building modules.
383 LLVM_PREFERRED_TYPE(bool)
385
387
388 /// Specifies the output format of the AST.
390
391 enum {
397
398 enum {
400
401 /// Enable migration to modern ObjC literals.
403
404 /// Enable migration to modern ObjC subscripting.
406
407 /// Enable migration to modern ObjC readonly property.
409
410 /// Enable migration to modern ObjC readwrite property.
412
413 /// Enable migration to modern ObjC property.
415
416 /// Enable annotation of ObjCMethods of all kinds.
418
419 /// Enable migration of ObjC methods to 'instancetype'.
421
422 /// Enable migration to NS_ENUM/NS_OPTIONS macros.
424
425 /// Enable migration to add conforming protocols.
427
428 /// prefer 'atomic' property over 'nonatomic'.
430
431 /// annotate property with NS_RETURNS_INNER_POINTER
433
434 /// use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
436
437 /// Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
439
440 /// Enable converting setter/getter expressions to property-dot syntx.
442
450 };
453
454 std::string MTMigrateDir;
456
457 /// The input kind, either specified via -x argument or deduced from the input
458 /// file name.
460
461 /// The input files and their types.
463
464 /// When the input is a module map, the original module map file from which
465 /// that map was inferred, if any (for umbrella modules).
466 std::string OriginalModuleMap;
467
468 /// The output file, if any.
469 std::string OutputFile;
470
471 /// If given, the new suffix for fix-it rewritten files.
472 std::string FixItSuffix;
473
474 /// If given, filter dumped AST Decl nodes by this substring.
475 std::string ASTDumpFilter;
476
477 /// If given, enable code completion at the provided location.
479
480 /// The frontend action to perform.
482
483 /// The name of the action to run when using a plugin action.
484 std::string ActionName;
485
486 // Currently this is only used as part of the `-extract-api` action.
487 /// The name of the product the input files belong too.
488 std::string ProductName;
489
490 // Currently this is only used as part of the `-extract-api` action.
491 // A comma seperated list of files providing a list of APIs to
492 // ignore when extracting documentation.
493 std::vector<std::string> ExtractAPIIgnoresFileList;
494
495 // Currently this is only used as part of the `-emit-symbol-graph`
496 // action.
497 // Location of output directory where symbol graph information would
498 // be dumped
500
501 /// Args to pass to the plugins
502 std::map<std::string, std::vector<std::string>> PluginArgs;
503
504 /// The list of plugin actions to run in addition to the normal action.
505 std::vector<std::string> AddPluginActions;
506
507 /// The list of plugins to load.
508 std::vector<std::string> Plugins;
509
510 /// The list of module file extensions.
511 std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
512
513 /// The list of module map files to load before processing the input.
514 std::vector<std::string> ModuleMapFiles;
515
516 /// The list of additional prebuilt module files to load before
517 /// processing the input.
518 std::vector<std::string> ModuleFiles;
519
520 /// The list of files to embed into the compiled module file.
521 std::vector<std::string> ModulesEmbedFiles;
522
523 /// The list of AST files to merge.
524 std::vector<std::string> ASTMergeFiles;
525
526 /// A list of arguments to forward to LLVM's option processing; this
527 /// should only be used for debugging and experimental features.
528 std::vector<std::string> LLVMArgs;
529
530 /// File name of the file that will provide record layouts
531 /// (in the format produced by -fdump-record-layouts).
533
534 /// Auxiliary triple for CUDA/HIP compilation.
535 std::string AuxTriple;
536
537 /// Auxiliary target CPU for CUDA/HIP compilation.
538 std::optional<std::string> AuxTargetCPU;
539
540 /// Auxiliary target features for CUDA/HIP compilation.
541 std::optional<std::vector<std::string>> AuxTargetFeatures;
542
543 /// Filename to write statistics to.
544 std::string StatsFile;
545
546 /// Minimum time granularity (in microseconds) traced by time profiler.
548
549 /// Path which stores the output files for -ftime-trace
550 std::string TimeTracePath;
551
552public:
565
566 /// getInputKindForExtension - Return the appropriate input kind for a file
567 /// extension. For example, "c" would return Language::C.
568 ///
569 /// \return The input kind for the extension, or Language::Unknown if the
570 /// extension is not recognized.
571 static InputKind getInputKindForExtension(StringRef Extension);
572};
573
574} // namespace clang
575
576#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.
enum clang::FrontendOptions::@192 ARCMTAction
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...
@ 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
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.
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.
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.
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.