clang 23.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/Compiler.h"
19#include "llvm/Support/MemoryBuffer.h"
20#include <cassert>
21#include <map>
22#include <memory>
23#include <optional>
24#include <string>
25#include <vector>
26
27namespace llvm {
28
29class MemoryBuffer;
30
31} // namespace llvm
32
33namespace clang {
34
35namespace frontend {
36
38 /// Parse ASTs and list Decl nodes.
40
41 /// Parse ASTs and dump them.
43
44 /// Parse ASTs and print them.
46
47 /// Parse ASTs and view them in Graphviz.
49
50 /// Dump the compiler configuration.
52
53 /// Dump out raw tokens.
55
56 /// Dump out preprocessed tokens.
58
59 /// Emit a .s file.
61
62 /// Emit a .bc file.
64
65 /// Translate input source into HTML.
67
68 /// Emit a .cir file
70
71 /// Emit a .ll file.
73
74 /// Generate LLVM IR, but do not emit anything.
76
77 /// Generate machine code, but don't emit anything.
79
80 /// Emit a .o file.
82
83 // Extract API information
85
86 /// Parse and apply any fixits to the source.
88
89 /// Generate pre-compiled module from a module map.
91
92 /// Generate pre-compiled module from a standard C++ module interface unit.
94
95 /// Generate reduced module interface for a standard C++ module interface
96 /// unit.
98
99 /// Generate a C++20 header unit module from a header file.
101
102 /// Generate pre-compiled header.
104
105 /// Generate Interface Stub Files.
107
108 /// Only execute frontend initialization.
110
111 /// Dump information about a module file.
113
114 /// Load and verify that a PCH file is usable.
116
117 /// Parse and perform semantic analysis.
119
120 /// Run a plugin action, \see ActionName.
122
123 /// Print the "preamble" of the input file
125
126 /// -E mode.
128
129 /// Expand macros but not \#includes.
131
132 /// ObjC->C Rewriter.
134
135 /// Rewriter playground
137
138 /// Run one or more source code analyses.
140
141 /// Dump template instantiations
143
144 /// Just lex, no output.
146
147 /// Print the output of the dependency directives source minimizer.
149};
150
151} // namespace frontend
152
153/// The kind of a file that we've been handed as an input.
155public:
156 /// The input file format.
162
163 // If we are building a header unit, what kind it is; this affects whether
164 // we look for the file in the user or system include search paths before
165 // flagging a missing input.
172
173private:
174 Language Lang;
175 LLVM_PREFERRED_TYPE(Format)
176 unsigned Fmt : 3;
177 LLVM_PREFERRED_TYPE(bool)
178 unsigned Preprocessed : 1;
179 LLVM_PREFERRED_TYPE(HeaderUnitKind)
180 unsigned HeaderUnit : 3;
181 LLVM_PREFERRED_TYPE(bool)
182 unsigned IsHeader : 1;
183
184public:
186 bool PP = false, HeaderUnitKind HU = HeaderUnit_None,
187 bool HD = false)
188 : Lang(L), Fmt(F), Preprocessed(PP), HeaderUnit(HU), IsHeader(HD) {}
189
190 Language getLanguage() const { return static_cast<Language>(Lang); }
191 Format getFormat() const { return static_cast<Format>(Fmt); }
193 return static_cast<HeaderUnitKind>(HeaderUnit);
194 }
195 bool isPreprocessed() const { return Preprocessed; }
196 bool isHeader() const { return IsHeader; }
197 bool isHeaderUnit() const { return HeaderUnit != HeaderUnit_None; }
198
199 /// Is the input kind fully-unknown?
200 bool isUnknown() const { return Lang == Language::Unknown && Fmt == Source; }
201
202 /// Is the language of the input some dialect of Objective-C?
203 bool isObjectiveC() const {
204 return Lang == Language::ObjC || Lang == Language::ObjCXX;
205 }
206
209 isHeader());
210 }
211
214 getHeaderUnitKind(), true);
215 }
216
221
226};
227
228/// An input file for the front end.
230 /// The file name, or "-" to read from standard input.
231 std::string File;
232
233 /// The input, if it comes from a buffer rather than a file. This object
234 /// does not own the buffer, and the caller is responsible for ensuring
235 /// that it outlives any users.
236 std::optional<llvm::MemoryBufferRef> Buffer;
237
238 /// The kind of input, e.g., C source, AST file, LLVM IR.
239 InputKind Kind;
240
241 /// Whether we're dealing with a 'system' input (vs. a 'user' input).
242 bool IsSystem = false;
243
245
246public:
247 FrontendInputFile() = default;
248 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
249 : File(File.str()), Kind(Kind), IsSystem(IsSystem) {}
250 FrontendInputFile(llvm::MemoryBufferRef Buffer, InputKind Kind,
251 bool IsSystem = false)
252 : Buffer(Buffer), Kind(Kind), IsSystem(IsSystem) {}
253
254 InputKind getKind() const { return Kind; }
255 bool isSystem() const { return IsSystem; }
256
257 bool isEmpty() const { return File.empty() && Buffer == std::nullopt; }
258 bool isFile() const { return !isBuffer(); }
259 bool isBuffer() const { return Buffer != std::nullopt; }
260 bool isPreprocessed() const { return Kind.isPreprocessed(); }
261 bool isHeader() const { return Kind.isHeader(); }
263 return Kind.getHeaderUnitKind();
264 }
265
266 StringRef getFile() const {
267 assert(isFile());
268 return File;
269 }
270
271 llvm::MemoryBufferRef getBuffer() const {
272 assert(isBuffer());
273 return *Buffer;
274 }
275};
276
277/// FrontendOptions - Options for controlling the behavior of the frontend.
279public:
280 /// Disable memory freeing on exit.
281 LLVM_PREFERRED_TYPE(bool)
283
284 /// When generating PCH files, instruct the AST writer to create relocatable
285 /// PCH files.
286 LLVM_PREFERRED_TYPE(bool)
287 unsigned RelocatablePCH : 1;
288
289 /// Show the -help text.
290 LLVM_PREFERRED_TYPE(bool)
291 unsigned ShowHelp : 1;
292
293 /// Show frontend performance metrics and statistics.
294 LLVM_PREFERRED_TYPE(bool)
295 unsigned ShowStats : 1;
296
297 LLVM_PREFERRED_TYPE(bool)
298 unsigned AppendStats : 1;
299
300 /// print the supported cpus for the current target
301 LLVM_PREFERRED_TYPE(bool)
302 unsigned PrintSupportedCPUs : 1;
303
304 /// Print the supported extensions for the current target.
305 LLVM_PREFERRED_TYPE(bool)
307
308 /// Print the extensions enabled for the current target.
309 LLVM_PREFERRED_TYPE(bool)
311
312 /// Show the -version text.
313 LLVM_PREFERRED_TYPE(bool)
314 unsigned ShowVersion : 1;
315
316 /// Apply fixes even if there are unfixable errors.
317 LLVM_PREFERRED_TYPE(bool)
318 unsigned FixWhatYouCan : 1;
319
320 /// Apply fixes only for warnings.
321 LLVM_PREFERRED_TYPE(bool)
322 unsigned FixOnlyWarnings : 1;
323
324 /// Apply fixes and recompile.
325 LLVM_PREFERRED_TYPE(bool)
326 unsigned FixAndRecompile : 1;
327
328 /// Apply fixes to temporary files.
329 LLVM_PREFERRED_TYPE(bool)
330 unsigned FixToTemporaries : 1;
331
332 /// Skip over function bodies to speed up parsing in cases you do not need
333 /// them (e.g. with code completion).
334 LLVM_PREFERRED_TYPE(bool)
335 unsigned SkipFunctionBodies : 1;
336
337 /// Whether we can use the global module index if available.
338 LLVM_PREFERRED_TYPE(bool)
340
341 /// Whether we can generate the global module index if needed.
342 LLVM_PREFERRED_TYPE(bool)
344
345 /// Whether we include declaration dumps in AST dumps.
346 LLVM_PREFERRED_TYPE(bool)
347 unsigned ASTDumpDecls : 1;
348
349 /// Whether we deserialize all decls when forming AST dumps.
350 LLVM_PREFERRED_TYPE(bool)
351 unsigned ASTDumpAll : 1;
352
353 /// Whether we include lookup table dumps in AST dumps.
354 LLVM_PREFERRED_TYPE(bool)
355 unsigned ASTDumpLookups : 1;
356
357 /// Whether we include declaration type dumps in AST dumps.
358 LLVM_PREFERRED_TYPE(bool)
359 unsigned ASTDumpDeclTypes : 1;
360
361 /// Whether we are performing an implicit module build.
362 LLVM_PREFERRED_TYPE(bool)
364
365 /// Whether to use a filesystem lock when building implicit modules.
366 LLVM_PREFERRED_TYPE(bool)
368
369 /// Whether we should embed all used files into the PCM file.
370 LLVM_PREFERRED_TYPE(bool)
372
373 /// Whether timestamps should be written to the produced PCH file.
374 LLVM_PREFERRED_TYPE(bool)
375 unsigned IncludeTimestamps : 1;
376
377 /// Should a temporary file be used during compilation.
378 LLVM_PREFERRED_TYPE(bool)
379 unsigned UseTemporary : 1;
380
381 /// When using -emit-module, treat the modulemap as a system module.
382 LLVM_PREFERRED_TYPE(bool)
383 unsigned IsSystemModule : 1;
384
385 /// Output (and read) PCM files regardless of compiler errors.
386 LLVM_PREFERRED_TYPE(bool)
388
389 /// Whether to share the FileManager when building modules.
390 LLVM_PREFERRED_TYPE(bool)
392
393 /// Whether to emit symbol graph files as a side effect of compilation.
394 LLVM_PREFERRED_TYPE(bool)
395 unsigned EmitSymbolGraph : 1;
396
397 /// Whether to emit additional symbol graphs for extended modules.
398 LLVM_PREFERRED_TYPE(bool)
400
401 /// Whether to emit symbol labels for testing in generated symbol graphs
402 LLVM_PREFERRED_TYPE(bool)
404
405 /// Whether to emit symbol labels for testing in generated symbol graphs
406 LLVM_PREFERRED_TYPE(bool)
408
409 /// Whether to generate reduced BMI for C++20 named modules.
410 LLVM_PREFERRED_TYPE(bool)
411 unsigned GenReducedBMI : 1;
412
413 /// Use Clang IR pipeline to emit code
414 LLVM_PREFERRED_TYPE(bool)
415 unsigned UseClangIRPipeline : 1;
416
417 /// Disable Clang IR specific (CIR) passes
418 LLVM_PREFERRED_TYPE(bool)
420
421 /// Disable Clang IR (CIR) verifier
422 LLVM_PREFERRED_TYPE(bool)
424
425 /// Enable Clang IR (CIR) idiom recognizer
426 LLVM_PREFERRED_TYPE(bool)
428
430
431 /// Specifies the output format of the AST.
433
434 /// The input kind, either specified via -x argument or deduced from the input
435 /// file name.
437
438 /// The input files and their types.
440
441 /// When the input is a module map, the original module map file from which
442 /// that map was inferred, if any (for umbrella modules).
444
445 /// The output file, if any.
447
448 /// If given, the new suffix for fix-it rewritten files.
450
451 /// If given, filter dumped AST Decl nodes by this substring.
453
454 /// If given, enable code completion at the provided location.
456
457 /// The frontend action to perform.
458 frontend::ActionKind ProgramAction = frontend::ParseSyntaxOnly;
459
460 /// The name of the action to run when using a plugin action.
462
463 // Currently this is only used as part of the `-extract-api` action.
464 /// The name of the product the input files belong too.
466
467 // Currently this is only used as part of the `-extract-api` action.
468 // A comma separated list of files providing a list of APIs to
469 // ignore when extracting documentation.
471
472 // Location of output directory where symbol graph information would
473 // be dumped. This overrides regular -o output file specification
475
476 /// Args to pass to the plugins
477 std::map<std::string, std::vector<std::string>> PluginArgs;
478
479 /// The list of plugin actions to run in addition to the normal action.
480 std::vector<std::string> AddPluginActions;
481
482 /// The list of plugins to load.
483 std::vector<std::string> Plugins;
484
485 /// The list of module file extensions.
487
488 /// The list of module map files to load before processing the input.
489 std::vector<std::string> ModuleMapFiles;
490
491 /// The list of additional prebuilt module files to load before
492 /// processing the input.
493 std::vector<std::string> ModuleFiles;
494
495 /// The list of files to embed into the compiled module file.
496 std::vector<std::string> ModulesEmbedFiles;
497
498 /// The list of AST files to merge.
499 std::vector<std::string> ASTMergeFiles;
500
501 /// A list of arguments to forward to LLVM's option processing; this
502 /// should only be used for debugging and experimental features.
503 std::vector<std::string> LLVMArgs;
504
505 /// A list of arguments to forward to MLIR's option processing; this
506 /// should only be used for debugging and experimental features.
507 std::vector<std::string> MLIRArgs;
508
509 /// File name of the file that will provide record layouts
510 /// (in the format produced by -fdump-record-layouts).
512
513 /// Auxiliary triple for CUDA/HIP compilation.
514 std::string AuxTriple;
515
516 /// Auxiliary target CPU for CUDA/HIP compilation.
517 std::optional<std::string> AuxTargetCPU;
518
519 /// Auxiliary target features for CUDA/HIP compilation.
520 std::optional<std::vector<std::string>> AuxTargetFeatures;
521
522 /// Filename to write statistics to.
523 std::string StatsFile;
524
525 /// Minimum time granularity (in microseconds) traced by time profiler.
527
528 /// Make time trace capture verbose event details (e.g. source filenames).
529 /// This can increase the size of the output by 2-3 times.
530 LLVM_PREFERRED_TYPE(bool)
531 unsigned TimeTraceVerbose : 1;
532
533 /// Path which stores the output files for -ftime-trace
535
536 /// Output Path for module output file.
538
539 /// Output path to dump ranges of deserialized declarations to use as
540 /// minimization hints.
542
543public:
561
562 /// getInputKindForExtension - Return the appropriate input kind for a file
563 /// extension. For example, "c" would return Language::C.
564 ///
565 /// \return The input kind for the extension, or Language::Unknown if the
566 /// extension is not recognized.
567 static InputKind getInputKindForExtension(StringRef Extension);
568};
569
570} // namespace clang
571
572#endif // LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
Options controlling the behavior of code completion.
An input file for the front end.
llvm::MemoryBufferRef getBuffer() const
friend class CompilerInvocationBase
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)
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::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 ClangIRDisablePasses
Disable Clang IR specific (CIR) passes.
unsigned IncludeTimestamps
Whether timestamps should be written to the produced PCH file.
unsigned EmitSymbolGraphSymbolLabelsForTesting
Whether to emit symbol labels for testing in generated symbol graphs.
unsigned EmitSymbolGraph
Whether to emit symbol graph files as a side effect of compilation.
std::map< std::string, std::vector< std::string > > PluginArgs
Args to pass to the plugins.
unsigned ClangIRDisableCIRVerifier
Disable Clang IR (CIR) verifier.
unsigned BuildingImplicitModuleUsesLock
Whether to use a filesystem lock when building implicit modules.
unsigned ModulesShareFileManager
Whether to share the FileManager when building modules.
std::vector< std::string > MLIRArgs
A list of arguments to forward to MLIR's option processing; this should only be used for debugging an...
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.
unsigned PrintEnabledExtensions
Print the extensions enabled 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 UseClangIRPipeline
Use Clang IR pipeline to emit code.
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.
unsigned GenReducedBMI
Whether to generate reduced BMI for C++20 named modules.
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 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.
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::string ModuleOutputPath
Output Path for module output 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.
unsigned ClangIREnableIdiomRecognizer
Enable Clang IR (CIR) idiom recognizer.
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 TimeTraceVerbose
Make time trace capture verbose event details (e.g.
std::string DumpMinimizationHintsPath
Output path to dump ranges of deserialized declarations to use as minimization hints.
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
unsigned EmitExtensionSymbolGraphs
Whether to emit additional symbol graphs for extended modules.
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.
unsigned EmitPrettySymbolGraphs
Whether to emit symbol labels for testing in generated symbol graphs.
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
An abstract superclass that describes a custom extension to the module/precompiled header file format...
@ 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.
@ 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.
@ EmitCIR
Emit a .cir 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.
Language
The language for the input, used to select and validate the language standard and possible actions.
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25
A source location that has been parsed on the command line.