• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===--- FrontendOptions.h --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
11 #define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
12 
13 #include "clang/Frontend/CommandLineSourceLoc.h"
14 #include "clang/Sema/CodeCompleteOptions.h"
15 #include "llvm/ADT/StringRef.h"
16 #include <string>
17 #include <vector>
18 
19 namespace llvm {
20 class MemoryBuffer;
21 }
22 
23 namespace clang {
24 
25 namespace frontend {
26   enum ActionKind {
27     ASTDeclList,            ///< Parse ASTs and list Decl nodes.
28     ASTDump,                ///< Parse ASTs and dump them.
29     ASTDumpXML,             ///< Parse ASTs and dump them in XML.
30     ASTPrint,               ///< Parse ASTs and print them.
31     ASTView,                ///< Parse ASTs and view them in Graphviz.
32     DumpRawTokens,          ///< Dump out raw tokens.
33     DumpTokens,             ///< Dump out preprocessed tokens.
34     EmitAssembly,           ///< Emit a .s file.
35     EmitBC,                 ///< Emit a .bc file.
36     EmitHTML,               ///< Translate input source into HTML.
37     EmitLLVM,               ///< Emit a .ll file.
38     EmitLLVMOnly,           ///< Generate LLVM IR, but do not emit anything.
39     EmitCodeGenOnly,        ///< Generate machine code, but don't emit anything.
40     EmitObj,                ///< Emit a .o file.
41     FixIt,                  ///< Parse and apply any fixits to the source.
42     GenerateModule,         ///< Generate pre-compiled module.
43     GeneratePCH,            ///< Generate pre-compiled header.
44     GeneratePTH,            ///< Generate pre-tokenized header.
45     InitOnly,               ///< Only execute frontend initialization.
46     ParseSyntaxOnly,        ///< Parse and perform semantic analysis.
47     PluginAction,           ///< Run a plugin action, \see ActionName.
48     PrintDeclContext,       ///< Print DeclContext and their Decls.
49     PrintPreamble,          ///< Print the "preamble" of the input file
50     PrintPreprocessedInput, ///< -E mode.
51     RewriteMacros,          ///< Expand macros but not \#includes.
52     RewriteObjC,            ///< ObjC->C Rewriter.
53     RewriteTest,            ///< Rewriter playground
54     RunAnalysis,            ///< Run one or more source code analyses.
55     MigrateSource,          ///< Run migrator.
56     RunPreprocessorOnly     ///< Just lex, no output.
57   };
58 }
59 
60 enum InputKind {
61   IK_None,
62   IK_Asm,
63   IK_C,
64   IK_CXX,
65   IK_ObjC,
66   IK_ObjCXX,
67   IK_PreprocessedC,
68   IK_PreprocessedCXX,
69   IK_PreprocessedObjC,
70   IK_PreprocessedObjCXX,
71   IK_OpenCL,
72   IK_CUDA,
73   IK_AST,
74   IK_LLVM_IR
75 };
76 
77 
78 /// \brief An input file for the front end.
79 class FrontendInputFile {
80   /// \brief The file name, or "-" to read from standard input.
81   std::string File;
82 
83   llvm::MemoryBuffer *Buffer;
84 
85   /// \brief The kind of input, e.g., C source, AST file, LLVM IR.
86   InputKind Kind;
87 
88   /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input).
89   bool IsSystem;
90 
91 public:
FrontendInputFile()92   FrontendInputFile() : Buffer(0), Kind(IK_None) { }
93   FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
94     : File(File.str()), Buffer(0), Kind(Kind), IsSystem(IsSystem) { }
95   FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind,
96                     bool IsSystem = false)
Buffer(buffer)97     : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { }
98 
getKind()99   InputKind getKind() const { return Kind; }
isSystem()100   bool isSystem() const { return IsSystem; }
101 
isEmpty()102   bool isEmpty() const { return File.empty() && Buffer == 0; }
isFile()103   bool isFile() const { return !isBuffer(); }
isBuffer()104   bool isBuffer() const { return Buffer != 0; }
105 
getFile()106   StringRef getFile() const {
107     assert(isFile());
108     return File;
109   }
getBuffer()110   llvm::MemoryBuffer *getBuffer() const {
111     assert(isBuffer());
112     return Buffer;
113   }
114 };
115 
116 /// FrontendOptions - Options for controlling the behavior of the frontend.
117 class FrontendOptions {
118 public:
119   unsigned DisableFree : 1;                ///< Disable memory freeing on exit.
120   unsigned RelocatablePCH : 1;             ///< When generating PCH files,
121                                            /// instruct the AST writer to create
122                                            /// relocatable PCH files.
123   unsigned ShowHelp : 1;                   ///< Show the -help text.
124   unsigned ShowStats : 1;                  ///< Show frontend performance
125                                            /// metrics and statistics.
126   unsigned ShowTimers : 1;                 ///< Show timers for individual
127                                            /// actions.
128   unsigned ShowVersion : 1;                ///< Show the -version text.
129   unsigned FixWhatYouCan : 1;              ///< Apply fixes even if there are
130                                            /// unfixable errors.
131   unsigned FixOnlyWarnings : 1;            ///< Apply fixes only for warnings.
132   unsigned FixAndRecompile : 1;            ///< Apply fixes and recompile.
133   unsigned FixToTemporaries : 1;           ///< Apply fixes to temporary files.
134   unsigned ARCMTMigrateEmitARCErrors : 1;  /// Emit ARC errors even if the
135                                            /// migrator can fix them
136   unsigned SkipFunctionBodies : 1;         ///< Skip over function bodies to
137                                            /// speed up parsing in cases you do
138                                            /// not need them (e.g. with code
139                                            /// completion).
140   unsigned UseGlobalModuleIndex : 1;       ///< Whether we can use the
141                                            ///< global module index if available.
142   unsigned GenerateGlobalModuleIndex : 1;  ///< Whether we can generate the
143                                            ///< global module index if needed.
144 
145   CodeCompleteOptions CodeCompleteOpts;
146 
147   enum {
148     ARCMT_None,
149     ARCMT_Check,
150     ARCMT_Modify,
151     ARCMT_Migrate
152   } ARCMTAction;
153 
154   enum {
155     ObjCMT_None = 0,
156     /// \brief Enable migration to modern ObjC literals.
157     ObjCMT_Literals = 0x1,
158     /// \brief Enable migration to modern ObjC subscripting.
159     ObjCMT_Subscripting = 0x2
160   };
161   unsigned ObjCMTAction;
162 
163   std::string MTMigrateDir;
164   std::string ARCMTMigrateReportOut;
165 
166   /// The input files and their types.
167   std::vector<FrontendInputFile> Inputs;
168 
169   /// The output file, if any.
170   std::string OutputFile;
171 
172   /// If given, the new suffix for fix-it rewritten files.
173   std::string FixItSuffix;
174 
175   /// If given, filter dumped AST Decl nodes by this substring.
176   std::string ASTDumpFilter;
177 
178   /// If given, enable code completion at the provided location.
179   ParsedSourceLocation CodeCompletionAt;
180 
181   /// The frontend action to perform.
182   frontend::ActionKind ProgramAction;
183 
184   /// The name of the action to run when using a plugin action.
185   std::string ActionName;
186 
187   /// Args to pass to the plugin
188   std::vector<std::string> PluginArgs;
189 
190   /// The list of plugin actions to run in addition to the normal action.
191   std::vector<std::string> AddPluginActions;
192 
193   /// Args to pass to the additional plugins
194   std::vector<std::vector<std::string> > AddPluginArgs;
195 
196   /// The list of plugins to load.
197   std::vector<std::string> Plugins;
198 
199   /// \brief The list of AST files to merge.
200   std::vector<std::string> ASTMergeFiles;
201 
202   /// \brief A list of arguments to forward to LLVM's option processing; this
203   /// should only be used for debugging and experimental features.
204   std::vector<std::string> LLVMArgs;
205 
206   /// \brief File name of the file that will provide record layouts
207   /// (in the format produced by -fdump-record-layouts).
208   std::string OverrideRecordLayoutsFile;
209 
210 public:
FrontendOptions()211   FrontendOptions() :
212     DisableFree(false), RelocatablePCH(false), ShowHelp(false),
213     ShowStats(false), ShowTimers(false), ShowVersion(false),
214     FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
215     FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
216     SkipFunctionBodies(false), UseGlobalModuleIndex(true),
217     GenerateGlobalModuleIndex(true),
218     ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None),
219     ProgramAction(frontend::ParseSyntaxOnly)
220   {}
221 
222   /// getInputKindForExtension - Return the appropriate input kind for a file
223   /// extension. For example, "c" would return IK_C.
224   ///
225   /// \return The input kind for the extension, or IK_None if the extension is
226   /// not recognized.
227   static InputKind getInputKindForExtension(StringRef Extension);
228 };
229 
230 }  // end namespace clang
231 
232 #endif
233