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 18 namespace clang { 19 20 namespace 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 MigrateSource, ///< Run migrator. 50 RunPreprocessorOnly ///< Just lex, no output. 51 }; 52 } 53 54 enum InputKind { 55 IK_None, 56 IK_Asm, 57 IK_C, 58 IK_CXX, 59 IK_ObjC, 60 IK_ObjCXX, 61 IK_PreprocessedC, 62 IK_PreprocessedCXX, 63 IK_PreprocessedObjC, 64 IK_PreprocessedObjCXX, 65 IK_OpenCL, 66 IK_CUDA, 67 IK_AST, 68 IK_LLVM_IR 69 }; 70 71 72 /// \brief An input file for the front end. 73 struct FrontendInputFile { 74 /// \brief The file name, or "-" to read from standard input. 75 std::string File; 76 77 /// \brief The kind of input, e.g., C source, AST file, LLVM IR. 78 InputKind Kind; 79 80 /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input). 81 bool IsSystem; 82 83 FrontendInputFile() : Kind(IK_None) { } 84 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) 85 : File(File.str()), Kind(Kind), IsSystem(IsSystem) { } 86 }; 87 88 /// FrontendOptions - Options for controlling the behavior of the frontend. 89 class FrontendOptions { 90 public: 91 unsigned DisableFree : 1; ///< Disable memory freeing on exit. 92 unsigned RelocatablePCH : 1; ///< When generating PCH files, 93 /// instruct the AST writer to create 94 /// relocatable PCH files. 95 unsigned ShowHelp : 1; ///< Show the -help text. 96 unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion 97 /// results. 98 unsigned ShowCodePatternsInCodeCompletion : 1; ///< Show code patterns in code 99 /// completion results. 100 unsigned ShowGlobalSymbolsInCodeCompletion : 1; ///< Show top-level decls in 101 /// code completion results. 102 unsigned ShowStats : 1; ///< Show frontend performance 103 /// metrics and statistics. 104 unsigned ShowTimers : 1; ///< Show timers for individual 105 /// actions. 106 unsigned ShowVersion : 1; ///< Show the -version text. 107 unsigned FixWhatYouCan : 1; ///< Apply fixes even if there are 108 /// unfixable errors. 109 unsigned FixOnlyWarnings : 1; ///< Apply fixes only for warnings. 110 unsigned FixAndRecompile : 1; ///< Apply fixes and recompile. 111 unsigned FixToTemporaries : 1; ///< Apply fixes to temporary files. 112 unsigned ARCMTMigrateEmitARCErrors : 1; /// Emit ARC errors even if the 113 /// migrator can fix them 114 unsigned SkipFunctionBodies : 1; ///< Skip over function bodies to 115 /// speed up parsing in cases you do 116 /// not need them (e.g. with code 117 /// completion). 118 119 enum { 120 ARCMT_None, 121 ARCMT_Check, 122 ARCMT_Modify, 123 ARCMT_Migrate 124 } ARCMTAction; 125 126 enum { 127 ObjCMT_None = 0, 128 /// \brief Enable migration to modern ObjC literals. 129 ObjCMT_Literals = 0x1, 130 /// \brief Enable migration to modern ObjC subscripting. 131 ObjCMT_Subscripting = 0x2 132 }; 133 unsigned ObjCMTAction; 134 135 std::string MTMigrateDir; 136 std::string ARCMTMigrateReportOut; 137 138 /// The input files and their types. 139 std::vector<FrontendInputFile> Inputs; 140 141 /// The output file, if any. 142 std::string OutputFile; 143 144 /// If given, the new suffix for fix-it rewritten files. 145 std::string FixItSuffix; 146 147 /// If given, enable code completion at the provided location. 148 ParsedSourceLocation CodeCompletionAt; 149 150 /// The frontend action to perform. 151 frontend::ActionKind ProgramAction; 152 153 /// The name of the action to run when using a plugin action. 154 std::string ActionName; 155 156 /// Args to pass to the plugin 157 std::vector<std::string> PluginArgs; 158 159 /// The list of plugin actions to run in addition to the normal action. 160 std::vector<std::string> AddPluginActions; 161 162 /// Args to pass to the additional plugins 163 std::vector<std::vector<std::string> > AddPluginArgs; 164 165 /// The list of plugins to load. 166 std::vector<std::string> Plugins; 167 168 /// \brief The list of AST files to merge. 169 std::vector<std::string> ASTMergeFiles; 170 171 /// \brief A list of arguments to forward to LLVM's option processing; this 172 /// should only be used for debugging and experimental features. 173 std::vector<std::string> LLVMArgs; 174 175 /// \brief File name of the file that will provide record layouts 176 /// (in the format produced by -fdump-record-layouts). 177 std::string OverrideRecordLayoutsFile; 178 179 public: 180 FrontendOptions() { 181 DisableFree = 0; 182 ProgramAction = frontend::ParseSyntaxOnly; 183 ActionName = ""; 184 RelocatablePCH = 0; 185 ShowHelp = 0; 186 ShowMacrosInCodeCompletion = 0; 187 ShowCodePatternsInCodeCompletion = 0; 188 ShowGlobalSymbolsInCodeCompletion = 1; 189 ShowStats = 0; 190 ShowTimers = 0; 191 ShowVersion = 0; 192 ARCMTAction = ARCMT_None; 193 ARCMTMigrateEmitARCErrors = 0; 194 SkipFunctionBodies = 0; 195 ObjCMTAction = ObjCMT_None; 196 } 197 198 /// getInputKindForExtension - Return the appropriate input kind for a file 199 /// extension. For example, "c" would return IK_C. 200 /// 201 /// \return The input kind for the extension, or IK_None if the extension is 202 /// not recognized. 203 static InputKind getInputKindForExtension(StringRef Extension); 204 }; 205 206 } // end namespace clang 207 208 #endif 209