FrontendOptions.h revision 61d679ab2831b161c857cf3f974312fbd4ef1efd
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    RewriteMacros,          ///< Expand macros but not #includes.
46    RewriteObjC,            ///< ObjC->C Rewriter.
47    RewriteTest,            ///< Rewriter playground
48    RunAnalysis,            ///< Run one or more source code analyses.
49    RunPreprocessorOnly     ///< Just lex, no output.
50  };
51}
52
53enum InputKind {
54  IK_None,
55  IK_Asm,
56  IK_C,
57  IK_CXX,
58  IK_ObjC,
59  IK_ObjCXX,
60  IK_PreprocessedC,
61  IK_PreprocessedCXX,
62  IK_PreprocessedObjC,
63  IK_PreprocessedObjCXX,
64  IK_OpenCL,
65  IK_CUDA,
66  IK_AST,
67  IK_LLVM_IR
68};
69
70
71/// \brief An input file for the front end.
72struct FrontendInputFile {
73  /// \brief The file name, or "-" to read from standard input.
74  std::string File;
75
76  /// \brief The kind of input, e.g., C source, AST file, LLVM IR.
77  InputKind Kind;
78
79  FrontendInputFile() : Kind(IK_None) { }
80  FrontendInputFile(StringRef File, InputKind Kind)
81    : File(File.str()), Kind(Kind) { }
82};
83
84/// FrontendOptions - Options for controlling the behavior of the frontend.
85class FrontendOptions {
86public:
87  unsigned DisableFree : 1;                ///< Disable memory freeing on exit.
88  unsigned RelocatablePCH : 1;             ///< When generating PCH files,
89                                           /// instruct the AST writer to create
90                                           /// relocatable PCH files.
91  unsigned ShowHelp : 1;                   ///< Show the -help text.
92  unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion
93                                           /// results.
94  unsigned ShowCodePatternsInCodeCompletion : 1; ///< Show code patterns in code
95                                                 /// completion results.
96  unsigned ShowGlobalSymbolsInCodeCompletion : 1; ///< Show top-level decls in
97                                                  /// code completion results.
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
111  enum {
112    ARCMT_None,
113    ARCMT_Check,
114    ARCMT_Modify,
115    ARCMT_Migrate
116  } ARCMTAction;
117
118  std::string ARCMTMigrateDir;
119  std::string ARCMTMigrateReportOut;
120
121  /// The input files and their types.
122  std::vector<FrontendInputFile> Inputs;
123
124  /// The output file, if any.
125  std::string OutputFile;
126
127  /// If given, the new suffix for fix-it rewritten files.
128  std::string FixItSuffix;
129
130  /// If given, enable code completion at the provided location.
131  ParsedSourceLocation CodeCompletionAt;
132
133  /// The frontend action to perform.
134  frontend::ActionKind ProgramAction;
135
136  /// The name of the action to run when using a plugin action.
137  std::string ActionName;
138
139  /// Args to pass to the plugin
140  std::vector<std::string> PluginArgs;
141
142  /// The list of plugin actions to run in addition to the normal action.
143  std::vector<std::string> AddPluginActions;
144
145  /// Args to pass to the additional plugins
146  std::vector<std::vector<std::string> > AddPluginArgs;
147
148  /// The list of plugins to load.
149  std::vector<std::string> Plugins;
150
151  /// \brief The list of AST files to merge.
152  std::vector<std::string> ASTMergeFiles;
153
154  /// \brief A list of arguments to forward to LLVM's option processing; this
155  /// should only be used for debugging and experimental features.
156  std::vector<std::string> LLVMArgs;
157
158public:
159  FrontendOptions() {
160    DisableFree = 0;
161    ProgramAction = frontend::ParseSyntaxOnly;
162    ActionName = "";
163    RelocatablePCH = 0;
164    ShowHelp = 0;
165    ShowMacrosInCodeCompletion = 0;
166    ShowCodePatternsInCodeCompletion = 0;
167    ShowGlobalSymbolsInCodeCompletion = 1;
168    ShowStats = 0;
169    ShowTimers = 0;
170    ShowVersion = 0;
171    ARCMTAction = ARCMT_None;
172    ARCMTMigrateEmitARCErrors = 0;
173  }
174
175  /// getInputKindForExtension - Return the appropriate input kind for a file
176  /// extension. For example, "c" would return IK_C.
177  ///
178  /// \return The input kind for the extension, or IK_None if the extension is
179  /// not recognized.
180  static InputKind getInputKindForExtension(StringRef Extension);
181};
182
183}  // end namespace clang
184
185#endif
186