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