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