FrontendOptions.h revision 686775deca8b8685eb90801495880e3abdd844c2
126266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar//===--- FrontendOptions.h --------------------------------------*- C++ -*-===//
226266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar//
326266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar//                     The LLVM Compiler Infrastructure
426266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar//
526266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar// This file is distributed under the University of Illinois Open Source
626266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar// License. See LICENSE.TXT for details.
726266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar//
826266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar//===----------------------------------------------------------------------===//
926266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar
1026266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar#ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
1126266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar#define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
1226266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar
13c86804bc9c3f1953520b59084c9ad75104aba123Daniel Dunbar#include "clang/Frontend/CommandLineSourceLoc.h"
14c34ce3fa613d5e4a283e53615fceafd17390445bDaniel Dunbar#include "clang/Frontend/FrontendAction.h"
15fbe2fafe317a757031e4f24026a77dd305607d32Daniel Dunbar#include "llvm/ADT/StringRef.h"
1626266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar#include <string>
1726266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar#include <vector>
1826266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar
1926266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbarnamespace clang {
2026266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar
219a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbarnamespace frontend {
229a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar  enum ActionKind {
239a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    ASTDump,                ///< Parse ASTs and dump them.
24f35142413974e9dfe2c5f202084db4bd1c2073e9John McCall    ASTDumpXML,             ///< Parse ASTs and dump them in XML.
259a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    ASTPrint,               ///< Parse ASTs and print them.
269a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    ASTView,                ///< Parse ASTs and view them in Graphviz.
27e55fd871b0cf3e4ebc708cf46831908d74eab40aSebastian Redl    CreateModule,           ///< Create module definition
289a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    DumpRawTokens,          ///< Dump out raw tokens.
299a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    DumpTokens,             ///< Dump out preprocessed tokens.
309a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    EmitAssembly,           ///< Emit a .s file.
319a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    EmitBC,                 ///< Emit a .bc file.
329a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    EmitHTML,               ///< Translate input source into HTML.
339a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    EmitLLVM,               ///< Emit a .ll file.
3432148cef25570a4fbe3ad0ec497ce3ae2cf1b774Daniel Dunbar    EmitLLVMOnly,           ///< Generate LLVM IR, but do not emit anything.
3532148cef25570a4fbe3ad0ec497ce3ae2cf1b774Daniel Dunbar    EmitCodeGenOnly,        ///< Generate machine code, but don't emit anything.
36da1573f95902a42aa4d11e8f45ab98ec7e27bc28Daniel Dunbar    EmitObj,                ///< Emit a .o file.
379a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    FixIt,                  ///< Parse and apply any fixits to the source.
389a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    GeneratePCH,            ///< Generate pre-compiled header.
399a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    GeneratePTH,            ///< Generate pre-tokenized header.
402758595023c5c7c0495f19260089f975022c50dcDaniel Dunbar    InitOnly,               ///< Only execute frontend initialization.
419a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    ParseSyntaxOnly,        ///< Parse and perform semantic analysis.
42d10c5b88334d860d19284032a7126dc2219f57edDaniel Dunbar    PluginAction,           ///< Run a plugin action, \see ActionName.
439a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    PrintDeclContext,       ///< Print DeclContext and their Decls.
44f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor    PrintPreamble,          ///< Print the "preamble" of the input file
459a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    PrintPreprocessedInput, ///< -E mode.
469a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    RewriteMacros,          ///< Expand macros but not #includes.
479a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    RewriteObjC,            ///< ObjC->C Rewriter.
489a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    RewriteTest,            ///< Rewriter playground
499a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    RunAnalysis,            ///< Run one or more source code analyses.
509a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    RunPreprocessorOnly     ///< Just lex, no output.
519a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar  };
529a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar}
539a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar
5426266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar/// FrontendOptions - Options for controlling the behavior of the frontend.
5526266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbarclass FrontendOptions {
5626266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbarpublic:
57914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar  unsigned DisableFree : 1;                ///< Disable memory freeing on exit.
58914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar  unsigned RelocatablePCH : 1;             ///< When generating PCH files,
593c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl                                           /// instruct the AST writer to create
60914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar                                           /// relocatable PCH files.
61d6ac4524cd441808f152f7e10900a8315ea31c08Sebastian Redl  unsigned ChainedPCH : 1;                 ///< When generating PCH files,
623c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl                                           /// instruct the AST writer to create
63d6ac4524cd441808f152f7e10900a8315ea31c08Sebastian Redl                                           /// chained PCH files.
649b5e9ae08defd14441acca1d7d4502b933bf6c5aDaniel Dunbar  unsigned ShowHelp : 1;                   ///< Show the -help text.
65914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar  unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion
66914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar                                           /// results.
67d8e8a58ee35ab334ab9d0c2154dca029c1822e8aDouglas Gregor  unsigned ShowCodePatternsInCodeCompletion : 1; ///< Show code patterns in code
68d8e8a58ee35ab334ab9d0c2154dca029c1822e8aDouglas Gregor                                                 /// completion results.
698071e4212ae08f8014e0c3ae6d18b7388003a5ccDouglas Gregor  unsigned ShowGlobalSymbolsInCodeCompletion : 1; ///< Show top-level decls in
708071e4212ae08f8014e0c3ae6d18b7388003a5ccDouglas Gregor                                                  /// code completion results.
71914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar  unsigned ShowStats : 1;                  ///< Show frontend performance
72914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar                                           /// metrics and statistics.
73914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar  unsigned ShowTimers : 1;                 ///< Show timers for individual
74914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar                                           /// actions.
759b5e9ae08defd14441acca1d7d4502b933bf6c5aDaniel Dunbar  unsigned ShowVersion : 1;                ///< Show the -version text.
761450f265fcc84a7ca64dd9f3b8d4492c5bd55e23Nick Lewycky  unsigned FixWhatYouCan : 1;              ///< Apply fixes even if there are
771450f265fcc84a7ca64dd9f3b8d4492c5bd55e23Nick Lewycky                                           /// unfixable errors.
787ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis  unsigned ARCMTMigrateEmitARCErrors : 1;  /// Emit ARC errors even if the
797ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis                                           /// migrator can fix them
8026266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar
81f85e193739c953358c865005855253af4f68a497John McCall  enum {
82f85e193739c953358c865005855253af4f68a497John McCall    ARCMT_None,
83f85e193739c953358c865005855253af4f68a497John McCall    ARCMT_Check,
8469325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis    ARCMT_Modify,
8569325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis    ARCMT_Migrate
86f85e193739c953358c865005855253af4f68a497John McCall  } ARCMTAction;
87f85e193739c953358c865005855253af4f68a497John McCall
8869325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis  std::string ARCMTMigrateDir;
897ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis  std::string ARCMTMigrateReportOut;
9069325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis
91fbe2fafe317a757031e4f24026a77dd305607d32Daniel Dunbar  /// The input files and their types.
92fbe2fafe317a757031e4f24026a77dd305607d32Daniel Dunbar  std::vector<std::pair<InputKind, std::string> > Inputs;
9326266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar
9426266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar  /// The output file, if any.
9526266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar  std::string OutputFile;
9626266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar
97ba5f6eced29937e4e4851a2c0980744768413d66Nick Lewycky  /// If given, the new suffix for fix-it rewritten files.
98ba5f6eced29937e4e4851a2c0980744768413d66Nick Lewycky  std::string FixItSuffix;
99c86804bc9c3f1953520b59084c9ad75104aba123Daniel Dunbar
100914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar  /// If given, enable code completion at the provided location.
101914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar  ParsedSourceLocation CodeCompletionAt;
102914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar
1039a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar  /// The frontend action to perform.
1049a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar  frontend::ActionKind ProgramAction;
1059a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar
106d10c5b88334d860d19284032a7126dc2219f57edDaniel Dunbar  /// The name of the action to run when using a plugin action.
107d10c5b88334d860d19284032a7126dc2219f57edDaniel Dunbar  std::string ActionName;
108d10c5b88334d860d19284032a7126dc2219f57edDaniel Dunbar
109f25649c74397d2620e6ac61f1045261644707c80Nico Weber  /// Args to pass to the plugin
1103177aae51a21f61ab483c52f97124bdb707da7f1Daniel Dunbar  std::vector<std::string> PluginArgs;
1113177aae51a21f61ab483c52f97124bdb707da7f1Daniel Dunbar
1125aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber  /// The list of plugin actions to run in addition to the normal action.
1135aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber  std::vector<std::string> AddPluginActions;
1145aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber
115f25649c74397d2620e6ac61f1045261644707c80Nico Weber  /// Args to pass to the additional plugins
116f25649c74397d2620e6ac61f1045261644707c80Nico Weber  std::vector<std::vector<std::string> > AddPluginArgs;
117f25649c74397d2620e6ac61f1045261644707c80Nico Weber
118efba227cc5459554eca466aafe786b5132dcb68cDaniel Dunbar  /// The list of plugins to load.
119efba227cc5459554eca466aafe786b5132dcb68cDaniel Dunbar  std::vector<std::string> Plugins;
120efba227cc5459554eca466aafe786b5132dcb68cDaniel Dunbar
1219bed8798964d9f07599c2c9199701f86fbc70e20Douglas Gregor  /// \brief The list of AST files to merge.
1229bed8798964d9f07599c2c9199701f86fbc70e20Douglas Gregor  std::vector<std::string> ASTMergeFiles;
1239bed8798964d9f07599c2c9199701f86fbc70e20Douglas Gregor
124e55fd871b0cf3e4ebc708cf46831908d74eab40aSebastian Redl  /// \brief The list of modules to import.
125e55fd871b0cf3e4ebc708cf46831908d74eab40aSebastian Redl  std::vector<std::string> Modules;
126e55fd871b0cf3e4ebc708cf46831908d74eab40aSebastian Redl
1273f87fb08dd502309960646db01099fb4c1be9a7cDaniel Dunbar  /// \brief A list of arguments to forward to LLVM's option processing; this
1283f87fb08dd502309960646db01099fb4c1be9a7cDaniel Dunbar  /// should only be used for debugging and experimental features.
1293f87fb08dd502309960646db01099fb4c1be9a7cDaniel Dunbar  std::vector<std::string> LLVMArgs;
1303f87fb08dd502309960646db01099fb4c1be9a7cDaniel Dunbar
13126266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbarpublic:
13226266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar  FrontendOptions() {
13326266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar    DisableFree = 0;
1349a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9Daniel Dunbar    ProgramAction = frontend::ParseSyntaxOnly;
135d10c5b88334d860d19284032a7126dc2219f57edDaniel Dunbar    ActionName = "";
13626266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar    RelocatablePCH = 0;
137d6ac4524cd441808f152f7e10900a8315ea31c08Sebastian Redl    ChainedPCH = 0;
1389b5e9ae08defd14441acca1d7d4502b933bf6c5aDaniel Dunbar    ShowHelp = 0;
139914474ca51d202369241a81013208833a6bb3f12Daniel Dunbar    ShowMacrosInCodeCompletion = 0;
140d8e8a58ee35ab334ab9d0c2154dca029c1822e8aDouglas Gregor    ShowCodePatternsInCodeCompletion = 0;
1418071e4212ae08f8014e0c3ae6d18b7388003a5ccDouglas Gregor    ShowGlobalSymbolsInCodeCompletion = 1;
14226266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar    ShowStats = 0;
14326266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar    ShowTimers = 0;
1449b5e9ae08defd14441acca1d7d4502b933bf6c5aDaniel Dunbar    ShowVersion = 0;
145f85e193739c953358c865005855253af4f68a497John McCall    ARCMTAction = ARCMT_None;
1467ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis    ARCMTMigrateEmitARCErrors = 0;
14726266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar  }
148fbe2fafe317a757031e4f24026a77dd305607d32Daniel Dunbar
149fbe2fafe317a757031e4f24026a77dd305607d32Daniel Dunbar  /// getInputKindForExtension - Return the appropriate input kind for a file
150fbe2fafe317a757031e4f24026a77dd305607d32Daniel Dunbar  /// extension. For example, "c" would return IK_C.
151fbe2fafe317a757031e4f24026a77dd305607d32Daniel Dunbar  ///
152fbe2fafe317a757031e4f24026a77dd305607d32Daniel Dunbar  /// \return The input kind for the extension, or IK_None if the extension is
153fbe2fafe317a757031e4f24026a77dd305607d32Daniel Dunbar  /// not recognized.
154686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  static InputKind getInputKindForExtension(StringRef Extension);
15526266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar};
15626266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar
15726266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar}  // end namespace clang
15826266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar
15926266885d6eba8ee197577dd42a8e68a0e4dd2e8Daniel Dunbar#endif
160