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