clang  9.0.0svn
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 
16 #include "llvm/ADT/StringRef.h"
17 #include <cassert>
18 #include <memory>
19 #include <string>
20 #include <vector>
21 #include <unordered_map>
22 
23 namespace llvm {
24 
25 class MemoryBuffer;
26 
27 } // namespace llvm
28 
29 namespace clang {
30 
31 namespace frontend {
32 
33 enum ActionKind {
34  /// Parse ASTs and list Decl nodes.
36 
37  /// Parse ASTs and dump them.
39 
40  /// Parse ASTs and print them.
42 
43  /// Parse ASTs and view them in Graphviz.
45 
46  /// Dump the compiler configuration.
48 
49  /// Dump out raw tokens.
51 
52  /// Dump out preprocessed tokens.
54 
55  /// Emit a .s file.
57 
58  /// Emit a .bc file.
60 
61  /// Translate input source into HTML.
63 
64  /// Emit a .ll file.
66 
67  /// Generate LLVM IR, but do not emit anything.
69 
70  /// Generate machine code, but don't emit anything.
72 
73  /// Emit a .o file.
75 
76  /// Parse and apply any fixits to the source.
78 
79  /// Generate pre-compiled module from a module map.
81 
82  /// Generate pre-compiled module from a C++ module interface file.
84 
85  /// Generate pre-compiled module from a set of header files.
87 
88  /// Generate pre-compiled header.
90 
91  /// Only execute frontend initialization.
93 
94  /// Dump information about a module file.
96 
97  /// Load and verify that a PCH file is usable.
99 
100  /// Parse and perform semantic analysis.
102 
103  /// Run a plugin action, \see ActionName.
105 
106  /// Print the "preamble" of the input file
108 
109  /// -E mode.
111 
112  /// Expand macros but not \#includes.
114 
115  /// ObjC->C Rewriter.
117 
118  /// Rewriter playground
120 
121  /// Run one or more source code analyses.
123 
124  /// Dump template instantiations
126 
127  /// Run migrator.
129 
130  /// Just lex, no output.
132 };
133 
134 } // namespace frontend
135 
136 /// The kind of a file that we've been handed as an input.
137 class InputKind {
138 private:
139  unsigned Lang : 4;
140  unsigned Fmt : 3;
141  unsigned Preprocessed : 1;
142 
143 public:
144  /// The language for the input, used to select and validate the language
145  /// standard and possible actions.
146  enum Language {
148 
149  /// Assembly: we accept this only so that we can preprocess it.
151 
152  /// LLVM IR: we accept this so that we can run the optimizer on it,
153  /// and compile it to assembly or object code.
155 
156  ///@{ Languages that the frontend can parse and compile.
157  C,
165  ///@}
166  };
167 
168  /// The input file format.
169  enum Format {
172  Precompiled
173  };
174 
175  constexpr InputKind(Language L = Unknown, Format F = Source,
176  bool PP = false)
177  : Lang(L), Fmt(F), Preprocessed(PP) {}
178 
179  Language getLanguage() const { return static_cast<Language>(Lang); }
180  Format getFormat() const { return static_cast<Format>(Fmt); }
181  bool isPreprocessed() const { return Preprocessed; }
182 
183  /// Is the input kind fully-unknown?
184  bool isUnknown() const { return Lang == Unknown && Fmt == Source; }
185 
186  /// Is the language of the input some dialect of Objective-C?
187  bool isObjectiveC() const { return Lang == ObjC || Lang == ObjCXX; }
188 
190  return InputKind(getLanguage(), getFormat(), true);
191  }
192 
194  return InputKind(getLanguage(), F, isPreprocessed());
195  }
196 };
197 
198 /// An input file for the front end.
200  /// The file name, or "-" to read from standard input.
201  std::string File;
202 
203  /// The input, if it comes from a buffer rather than a file. This object
204  /// does not own the buffer, and the caller is responsible for ensuring
205  /// that it outlives any users.
206  const llvm::MemoryBuffer *Buffer = nullptr;
207 
208  /// The kind of input, e.g., C source, AST file, LLVM IR.
209  InputKind Kind;
210 
211  /// Whether we're dealing with a 'system' input (vs. a 'user' input).
212  bool IsSystem = false;
213 
214 public:
215  FrontendInputFile() = default;
216  FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
217  : File(File.str()), Kind(Kind), IsSystem(IsSystem) {}
218  FrontendInputFile(const llvm::MemoryBuffer *Buffer, InputKind Kind,
219  bool IsSystem = false)
220  : Buffer(Buffer), Kind(Kind), IsSystem(IsSystem) {}
221 
222  InputKind getKind() const { return Kind; }
223  bool isSystem() const { return IsSystem; }
224 
225  bool isEmpty() const { return File.empty() && Buffer == nullptr; }
226  bool isFile() const { return !isBuffer(); }
227  bool isBuffer() const { return Buffer != nullptr; }
228  bool isPreprocessed() const { return Kind.isPreprocessed(); }
229 
230  StringRef getFile() const {
231  assert(isFile());
232  return File;
233  }
234 
235  const llvm::MemoryBuffer *getBuffer() const {
236  assert(isBuffer());
237  return Buffer;
238  }
239 };
240 
241 /// FrontendOptions - Options for controlling the behavior of the frontend.
243 public:
244  /// Disable memory freeing on exit.
245  unsigned DisableFree : 1;
246 
247  /// When generating PCH files, instruct the AST writer to create relocatable
248  /// PCH files.
249  unsigned RelocatablePCH : 1;
250 
251  /// Show the -help text.
252  unsigned ShowHelp : 1;
253 
254  /// Show frontend performance metrics and statistics.
255  unsigned ShowStats : 1;
256 
257  /// Show timers for individual actions.
258  unsigned ShowTimers : 1;
259 
260  /// Output time trace profile.
261  unsigned TimeTrace : 1;
262 
263  /// Show the -version text.
264  unsigned ShowVersion : 1;
265 
266  /// Apply fixes even if there are unfixable errors.
267  unsigned FixWhatYouCan : 1;
268 
269  /// Apply fixes only for warnings.
270  unsigned FixOnlyWarnings : 1;
271 
272  /// Apply fixes and recompile.
273  unsigned FixAndRecompile : 1;
274 
275  /// Apply fixes to temporary files.
276  unsigned FixToTemporaries : 1;
277 
278  /// Emit ARC errors even if the migrator can fix them.
280 
281  /// Skip over function bodies to speed up parsing in cases you do not need
282  /// them (e.g. with code completion).
283  unsigned SkipFunctionBodies : 1;
284 
285  /// Whether we can use the global module index if available.
286  unsigned UseGlobalModuleIndex : 1;
287 
288  /// Whether we can generate the global module index if needed.
290 
291  /// Whether we include declaration dumps in AST dumps.
292  unsigned ASTDumpDecls : 1;
293 
294  /// Whether we deserialize all decls when forming AST dumps.
295  unsigned ASTDumpAll : 1;
296 
297  /// Whether we include lookup table dumps in AST dumps.
298  unsigned ASTDumpLookups : 1;
299 
300  /// Whether we are performing an implicit module build.
302 
303  /// Whether we should embed all used files into the PCM file.
304  unsigned ModulesEmbedAllFiles : 1;
305 
306  /// Whether timestamps should be written to the produced PCH file.
307  unsigned IncludeTimestamps : 1;
308 
310 
311  /// Specifies the output format of the AST.
313 
314  enum {
318  ARCMT_Migrate
319  } ARCMTAction = ARCMT_None;
320 
321  enum {
322  ObjCMT_None = 0,
323 
324  /// Enable migration to modern ObjC literals.
325  ObjCMT_Literals = 0x1,
326 
327  /// Enable migration to modern ObjC subscripting.
328  ObjCMT_Subscripting = 0x2,
329 
330  /// Enable migration to modern ObjC readonly property.
331  ObjCMT_ReadonlyProperty = 0x4,
332 
333  /// Enable migration to modern ObjC readwrite property.
334  ObjCMT_ReadwriteProperty = 0x8,
335 
336  /// Enable migration to modern ObjC property.
337  ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty),
338 
339  /// Enable annotation of ObjCMethods of all kinds.
340  ObjCMT_Annotation = 0x10,
341 
342  /// Enable migration of ObjC methods to 'instancetype'.
343  ObjCMT_Instancetype = 0x20,
344 
345  /// Enable migration to NS_ENUM/NS_OPTIONS macros.
346  ObjCMT_NsMacros = 0x40,
347 
348  /// Enable migration to add conforming protocols.
349  ObjCMT_ProtocolConformance = 0x80,
350 
351  /// prefer 'atomic' property over 'nonatomic'.
352  ObjCMT_AtomicProperty = 0x100,
353 
354  /// annotate property with NS_RETURNS_INNER_POINTER
355  ObjCMT_ReturnsInnerPointerProperty = 0x200,
356 
357  /// use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
358  ObjCMT_NsAtomicIOSOnlyProperty = 0x400,
359 
360  /// Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
361  ObjCMT_DesignatedInitializer = 0x800,
362 
363  /// Enable converting setter/getter expressions to property-dot syntx.
364  ObjCMT_PropertyDotSyntax = 0x1000,
365 
366  ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty |
367  ObjCMT_Annotation | ObjCMT_Instancetype |
368  ObjCMT_NsMacros | ObjCMT_ProtocolConformance |
369  ObjCMT_NsAtomicIOSOnlyProperty |
370  ObjCMT_DesignatedInitializer),
371  ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting |
372  ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax)
373  };
374  unsigned ObjCMTAction = ObjCMT_None;
375  std::string ObjCMTWhiteListPath;
376 
377  std::string MTMigrateDir;
379 
380  /// The input files and their types.
381  std::vector<FrontendInputFile> Inputs;
382 
383  /// When the input is a module map, the original module map file from which
384  /// that map was inferred, if any (for umbrella modules).
385  std::string OriginalModuleMap;
386 
387  /// The output file, if any.
388  std::string OutputFile;
389 
390  /// If given, the new suffix for fix-it rewritten files.
391  std::string FixItSuffix;
392 
393  /// If given, filter dumped AST Decl nodes by this substring.
394  std::string ASTDumpFilter;
395 
396  /// If given, enable code completion at the provided location.
398 
399  /// The frontend action to perform.
401 
402  /// The name of the action to run when using a plugin action.
403  std::string ActionName;
404 
405  /// Args to pass to the plugins
406  std::unordered_map<std::string,std::vector<std::string>> PluginArgs;
407 
408  /// The list of plugin actions to run in addition to the normal action.
409  std::vector<std::string> AddPluginActions;
410 
411  /// The list of plugins to load.
412  std::vector<std::string> Plugins;
413 
414  /// The list of module file extensions.
415  std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
416 
417  /// The list of module map files to load before processing the input.
418  std::vector<std::string> ModuleMapFiles;
419 
420  /// The list of additional prebuilt module files to load before
421  /// processing the input.
422  std::vector<std::string> ModuleFiles;
423 
424  /// The list of files to embed into the compiled module file.
425  std::vector<std::string> ModulesEmbedFiles;
426 
427  /// The list of AST files to merge.
428  std::vector<std::string> ASTMergeFiles;
429 
430  /// A list of arguments to forward to LLVM's option processing; this
431  /// should only be used for debugging and experimental features.
432  std::vector<std::string> LLVMArgs;
433 
434  /// File name of the file that will provide record layouts
435  /// (in the format produced by -fdump-record-layouts).
437 
438  /// Auxiliary triple for CUDA compilation.
439  std::string AuxTriple;
440 
441  /// Filename to write statistics to.
442  std::string StatsFile;
443 
444 public:
446  : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
447  ShowStats(false), ShowTimers(false), TimeTrace(false),
448  ShowVersion(false), FixWhatYouCan(false), FixOnlyWarnings(false),
449  FixAndRecompile(false), FixToTemporaries(false),
450  ARCMTMigrateEmitARCErrors(false), SkipFunctionBodies(false),
451  UseGlobalModuleIndex(true), GenerateGlobalModuleIndex(true),
452  ASTDumpDecls(false), ASTDumpLookups(false),
453  BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
454  IncludeTimestamps(true) {}
455 
456  /// getInputKindForExtension - Return the appropriate input kind for a file
457  /// extension. For example, "c" would return InputKind::C.
458  ///
459  /// \return The input kind for the extension, or InputKind::Unknown if the
460  /// extension is not recognized.
461  static InputKind getInputKindForExtension(StringRef Extension);
462 };
463 
464 } // namespace clang
465 
466 #endif // LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
Expand macros but not #includes.
std::string OutputFile
The output file, if any.
std::string OriginalModuleMap
When the input is a module map, the original module map file from which that map was inferred...
std::string ObjCMTWhiteListPath
Generate pre-compiled module from a module map.
constexpr InputKind(Language L=Unknown, Format F=Source, bool PP=false)
Parse and perform semantic analysis.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:29
Emit a .bc file.
Format getFormat() const
Parse ASTs and print them.
bool isObjectiveC() const
Is the language of the input some dialect of Objective-C?
Format
The input file format.
std::string ASTDumpFilter
If given, filter dumped AST Decl nodes by this substring.
std::string FixItSuffix
If given, the new suffix for fix-it rewritten files.
Parse and apply any fixits to the source.
unsigned TimeTrace
Output time trace profile.
const llvm::MemoryBuffer * getBuffer() const
Translate input source into HTML.
A source location that has been parsed on the command line.
FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem=false)
InputKind withFormat(Format F) const
std::vector< std::string > ASTMergeFiles
The list of AST files to merge.
unsigned BuildingImplicitModule
Whether we are performing an implicit module build.
std::vector< std::string > ModulesEmbedFiles
The list of files to embed into the compiled module file.
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
Languages that the frontend can parse and compile.
Generate LLVM IR, but do not emit anything.
unsigned ShowStats
Show frontend performance metrics and statistics.
unsigned FixWhatYouCan
Apply fixes even if there are unfixable errors.
unsigned SkipFunctionBodies
Skip over function bodies to speed up parsing in cases you do not need them (e.g. ...
InputKind getKind() const
unsigned FixAndRecompile
Apply fixes and recompile.
Dump the compiler configuration.
bool isPreprocessed() const
Dump template instantiations.
return Out str()
Dump out preprocessed tokens.
unsigned ASTDumpAll
Whether we deserialize all decls when forming AST dumps.
Generate pre-compiled module from a C++ module interface file.
std::vector< std::string > Plugins
The list of plugins to load.
StringRef getFile() const
ASTDumpOutputFormat
Used to specify the format for printing AST dump information.
unsigned ShowTimers
Show timers for individual actions.
Only execute frontend initialization.
Print the "preamble" of the input file.
Rewriter playground.
unsigned ModulesEmbedAllFiles
Whether we should embed all used files into the PCM file.
unsigned FixOnlyWarnings
Apply fixes only for warnings.
An input file for the front end.
std::string AuxTriple
Auxiliary triple for CUDA compilation.
unsigned ARCMTMigrateEmitARCErrors
Emit ARC errors even if the migrator can fix them.
#define false
Definition: stdbool.h:17
Kind
InputKind getPreprocessed() const
Generate machine code, but don&#39;t emit anything.
Assembly: we accept this only so that we can preprocess it.
std::vector< std::string > ModuleFiles
The list of additional prebuilt module files to load before processing the input. ...
ParsedSourceLocation CodeCompletionAt
If given, enable code completion at the provided location.
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
std::vector< FrontendInputFile > Inputs
The input files and their types.
The kind of a file that we&#39;ve been handed as an input.
unsigned IncludeTimestamps
Whether timestamps should be written to the produced PCH file.
Parse ASTs and view them in Graphviz.
Parse ASTs and list Decl nodes.
std::unordered_map< std::string, std::vector< std::string > > PluginArgs
Args to pass to the plugins.
unsigned ASTDumpLookups
Whether we include lookup table dumps in AST dumps.
Load and verify that a PCH file is usable.
unsigned ShowVersion
Show the -version text.
unsigned GenerateGlobalModuleIndex
Whether we can generate the global module index if needed.
unsigned ShowHelp
Show the -help text.
std::string OverrideRecordLayoutsFile
File name of the file that will provide record layouts (in the format produced by -fdump-record-layou...
unsigned FixToTemporaries
Apply fixes to temporary files.
Options controlling the behavior of code completion.
Dataflow Directional Tag Classes.
Language getLanguage() const
std::string ARCMTMigrateReportOut
unsigned UseGlobalModuleIndex
Whether we can use the global module index if available.
Language
The language for the input, used to select and validate the language standard and possible actions...
FrontendOptions - Options for controlling the behavior of the frontend.
Run a plugin action,.
std::string StatsFile
Filename to write statistics to.
Parse ASTs and dump them.
std::vector< std::shared_ptr< ModuleFileExtension > > ModuleFileExtensions
The list of module file extensions.
CodeCompleteOptions CodeCompleteOpts
std::vector< std::string > AddPluginActions
The list of plugin actions to run in addition to the normal action.
unsigned DisableFree
Disable memory freeing on exit.
Generate pre-compiled header.
Generate pre-compiled module from a set of header files.
bool isUnknown() const
Is the input kind fully-unknown?
unsigned ASTDumpDecls
Whether we include declaration dumps in AST dumps.
std::string ActionName
The name of the action to run when using a plugin action.
Run one or more source code analyses.
std::vector< std::string > LLVMArgs
A list of arguments to forward to LLVM&#39;s option processing; this should only be used for debugging an...
Dump information about a module file.
FrontendInputFile(const llvm::MemoryBuffer *Buffer, InputKind Kind, bool IsSystem=false)
#define true
Definition: stdbool.h:16
std::vector< std::string > ModuleMapFiles
The list of module map files to load before processing the input.