1199482Srdivacky//===-- CompilerInvocation.h - Compiler Invocation Helper Data --*- 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_COMPILERINVOCATION_H_ 11199482Srdivacky#define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_ 12199482Srdivacky 13249423Sdim#include "clang/Basic/DiagnosticOptions.h" 14249423Sdim#include "clang/Basic/FileSystemOptions.h" 15199482Srdivacky#include "clang/Basic/LangOptions.h" 16199482Srdivacky#include "clang/Basic/TargetOptions.h" 17210299Sed#include "clang/Frontend/CodeGenOptions.h" 18199482Srdivacky#include "clang/Frontend/DependencyOutputOptions.h" 19199482Srdivacky#include "clang/Frontend/FrontendOptions.h" 20218893Sdim#include "clang/Frontend/LangStandard.h" 21249423Sdim#include "clang/Frontend/MigratorOptions.h" 22199482Srdivacky#include "clang/Frontend/PreprocessorOutputOptions.h" 23249423Sdim#include "clang/Lex/HeaderSearchOptions.h" 24249423Sdim#include "clang/Lex/PreprocessorOptions.h" 25249423Sdim#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" 26221345Sdim#include "llvm/ADT/IntrusiveRefCntPtr.h" 27249423Sdim#include "llvm/ADT/StringMap.h" 28199482Srdivacky#include "llvm/ADT/StringRef.h" 29199482Srdivacky#include <string> 30199482Srdivacky#include <vector> 31199482Srdivacky 32263508Sdimnamespace llvm { 33263508Sdimnamespace opt { 34263508Sdimclass ArgList; 35263508Sdim} 36263508Sdim} 37263508Sdim 38199482Srdivackynamespace clang { 39234353Sdimclass CompilerInvocation; 40226633Sdimclass DiagnosticsEngine; 41199990Srdivacky 42239462Sdim/// \brief Fill out Opts based on the options given in Args. 43239462Sdim/// 44234353Sdim/// Args must have been created from the OptTable returned by 45239462Sdim/// createCC1OptTable(). 46239462Sdim/// 47239462Sdim/// When errors are encountered, return false and, if Diags is non-null, 48239462Sdim/// report the error(s). 49263508Sdimbool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, 50234353Sdim DiagnosticsEngine *Diags = 0); 51263508Sdim 52234353Sdimclass CompilerInvocationBase : public RefCountedBase<CompilerInvocation> { 53234353Sdimprotected: 54234353Sdim /// Options controlling the language variant. 55234353Sdim IntrusiveRefCntPtr<LangOptions> LangOpts; 56243830Sdim 57243830Sdim /// Options controlling the target. 58243830Sdim IntrusiveRefCntPtr<TargetOptions> TargetOpts; 59243830Sdim 60243830Sdim /// Options controlling the diagnostic engine. 61243830Sdim IntrusiveRefCntPtr<DiagnosticOptions> DiagnosticOpts; 62243830Sdim 63243830Sdim /// Options controlling the \#include directive. 64243830Sdim IntrusiveRefCntPtr<HeaderSearchOptions> HeaderSearchOpts; 65243830Sdim 66243830Sdim /// Options controlling the preprocessor (aside from \#include handling). 67243830Sdim IntrusiveRefCntPtr<PreprocessorOptions> PreprocessorOpts; 68243830Sdim 69234353Sdimpublic: 70234353Sdim CompilerInvocationBase(); 71234353Sdim 72234353Sdim CompilerInvocationBase(const CompilerInvocationBase &X); 73234353Sdim 74234353Sdim LangOptions *getLangOpts() { return LangOpts.getPtr(); } 75234353Sdim const LangOptions *getLangOpts() const { return LangOpts.getPtr(); } 76243830Sdim 77243830Sdim TargetOptions &getTargetOpts() { return *TargetOpts.getPtr(); } 78243830Sdim const TargetOptions &getTargetOpts() const { 79243830Sdim return *TargetOpts.getPtr(); 80243830Sdim } 81243830Sdim 82243830Sdim DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; } 83243830Sdim 84243830Sdim HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; } 85243830Sdim const HeaderSearchOptions &getHeaderSearchOpts() const { 86243830Sdim return *HeaderSearchOpts; 87243830Sdim } 88243830Sdim 89243830Sdim PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; } 90243830Sdim const PreprocessorOptions &getPreprocessorOpts() const { 91243830Sdim return *PreprocessorOpts; 92243830Sdim } 93234353Sdim}; 94234353Sdim 95239462Sdim/// \brief Helper class for holding the data necessary to invoke the compiler. 96199482Srdivacky/// 97199482Srdivacky/// This class is designed to represent an abstract "invocation" of the 98199482Srdivacky/// compiler, including data such as the include paths, the code generation 99199482Srdivacky/// options, the warning flags, and so on. 100234353Sdimclass CompilerInvocation : public CompilerInvocationBase { 101199482Srdivacky /// Options controlling the static analyzer. 102243830Sdim AnalyzerOptionsRef AnalyzerOpts; 103199482Srdivacky 104234353Sdim MigratorOptions MigratorOpts; 105234353Sdim 106199482Srdivacky /// Options controlling IRgen and the backend. 107199482Srdivacky CodeGenOptions CodeGenOpts; 108199482Srdivacky 109199482Srdivacky /// Options controlling dependency output. 110199482Srdivacky DependencyOutputOptions DependencyOutputOpts; 111199482Srdivacky 112218893Sdim /// Options controlling file system operations. 113218893Sdim FileSystemOptions FileSystemOpts; 114218893Sdim 115199482Srdivacky /// Options controlling the frontend itself. 116199482Srdivacky FrontendOptions FrontendOpts; 117199482Srdivacky 118199482Srdivacky /// Options controlling preprocessed output. 119199482Srdivacky PreprocessorOutputOptions PreprocessorOutputOpts; 120199482Srdivacky 121199482Srdivackypublic: 122243830Sdim CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {} 123199482Srdivacky 124199482Srdivacky /// @name Utility Methods 125199482Srdivacky /// @{ 126199482Srdivacky 127239462Sdim /// \brief Create a compiler invocation from a list of input options. 128239462Sdim /// \returns true on success. 129199482Srdivacky /// 130239462Sdim /// \param [out] Res - The resulting invocation. 131199990Srdivacky /// \param ArgBegin - The first element in the argument vector. 132199990Srdivacky /// \param ArgEnd - The last element in the argument vector. 133200583Srdivacky /// \param Diags - The diagnostic engine to use for errors. 134234353Sdim static bool CreateFromArgs(CompilerInvocation &Res, 135218893Sdim const char* const *ArgBegin, 136218893Sdim const char* const *ArgEnd, 137226633Sdim DiagnosticsEngine &Diags); 138200583Srdivacky 139239462Sdim /// \brief Get the directory where the compiler headers 140200583Srdivacky /// reside, relative to the compiler binary (found by the passed in 141200583Srdivacky /// arguments). 142200583Srdivacky /// 143199990Srdivacky /// \param Argv0 - The program path (from argv[0]), for finding the builtin 144199990Srdivacky /// compiler path. 145199990Srdivacky /// \param MainAddr - The address of main (or some other function in the main 146199990Srdivacky /// executable), for finding the builtin compiler path. 147200583Srdivacky static std::string GetResourcesPath(const char *Argv0, void *MainAddr); 148199482Srdivacky 149239462Sdim /// \brief Set language defaults for the given input language and 150218893Sdim /// language standard in the given LangOptions object. 151218893Sdim /// 152239462Sdim /// \param Opts - The LangOptions object to set up. 153218893Sdim /// \param IK - The input language. 154218893Sdim /// \param LangStd - The input language standard. 155218893Sdim static void setLangDefaults(LangOptions &Opts, InputKind IK, 156218893Sdim LangStandard::Kind LangStd = LangStandard::lang_unspecified); 157218893Sdim 158226633Sdim /// \brief Retrieve a module hash string that is suitable for uniquely 159226633Sdim /// identifying the conditions under which the module was built. 160226633Sdim std::string getModuleHash() const; 161226633Sdim 162199482Srdivacky /// @} 163199482Srdivacky /// @name Option Subgroups 164199482Srdivacky /// @{ 165199482Srdivacky 166243830Sdim AnalyzerOptionsRef getAnalyzerOpts() const { 167199482Srdivacky return AnalyzerOpts; 168199482Srdivacky } 169199482Srdivacky 170234353Sdim MigratorOptions &getMigratorOpts() { return MigratorOpts; } 171234353Sdim const MigratorOptions &getMigratorOpts() const { 172234353Sdim return MigratorOpts; 173234353Sdim } 174234353Sdim 175199482Srdivacky CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; } 176199482Srdivacky const CodeGenOptions &getCodeGenOpts() const { 177199482Srdivacky return CodeGenOpts; 178199482Srdivacky } 179199482Srdivacky 180199482Srdivacky DependencyOutputOptions &getDependencyOutputOpts() { 181199482Srdivacky return DependencyOutputOpts; 182199482Srdivacky } 183199482Srdivacky const DependencyOutputOptions &getDependencyOutputOpts() const { 184199482Srdivacky return DependencyOutputOpts; 185199482Srdivacky } 186199482Srdivacky 187218893Sdim FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; } 188218893Sdim const FileSystemOptions &getFileSystemOpts() const { 189218893Sdim return FileSystemOpts; 190218893Sdim } 191218893Sdim 192199482Srdivacky FrontendOptions &getFrontendOpts() { return FrontendOpts; } 193199482Srdivacky const FrontendOptions &getFrontendOpts() const { 194199482Srdivacky return FrontendOpts; 195199482Srdivacky } 196199482Srdivacky 197199482Srdivacky PreprocessorOutputOptions &getPreprocessorOutputOpts() { 198199482Srdivacky return PreprocessorOutputOpts; 199199482Srdivacky } 200199482Srdivacky const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 201199482Srdivacky return PreprocessorOutputOpts; 202199482Srdivacky } 203199482Srdivacky 204199482Srdivacky /// @} 205199482Srdivacky}; 206199482Srdivacky 207199482Srdivacky} // end namespace clang 208199482Srdivacky 209199482Srdivacky#endif 210