]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/FrontendOptions.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / clang / include / clang / Frontend / FrontendOptions.h
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     ModuleFileInfo,         ///< Dump information about a module file.
47     ParseSyntaxOnly,        ///< Parse and perform semantic analysis.
48     PluginAction,           ///< Run a plugin action, \see ActionName.
49     PrintDeclContext,       ///< Print DeclContext and their Decls.
50     PrintPreamble,          ///< Print the "preamble" of the input file
51     PrintPreprocessedInput, ///< -E mode.
52     RewriteMacros,          ///< Expand macros but not \#includes.
53     RewriteObjC,            ///< ObjC->C Rewriter.
54     RewriteTest,            ///< Rewriter playground
55     RunAnalysis,            ///< Run one or more source code analyses.
56     MigrateSource,          ///< Run migrator.
57     RunPreprocessorOnly     ///< Just lex, no output.
58   };
59 }
60
61 enum InputKind {
62   IK_None,
63   IK_Asm,
64   IK_C,
65   IK_CXX,
66   IK_ObjC,
67   IK_ObjCXX,
68   IK_PreprocessedC,
69   IK_PreprocessedCXX,
70   IK_PreprocessedObjC,
71   IK_PreprocessedObjCXX,
72   IK_OpenCL,
73   IK_CUDA,
74   IK_AST,
75   IK_LLVM_IR
76 };
77
78   
79 /// \brief An input file for the front end.
80 class FrontendInputFile {
81   /// \brief The file name, or "-" to read from standard input.
82   std::string File;
83
84   llvm::MemoryBuffer *Buffer;
85
86   /// \brief The kind of input, e.g., C source, AST file, LLVM IR.
87   InputKind Kind;
88
89   /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input).
90   bool IsSystem;
91
92 public:
93   FrontendInputFile() : Buffer(0), Kind(IK_None) { }
94   FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
95     : File(File.str()), Buffer(0), Kind(Kind), IsSystem(IsSystem) { }
96   FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind,
97                     bool IsSystem = false)
98     : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { }
99
100   InputKind getKind() const { return Kind; }
101   bool isSystem() const { return IsSystem; }
102
103   bool isEmpty() const { return File.empty() && Buffer == 0; }
104   bool isFile() const { return !isBuffer(); }
105   bool isBuffer() const { return Buffer != 0; }
106
107   StringRef getFile() const {
108     assert(isFile());
109     return File;
110   }
111   llvm::MemoryBuffer *getBuffer() const {
112     assert(isBuffer());
113     return Buffer;
114   }
115 };
116
117 /// FrontendOptions - Options for controlling the behavior of the frontend.
118 class FrontendOptions {
119 public:
120   unsigned DisableFree : 1;                ///< Disable memory freeing on exit.
121   unsigned RelocatablePCH : 1;             ///< When generating PCH files,
122                                            /// instruct the AST writer to create
123                                            /// relocatable PCH files.
124   unsigned ShowHelp : 1;                   ///< Show the -help text.
125   unsigned ShowStats : 1;                  ///< Show frontend performance
126                                            /// metrics and statistics.
127   unsigned ShowTimers : 1;                 ///< Show timers for individual
128                                            /// actions.
129   unsigned ShowVersion : 1;                ///< Show the -version text.
130   unsigned FixWhatYouCan : 1;              ///< Apply fixes even if there are
131                                            /// unfixable errors.
132   unsigned FixOnlyWarnings : 1;            ///< Apply fixes only for warnings.
133   unsigned FixAndRecompile : 1;            ///< Apply fixes and recompile.
134   unsigned FixToTemporaries : 1;           ///< Apply fixes to temporary files.
135   unsigned ARCMTMigrateEmitARCErrors : 1;  /// Emit ARC errors even if the
136                                            /// migrator can fix them
137   unsigned SkipFunctionBodies : 1;         ///< Skip over function bodies to
138                                            /// speed up parsing in cases you do
139                                            /// not need them (e.g. with code
140                                            /// completion).
141   unsigned UseGlobalModuleIndex : 1;       ///< Whether we can use the
142                                            ///< global module index if available.
143   unsigned GenerateGlobalModuleIndex : 1;  ///< Whether we can generate the
144                                            ///< global module index if needed.
145
146   CodeCompleteOptions CodeCompleteOpts;
147
148   enum {
149     ARCMT_None,
150     ARCMT_Check,
151     ARCMT_Modify,
152     ARCMT_Migrate
153   } ARCMTAction;
154
155   enum {
156     ObjCMT_None = 0,
157     /// \brief Enable migration to modern ObjC literals.
158     ObjCMT_Literals = 0x1,
159     /// \brief Enable migration to modern ObjC subscripting.
160     ObjCMT_Subscripting = 0x2
161   };
162   unsigned ObjCMTAction;
163
164   std::string MTMigrateDir;
165   std::string ARCMTMigrateReportOut;
166
167   /// The input files and their types.
168   std::vector<FrontendInputFile> Inputs;
169
170   /// The output file, if any.
171   std::string OutputFile;
172
173   /// If given, the new suffix for fix-it rewritten files.
174   std::string FixItSuffix;
175
176   /// If given, filter dumped AST Decl nodes by this substring.
177   std::string ASTDumpFilter;
178
179   /// If given, enable code completion at the provided location.
180   ParsedSourceLocation CodeCompletionAt;
181
182   /// The frontend action to perform.
183   frontend::ActionKind ProgramAction;
184
185   /// The name of the action to run when using a plugin action.
186   std::string ActionName;
187
188   /// Args to pass to the plugin
189   std::vector<std::string> PluginArgs;
190
191   /// The list of plugin actions to run in addition to the normal action.
192   std::vector<std::string> AddPluginActions;
193
194   /// Args to pass to the additional plugins
195   std::vector<std::vector<std::string> > AddPluginArgs;
196
197   /// The list of plugins to load.
198   std::vector<std::string> Plugins;
199
200   /// \brief The list of AST files to merge.
201   std::vector<std::string> ASTMergeFiles;
202
203   /// \brief A list of arguments to forward to LLVM's option processing; this
204   /// should only be used for debugging and experimental features.
205   std::vector<std::string> LLVMArgs;
206
207   /// \brief File name of the file that will provide record layouts
208   /// (in the format produced by -fdump-record-layouts).
209   std::string OverrideRecordLayoutsFile;
210   
211 public:
212   FrontendOptions() :
213     DisableFree(false), RelocatablePCH(false), ShowHelp(false),
214     ShowStats(false), ShowTimers(false), ShowVersion(false),
215     FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
216     FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
217     SkipFunctionBodies(false), UseGlobalModuleIndex(true),
218     GenerateGlobalModuleIndex(true),
219     ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None),
220     ProgramAction(frontend::ParseSyntaxOnly)
221   {}
222
223   /// getInputKindForExtension - Return the appropriate input kind for a file
224   /// extension. For example, "c" would return IK_C.
225   ///
226   /// \return The input kind for the extension, or IK_None if the extension is
227   /// not recognized.
228   static InputKind getInputKindForExtension(StringRef Extension);
229 };
230
231 }  // end namespace clang
232
233 #endif