1199482Srdivacky//===--- FrontendOptions.h --------------------------------------*- C++ -*-===// 2199482Srdivacky// 3199482Srdivacky// The LLVM Compiler Infrastructure 4199482Srdivacky// 5199482Srdivacky// This file is distributed under the University of Illinois Open Source 6199482Srdivacky// License. See LICENSE.TXT for details. 7199482Srdivacky// 8199482Srdivacky//===----------------------------------------------------------------------===// 9199482Srdivacky 10199482Srdivacky#ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H 11199482Srdivacky#define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H 12199482Srdivacky 13199482Srdivacky#include "clang/Frontend/CommandLineSourceLoc.h" 14239462Sdim#include "clang/Sema/CodeCompleteOptions.h" 15199482Srdivacky#include "llvm/ADT/StringRef.h" 16199482Srdivacky#include <string> 17199482Srdivacky#include <vector> 18199482Srdivacky 19243830Sdimnamespace llvm { 20243830Sdimclass MemoryBuffer; 21243830Sdim} 22243830Sdim 23199482Srdivackynamespace clang { 24199482Srdivacky 25199482Srdivackynamespace frontend { 26199482Srdivacky enum ActionKind { 27239462Sdim ASTDeclList, ///< Parse ASTs and list Decl nodes. 28199482Srdivacky ASTDump, ///< Parse ASTs and dump them. 29199482Srdivacky ASTPrint, ///< Parse ASTs and print them. 30199482Srdivacky ASTView, ///< Parse ASTs and view them in Graphviz. 31199482Srdivacky DumpRawTokens, ///< Dump out raw tokens. 32199482Srdivacky DumpTokens, ///< Dump out preprocessed tokens. 33199482Srdivacky EmitAssembly, ///< Emit a .s file. 34199482Srdivacky EmitBC, ///< Emit a .bc file. 35199482Srdivacky EmitHTML, ///< Translate input source into HTML. 36199482Srdivacky EmitLLVM, ///< Emit a .ll file. 37208600Srdivacky EmitLLVMOnly, ///< Generate LLVM IR, but do not emit anything. 38208600Srdivacky EmitCodeGenOnly, ///< Generate machine code, but don't emit anything. 39203955Srdivacky EmitObj, ///< Emit a .o file. 40199482Srdivacky FixIt, ///< Parse and apply any fixits to the source. 41226633Sdim GenerateModule, ///< Generate pre-compiled module. 42199482Srdivacky GeneratePCH, ///< Generate pre-compiled header. 43199482Srdivacky GeneratePTH, ///< Generate pre-tokenized header. 44205408Srdivacky InitOnly, ///< Only execute frontend initialization. 45249423Sdim ModuleFileInfo, ///< Dump information about a module file. 46199482Srdivacky ParseSyntaxOnly, ///< Parse and perform semantic analysis. 47199482Srdivacky PluginAction, ///< Run a plugin action, \see ActionName. 48199482Srdivacky PrintDeclContext, ///< Print DeclContext and their Decls. 49212904Sdim PrintPreamble, ///< Print the "preamble" of the input file 50199482Srdivacky PrintPreprocessedInput, ///< -E mode. 51239462Sdim RewriteMacros, ///< Expand macros but not \#includes. 52199482Srdivacky RewriteObjC, ///< ObjC->C Rewriter. 53199482Srdivacky RewriteTest, ///< Rewriter playground 54199482Srdivacky RunAnalysis, ///< Run one or more source code analyses. 55234353Sdim MigrateSource, ///< Run migrator. 56199482Srdivacky RunPreprocessorOnly ///< Just lex, no output. 57199482Srdivacky }; 58199482Srdivacky} 59199482Srdivacky 60234353Sdimenum InputKind { 61234353Sdim IK_None, 62234353Sdim IK_Asm, 63234353Sdim IK_C, 64234353Sdim IK_CXX, 65234353Sdim IK_ObjC, 66234353Sdim IK_ObjCXX, 67234353Sdim IK_PreprocessedC, 68234353Sdim IK_PreprocessedCXX, 69234353Sdim IK_PreprocessedObjC, 70234353Sdim IK_PreprocessedObjCXX, 71234353Sdim IK_OpenCL, 72234353Sdim IK_CUDA, 73234353Sdim IK_AST, 74234353Sdim IK_LLVM_IR 75234353Sdim}; 76234353Sdim 77234353Sdim 78234353Sdim/// \brief An input file for the front end. 79243830Sdimclass FrontendInputFile { 80234353Sdim /// \brief The file name, or "-" to read from standard input. 81234353Sdim std::string File; 82234353Sdim 83243830Sdim llvm::MemoryBuffer *Buffer; 84243830Sdim 85234353Sdim /// \brief The kind of input, e.g., C source, AST file, LLVM IR. 86234353Sdim InputKind Kind; 87234353Sdim 88234353Sdim /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input). 89234353Sdim bool IsSystem; 90243830Sdim 91243830Sdimpublic: 92243830Sdim FrontendInputFile() : Buffer(0), Kind(IK_None) { } 93234353Sdim FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) 94243830Sdim : File(File.str()), Buffer(0), Kind(Kind), IsSystem(IsSystem) { } 95243830Sdim FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind, 96243830Sdim bool IsSystem = false) 97243830Sdim : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { } 98243830Sdim 99243830Sdim InputKind getKind() const { return Kind; } 100243830Sdim bool isSystem() const { return IsSystem; } 101243830Sdim 102243830Sdim bool isEmpty() const { return File.empty() && Buffer == 0; } 103243830Sdim bool isFile() const { return !isBuffer(); } 104243830Sdim bool isBuffer() const { return Buffer != 0; } 105243830Sdim 106243830Sdim StringRef getFile() const { 107243830Sdim assert(isFile()); 108243830Sdim return File; 109243830Sdim } 110243830Sdim llvm::MemoryBuffer *getBuffer() const { 111243830Sdim assert(isBuffer()); 112243830Sdim return Buffer; 113243830Sdim } 114234353Sdim}; 115239462Sdim 116199482Srdivacky/// FrontendOptions - Options for controlling the behavior of the frontend. 117199482Srdivackyclass FrontendOptions { 118199482Srdivackypublic: 119199482Srdivacky unsigned DisableFree : 1; ///< Disable memory freeing on exit. 120199482Srdivacky unsigned RelocatablePCH : 1; ///< When generating PCH files, 121212904Sdim /// instruct the AST writer to create 122199482Srdivacky /// relocatable PCH files. 123200583Srdivacky unsigned ShowHelp : 1; ///< Show the -help text. 124199482Srdivacky unsigned ShowStats : 1; ///< Show frontend performance 125199482Srdivacky /// metrics and statistics. 126199482Srdivacky unsigned ShowTimers : 1; ///< Show timers for individual 127199482Srdivacky /// actions. 128200583Srdivacky unsigned ShowVersion : 1; ///< Show the -version text. 129212904Sdim unsigned FixWhatYouCan : 1; ///< Apply fixes even if there are 130212904Sdim /// unfixable errors. 131234353Sdim unsigned FixOnlyWarnings : 1; ///< Apply fixes only for warnings. 132234353Sdim unsigned FixAndRecompile : 1; ///< Apply fixes and recompile. 133234353Sdim unsigned FixToTemporaries : 1; ///< Apply fixes to temporary files. 134226633Sdim unsigned ARCMTMigrateEmitARCErrors : 1; /// Emit ARC errors even if the 135226633Sdim /// migrator can fix them 136234353Sdim unsigned SkipFunctionBodies : 1; ///< Skip over function bodies to 137234353Sdim /// speed up parsing in cases you do 138234353Sdim /// not need them (e.g. with code 139234353Sdim /// completion). 140249423Sdim unsigned UseGlobalModuleIndex : 1; ///< Whether we can use the 141249423Sdim ///< global module index if available. 142249423Sdim unsigned GenerateGlobalModuleIndex : 1; ///< Whether we can generate the 143249423Sdim ///< global module index if needed. 144263508Sdim unsigned ASTDumpLookups : 1; ///< Whether we include lookup table 145263508Sdim ///< dumps in AST dumps. 146199482Srdivacky 147239462Sdim CodeCompleteOptions CodeCompleteOpts; 148239462Sdim 149224145Sdim enum { 150224145Sdim ARCMT_None, 151224145Sdim ARCMT_Check, 152224145Sdim ARCMT_Modify, 153224145Sdim ARCMT_Migrate 154224145Sdim } ARCMTAction; 155224145Sdim 156234353Sdim enum { 157234353Sdim ObjCMT_None = 0, 158234353Sdim /// \brief Enable migration to modern ObjC literals. 159234353Sdim ObjCMT_Literals = 0x1, 160234353Sdim /// \brief Enable migration to modern ObjC subscripting. 161263508Sdim ObjCMT_Subscripting = 0x2, 162263508Sdim /// \brief Enable migration to modern ObjC readonly property. 163263508Sdim ObjCMT_ReadonlyProperty = 0x4, 164263508Sdim /// \brief Enable migration to modern ObjC readwrite property. 165263508Sdim ObjCMT_ReadwriteProperty = 0x8, 166263508Sdim /// \brief Enable migration to modern ObjC property. 167263508Sdim ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty), 168263508Sdim /// \brief Enable annotation of ObjCMethods of all kinds. 169263508Sdim ObjCMT_Annotation = 0x10, 170263508Sdim /// \brief Enable migration of ObjC methods to 'instancetype'. 171263508Sdim ObjCMT_Instancetype = 0x20, 172263508Sdim /// \brief Enable migration to NS_ENUM/NS_OPTIONS macros. 173263508Sdim ObjCMT_NsMacros = 0x40, 174263508Sdim /// \brief Enable migration to add conforming protocols. 175263508Sdim ObjCMT_ProtocolConformance = 0x80, 176263508Sdim /// \brief prefer 'atomic' property over 'nonatomic'. 177263508Sdim ObjCMT_AtomicProperty = 0x100, 178263508Sdim /// \brief annotate property with NS_RETURNS_INNER_POINTER 179263508Sdim ObjCMT_ReturnsInnerPointerProperty = 0x200, 180263508Sdim /// \brief use NS_NONATOMIC_IOSONLY for property 'atomic' attribute 181263508Sdim ObjCMT_NsAtomicIOSOnlyProperty = 0x400, 182263508Sdim ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | 183263508Sdim ObjCMT_Annotation | ObjCMT_Instancetype | 184263508Sdim ObjCMT_NsMacros | ObjCMT_ProtocolConformance | 185263508Sdim ObjCMT_NsAtomicIOSOnlyProperty), 186263508Sdim ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | ObjCMT_MigrateDecls) 187234353Sdim }; 188234353Sdim unsigned ObjCMTAction; 189263508Sdim std::string ObjCMTWhiteListPath; 190234353Sdim 191234353Sdim std::string MTMigrateDir; 192226633Sdim std::string ARCMTMigrateReportOut; 193224145Sdim 194199482Srdivacky /// The input files and their types. 195234353Sdim std::vector<FrontendInputFile> Inputs; 196199482Srdivacky 197199482Srdivacky /// The output file, if any. 198199482Srdivacky std::string OutputFile; 199199482Srdivacky 200207619Srdivacky /// If given, the new suffix for fix-it rewritten files. 201207619Srdivacky std::string FixItSuffix; 202199482Srdivacky 203239462Sdim /// If given, filter dumped AST Decl nodes by this substring. 204239462Sdim std::string ASTDumpFilter; 205239462Sdim 206199482Srdivacky /// If given, enable code completion at the provided location. 207199482Srdivacky ParsedSourceLocation CodeCompletionAt; 208199482Srdivacky 209199482Srdivacky /// The frontend action to perform. 210199482Srdivacky frontend::ActionKind ProgramAction; 211199482Srdivacky 212199482Srdivacky /// The name of the action to run when using a plugin action. 213199482Srdivacky std::string ActionName; 214199482Srdivacky 215218893Sdim /// Args to pass to the plugin 216210299Sed std::vector<std::string> PluginArgs; 217210299Sed 218218893Sdim /// The list of plugin actions to run in addition to the normal action. 219218893Sdim std::vector<std::string> AddPluginActions; 220218893Sdim 221218893Sdim /// Args to pass to the additional plugins 222218893Sdim std::vector<std::vector<std::string> > AddPluginArgs; 223218893Sdim 224200583Srdivacky /// The list of plugins to load. 225200583Srdivacky std::vector<std::string> Plugins; 226200583Srdivacky 227203955Srdivacky /// \brief The list of AST files to merge. 228203955Srdivacky std::vector<std::string> ASTMergeFiles; 229203955Srdivacky 230207619Srdivacky /// \brief A list of arguments to forward to LLVM's option processing; this 231207619Srdivacky /// should only be used for debugging and experimental features. 232207619Srdivacky std::vector<std::string> LLVMArgs; 233207619Srdivacky 234234353Sdim /// \brief File name of the file that will provide record layouts 235234353Sdim /// (in the format produced by -fdump-record-layouts). 236234353Sdim std::string OverrideRecordLayoutsFile; 237234353Sdim 238199482Srdivackypublic: 239249423Sdim FrontendOptions() : 240249423Sdim DisableFree(false), RelocatablePCH(false), ShowHelp(false), 241249423Sdim ShowStats(false), ShowTimers(false), ShowVersion(false), 242249423Sdim FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false), 243249423Sdim FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false), 244249423Sdim SkipFunctionBodies(false), UseGlobalModuleIndex(true), 245263508Sdim GenerateGlobalModuleIndex(true), ASTDumpLookups(false), 246249423Sdim ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None), 247249423Sdim ProgramAction(frontend::ParseSyntaxOnly) 248249423Sdim {} 249199482Srdivacky 250199482Srdivacky /// getInputKindForExtension - Return the appropriate input kind for a file 251199482Srdivacky /// extension. For example, "c" would return IK_C. 252199482Srdivacky /// 253199482Srdivacky /// \return The input kind for the extension, or IK_None if the extension is 254199482Srdivacky /// not recognized. 255226633Sdim static InputKind getInputKindForExtension(StringRef Extension); 256199482Srdivacky}; 257199482Srdivacky 258199482Srdivacky} // end namespace clang 259199482Srdivacky 260199482Srdivacky#endif 261