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/Serialization/ModuleFileExtension.h" 15 #include "clang/Sema/CodeCompleteOptions.h" 16 #include "llvm/ADT/StringRef.h" 17 #include <string> 18 #include <vector> 19 #include <unordered_map> 20 21 namespace llvm { 22 class MemoryBuffer; 23 } 24 25 namespace clang { 26 27 namespace frontend { 28 enum ActionKind { 29 ASTDeclList, ///< Parse ASTs and list Decl nodes. 30 ASTDump, ///< Parse ASTs and dump them. 31 ASTPrint, ///< Parse ASTs and print them. 32 ASTView, ///< Parse ASTs and view them in Graphviz. 33 DumpRawTokens, ///< Dump out raw tokens. 34 DumpTokens, ///< Dump out preprocessed tokens. 35 EmitAssembly, ///< Emit a .s file. 36 EmitBC, ///< Emit a .bc file. 37 EmitHTML, ///< Translate input source into HTML. 38 EmitLLVM, ///< Emit a .ll file. 39 EmitLLVMOnly, ///< Generate LLVM IR, but do not emit anything. 40 EmitCodeGenOnly, ///< Generate machine code, but don't emit anything. 41 EmitObj, ///< Emit a .o file. 42 FixIt, ///< Parse and apply any fixits to the source. 43 GenerateModule, ///< Generate pre-compiled module from a module map. 44 GenerateModuleInterface,///< Generate pre-compiled module from a C++ module 45 ///< interface file. 46 GeneratePCH, ///< Generate pre-compiled header. 47 GeneratePTH, ///< Generate pre-tokenized header. 48 InitOnly, ///< Only execute frontend initialization. 49 ModuleFileInfo, ///< Dump information about a module file. 50 VerifyPCH, ///< Load and verify that a PCH file is usable. 51 ParseSyntaxOnly, ///< Parse and perform semantic analysis. 52 PluginAction, ///< Run a plugin action, \see ActionName. 53 PrintDeclContext, ///< Print DeclContext and their Decls. 54 PrintPreamble, ///< Print the "preamble" of the input file 55 PrintPreprocessedInput, ///< -E mode. 56 RewriteMacros, ///< Expand macros but not \#includes. 57 RewriteObjC, ///< ObjC->C Rewriter. 58 RewriteTest, ///< Rewriter playground 59 RunAnalysis, ///< Run one or more source code analyses. 60 MigrateSource, ///< Run migrator. 61 RunPreprocessorOnly ///< Just lex, no output. 62 }; 63 } 64 65 enum InputKind { 66 IK_None, 67 IK_Asm, 68 IK_C, 69 IK_CXX, 70 IK_ObjC, 71 IK_ObjCXX, 72 IK_PreprocessedC, 73 IK_PreprocessedCXX, 74 IK_PreprocessedObjC, 75 IK_PreprocessedObjCXX, 76 IK_OpenCL, 77 IK_CUDA, 78 IK_PreprocessedCuda, 79 IK_RenderScript, 80 IK_AST, 81 IK_LLVM_IR 82 }; 83 84 85 /// \brief An input file for the front end. 86 class FrontendInputFile { 87 /// \brief The file name, or "-" to read from standard input. 88 std::string File; 89 90 llvm::MemoryBuffer *Buffer; 91 92 /// \brief The kind of input, e.g., C source, AST file, LLVM IR. 93 InputKind Kind; 94 95 /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input). 96 bool IsSystem; 97 98 public: 99 FrontendInputFile() : Buffer(nullptr), Kind(IK_None), IsSystem(false) { } 100 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) 101 : File(File.str()), Buffer(nullptr), Kind(Kind), IsSystem(IsSystem) { } 102 FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind, 103 bool IsSystem = false) 104 : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { } 105 106 InputKind getKind() const { return Kind; } 107 bool isSystem() const { return IsSystem; } 108 109 bool isEmpty() const { return File.empty() && Buffer == nullptr; } 110 bool isFile() const { return !isBuffer(); } 111 bool isBuffer() const { return Buffer != nullptr; } 112 bool isPreprocessed() const { 113 return Kind == IK_PreprocessedC || 114 Kind == IK_PreprocessedCXX || 115 Kind == IK_PreprocessedObjC || 116 Kind == IK_PreprocessedObjCXX || 117 Kind == IK_PreprocessedCuda; 118 } 119 120 StringRef getFile() const { 121 assert(isFile()); 122 return File; 123 } 124 llvm::MemoryBuffer *getBuffer() const { 125 assert(isBuffer()); 126 return Buffer; 127 } 128 }; 129 130 /// FrontendOptions - Options for controlling the behavior of the frontend. 131 class FrontendOptions { 132 public: 133 unsigned DisableFree : 1; ///< Disable memory freeing on exit. 134 unsigned RelocatablePCH : 1; ///< When generating PCH files, 135 /// instruct the AST writer to create 136 /// relocatable PCH files. 137 unsigned ShowHelp : 1; ///< Show the -help text. 138 unsigned ShowStats : 1; ///< Show frontend performance 139 /// metrics and statistics. 140 unsigned ShowTimers : 1; ///< Show timers for individual 141 /// actions. 142 unsigned ShowVersion : 1; ///< Show the -version text. 143 unsigned FixWhatYouCan : 1; ///< Apply fixes even if there are 144 /// unfixable errors. 145 unsigned FixOnlyWarnings : 1; ///< Apply fixes only for warnings. 146 unsigned FixAndRecompile : 1; ///< Apply fixes and recompile. 147 unsigned FixToTemporaries : 1; ///< Apply fixes to temporary files. 148 unsigned ARCMTMigrateEmitARCErrors : 1; /// Emit ARC errors even if the 149 /// migrator can fix them 150 unsigned SkipFunctionBodies : 1; ///< Skip over function bodies to 151 /// speed up parsing in cases you do 152 /// not need them (e.g. with code 153 /// completion). 154 unsigned UseGlobalModuleIndex : 1; ///< Whether we can use the 155 ///< global module index if available. 156 unsigned GenerateGlobalModuleIndex : 1; ///< Whether we can generate the 157 ///< global module index if needed. 158 unsigned ASTDumpDecls : 1; ///< Whether we include declaration 159 ///< dumps in AST dumps. 160 unsigned ASTDumpAll : 1; ///< Whether we deserialize all decls 161 ///< when forming AST dumps. 162 unsigned ASTDumpLookups : 1; ///< Whether we include lookup table 163 ///< dumps in AST dumps. 164 unsigned BuildingImplicitModule : 1; ///< Whether we are performing an 165 ///< implicit module build. 166 unsigned ModulesEmbedAllFiles : 1; ///< Whether we should embed all used 167 ///< files into the PCM file. 168 unsigned IncludeTimestamps : 1; ///< Whether timestamps should be 169 ///< written to the produced PCH file. 170 171 CodeCompleteOptions CodeCompleteOpts; 172 173 enum { 174 ARCMT_None, 175 ARCMT_Check, 176 ARCMT_Modify, 177 ARCMT_Migrate 178 } ARCMTAction; 179 180 enum { 181 ObjCMT_None = 0, 182 /// \brief Enable migration to modern ObjC literals. 183 ObjCMT_Literals = 0x1, 184 /// \brief Enable migration to modern ObjC subscripting. 185 ObjCMT_Subscripting = 0x2, 186 /// \brief Enable migration to modern ObjC readonly property. 187 ObjCMT_ReadonlyProperty = 0x4, 188 /// \brief Enable migration to modern ObjC readwrite property. 189 ObjCMT_ReadwriteProperty = 0x8, 190 /// \brief Enable migration to modern ObjC property. 191 ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty), 192 /// \brief Enable annotation of ObjCMethods of all kinds. 193 ObjCMT_Annotation = 0x10, 194 /// \brief Enable migration of ObjC methods to 'instancetype'. 195 ObjCMT_Instancetype = 0x20, 196 /// \brief Enable migration to NS_ENUM/NS_OPTIONS macros. 197 ObjCMT_NsMacros = 0x40, 198 /// \brief Enable migration to add conforming protocols. 199 ObjCMT_ProtocolConformance = 0x80, 200 /// \brief prefer 'atomic' property over 'nonatomic'. 201 ObjCMT_AtomicProperty = 0x100, 202 /// \brief annotate property with NS_RETURNS_INNER_POINTER 203 ObjCMT_ReturnsInnerPointerProperty = 0x200, 204 /// \brief use NS_NONATOMIC_IOSONLY for property 'atomic' attribute 205 ObjCMT_NsAtomicIOSOnlyProperty = 0x400, 206 /// \brief Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods. 207 ObjCMT_DesignatedInitializer = 0x800, 208 /// \brief Enable converting setter/getter expressions to property-dot syntx. 209 ObjCMT_PropertyDotSyntax = 0x1000, 210 ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | 211 ObjCMT_Annotation | ObjCMT_Instancetype | 212 ObjCMT_NsMacros | ObjCMT_ProtocolConformance | 213 ObjCMT_NsAtomicIOSOnlyProperty | 214 ObjCMT_DesignatedInitializer), 215 ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | 216 ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax) 217 }; 218 unsigned ObjCMTAction; 219 std::string ObjCMTWhiteListPath; 220 221 std::string MTMigrateDir; 222 std::string ARCMTMigrateReportOut; 223 224 /// The input files and their types. 225 std::vector<FrontendInputFile> Inputs; 226 227 /// The output file, if any. 228 std::string OutputFile; 229 230 /// If given, the new suffix for fix-it rewritten files. 231 std::string FixItSuffix; 232 233 /// If given, filter dumped AST Decl nodes by this substring. 234 std::string ASTDumpFilter; 235 236 /// If given, enable code completion at the provided location. 237 ParsedSourceLocation CodeCompletionAt; 238 239 /// The frontend action to perform. 240 frontend::ActionKind ProgramAction; 241 242 /// The name of the action to run when using a plugin action. 243 std::string ActionName; 244 245 /// Args to pass to the plugins 246 std::unordered_map<std::string,std::vector<std::string>> PluginArgs; 247 248 /// The list of plugin actions to run in addition to the normal action. 249 std::vector<std::string> AddPluginActions; 250 251 /// The list of plugins to load. 252 std::vector<std::string> Plugins; 253 254 /// The list of module file extensions. 255 std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions; 256 257 /// \brief The list of module map files to load before processing the input. 258 std::vector<std::string> ModuleMapFiles; 259 260 /// \brief The list of additional prebuilt module files to load before 261 /// processing the input. 262 std::vector<std::string> ModuleFiles; 263 264 /// \brief The list of files to embed into the compiled module file. 265 std::vector<std::string> ModulesEmbedFiles; 266 267 /// \brief The list of AST files to merge. 268 std::vector<std::string> ASTMergeFiles; 269 270 /// \brief A list of arguments to forward to LLVM's option processing; this 271 /// should only be used for debugging and experimental features. 272 std::vector<std::string> LLVMArgs; 273 274 /// \brief File name of the file that will provide record layouts 275 /// (in the format produced by -fdump-record-layouts). 276 std::string OverrideRecordLayoutsFile; 277 278 /// \brief Auxiliary triple for CUDA compilation. 279 std::string AuxTriple; 280 281 /// \brief If non-empty, search the pch input file as it was a header 282 // included by this file. 283 std::string FindPchSource; 284 285 /// Filename to write statistics to. 286 std::string StatsFile; 287 288 public: 289 FrontendOptions() : 290 DisableFree(false), RelocatablePCH(false), ShowHelp(false), 291 ShowStats(false), ShowTimers(false), ShowVersion(false), 292 FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false), 293 FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false), 294 SkipFunctionBodies(false), UseGlobalModuleIndex(true), 295 GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false), 296 BuildingImplicitModule(false), ModulesEmbedAllFiles(false), 297 IncludeTimestamps(true), ARCMTAction(ARCMT_None), 298 ObjCMTAction(ObjCMT_None), ProgramAction(frontend::ParseSyntaxOnly) 299 {} 300 301 /// getInputKindForExtension - Return the appropriate input kind for a file 302 /// extension. For example, "c" would return IK_C. 303 /// 304 /// \return The input kind for the extension, or IK_None if the extension is 305 /// not recognized. 306 static InputKind getInputKindForExtension(StringRef Extension); 307 }; 308 309 } // end namespace clang 310 311 #endif 312