Home | History | Annotate | Download | only in Frontend
      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/Frontend/FrontendAction.h"
     15 #include "llvm/ADT/StringRef.h"
     16 #include <string>
     17 #include <vector>
     18 
     19 namespace clang {
     20 
     21 namespace frontend {
     22   enum ActionKind {
     23     ASTDump,                ///< Parse ASTs and dump them.
     24     ASTDumpXML,             ///< Parse ASTs and dump them in XML.
     25     ASTPrint,               ///< Parse ASTs and print them.
     26     ASTView,                ///< Parse ASTs and view them in Graphviz.
     27     CreateModule,           ///< Create module definition
     28     DumpRawTokens,          ///< Dump out raw tokens.
     29     DumpTokens,             ///< Dump out preprocessed tokens.
     30     EmitAssembly,           ///< Emit a .s file.
     31     EmitBC,                 ///< Emit a .bc file.
     32     EmitHTML,               ///< Translate input source into HTML.
     33     EmitLLVM,               ///< Emit a .ll file.
     34     EmitLLVMOnly,           ///< Generate LLVM IR, but do not emit anything.
     35     EmitCodeGenOnly,        ///< Generate machine code, but don't emit anything.
     36     EmitObj,                ///< Emit a .o file.
     37     FixIt,                  ///< Parse and apply any fixits to the source.
     38     GeneratePCH,            ///< Generate pre-compiled header.
     39     GeneratePTH,            ///< Generate pre-tokenized header.
     40     InitOnly,               ///< Only execute frontend initialization.
     41     ParseSyntaxOnly,        ///< Parse and perform semantic analysis.
     42     PluginAction,           ///< Run a plugin action, \see ActionName.
     43     PrintDeclContext,       ///< Print DeclContext and their Decls.
     44     PrintPreamble,          ///< Print the "preamble" of the input file
     45     PrintPreprocessedInput, ///< -E mode.
     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     RunPreprocessorOnly     ///< Just lex, no output.
     51   };
     52 }
     53 
     54 /// FrontendOptions - Options for controlling the behavior of the frontend.
     55 class FrontendOptions {
     56 public:
     57   unsigned DisableFree : 1;                ///< Disable memory freeing on exit.
     58   unsigned RelocatablePCH : 1;             ///< When generating PCH files,
     59                                            /// instruct the AST writer to create
     60                                            /// relocatable PCH files.
     61   unsigned ChainedPCH : 1;                 ///< When generating PCH files,
     62                                            /// instruct the AST writer to create
     63                                            /// chained PCH files.
     64   unsigned ShowHelp : 1;                   ///< Show the -help text.
     65   unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion
     66                                            /// results.
     67   unsigned ShowCodePatternsInCodeCompletion : 1; ///< Show code patterns in code
     68                                                  /// completion results.
     69   unsigned ShowGlobalSymbolsInCodeCompletion : 1; ///< Show top-level decls in
     70                                                   /// code completion results.
     71   unsigned ShowStats : 1;                  ///< Show frontend performance
     72                                            /// metrics and statistics.
     73   unsigned ShowTimers : 1;                 ///< Show timers for individual
     74                                            /// actions.
     75   unsigned ShowVersion : 1;                ///< Show the -version text.
     76   unsigned FixWhatYouCan : 1;              ///< Apply fixes even if there are
     77                                            /// unfixable errors.
     78   unsigned ARCMTMigrateEmitARCErrors : 1;  /// Emit ARC errors even if the
     79                                            /// migrator can fix them
     80 
     81   enum {
     82     ARCMT_None,
     83     ARCMT_Check,
     84     ARCMT_Modify,
     85     ARCMT_Migrate
     86   } ARCMTAction;
     87 
     88   std::string ARCMTMigrateDir;
     89   std::string ARCMTMigrateReportOut;
     90 
     91   /// The input files and their types.
     92   std::vector<std::pair<InputKind, std::string> > Inputs;
     93 
     94   /// The output file, if any.
     95   std::string OutputFile;
     96 
     97   /// If given, the new suffix for fix-it rewritten files.
     98   std::string FixItSuffix;
     99 
    100   /// If given, enable code completion at the provided location.
    101   ParsedSourceLocation CodeCompletionAt;
    102 
    103   /// The frontend action to perform.
    104   frontend::ActionKind ProgramAction;
    105 
    106   /// The name of the action to run when using a plugin action.
    107   std::string ActionName;
    108 
    109   /// Args to pass to the plugin
    110   std::vector<std::string> PluginArgs;
    111 
    112   /// The list of plugin actions to run in addition to the normal action.
    113   std::vector<std::string> AddPluginActions;
    114 
    115   /// Args to pass to the additional plugins
    116   std::vector<std::vector<std::string> > AddPluginArgs;
    117 
    118   /// The list of plugins to load.
    119   std::vector<std::string> Plugins;
    120 
    121   /// \brief The list of AST files to merge.
    122   std::vector<std::string> ASTMergeFiles;
    123 
    124   /// \brief The list of modules to import.
    125   std::vector<std::string> Modules;
    126 
    127   /// \brief A list of arguments to forward to LLVM's option processing; this
    128   /// should only be used for debugging and experimental features.
    129   std::vector<std::string> LLVMArgs;
    130 
    131 public:
    132   FrontendOptions() {
    133     DisableFree = 0;
    134     ProgramAction = frontend::ParseSyntaxOnly;
    135     ActionName = "";
    136     RelocatablePCH = 0;
    137     ChainedPCH = 0;
    138     ShowHelp = 0;
    139     ShowMacrosInCodeCompletion = 0;
    140     ShowCodePatternsInCodeCompletion = 0;
    141     ShowGlobalSymbolsInCodeCompletion = 1;
    142     ShowStats = 0;
    143     ShowTimers = 0;
    144     ShowVersion = 0;
    145     ARCMTAction = ARCMT_None;
    146     ARCMTMigrateEmitARCErrors = 0;
    147   }
    148 
    149   /// getInputKindForExtension - Return the appropriate input kind for a file
    150   /// extension. For example, "c" would return IK_C.
    151   ///
    152   /// \return The input kind for the extension, or IK_None if the extension is
    153   /// not recognized.
    154   static InputKind getInputKindForExtension(llvm::StringRef Extension);
    155 };
    156 
    157 }  // end namespace clang
    158 
    159 #endif
    160