1199482Srdivacky//===--- Utils.h - Misc utilities for the front-end -------------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This header contains miscellaneous utilities for various front-end actions. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_FRONTEND_UTILS_H 15193326Sed#define LLVM_CLANG_FRONTEND_UTILS_H 16193326Sed 17221345Sdim#include "clang/Basic/Diagnostic.h" 18234353Sdim#include "llvm/ADT/IntrusiveRefCntPtr.h" 19199482Srdivacky#include "llvm/ADT/StringRef.h" 20263508Sdim#include "llvm/Option/OptSpecifier.h" 21193326Sed 22193326Sednamespace llvm { 23234353Sdimclass raw_fd_ostream; 24199482Srdivackyclass Triple; 25263508Sdim 26263508Sdimnamespace opt { 27263508Sdimclass ArgList; 28193326Sed} 29263508Sdim} 30193326Sed 31193326Sednamespace clang { 32199482Srdivackyclass ASTConsumer; 33212904Sdimclass CompilerInstance; 34221345Sdimclass CompilerInvocation; 35199482Srdivackyclass Decl; 36199482Srdivackyclass DependencyOutputOptions; 37226633Sdimclass DiagnosticsEngine; 38199482Srdivackyclass DiagnosticOptions; 39219077Sdimclass FileManager; 40199482Srdivackyclass HeaderSearch; 41199482Srdivackyclass HeaderSearchOptions; 42193326Sedclass IdentifierTable; 43199482Srdivackyclass LangOptions; 44199482Srdivackyclass Preprocessor; 45199482Srdivackyclass PreprocessorOptions; 46199482Srdivackyclass PreprocessorOutputOptions; 47193326Sedclass SourceManager; 48195099Sedclass Stmt; 49199482Srdivackyclass TargetInfo; 50202379Srdivackyclass FrontendOptions; 51193326Sed 52199482Srdivacky/// Apply the header search options to get given HeaderSearch object. 53199482Srdivackyvoid ApplyHeaderSearchOptions(HeaderSearch &HS, 54199482Srdivacky const HeaderSearchOptions &HSOpts, 55199482Srdivacky const LangOptions &Lang, 56199482Srdivacky const llvm::Triple &triple); 57199482Srdivacky 58199482Srdivacky/// InitializePreprocessor - Initialize the preprocessor getting it and the 59199482Srdivacky/// environment ready to process a single file. 60199482Srdivackyvoid InitializePreprocessor(Preprocessor &PP, 61199482Srdivacky const PreprocessorOptions &PPOpts, 62202379Srdivacky const HeaderSearchOptions &HSOpts, 63202379Srdivacky const FrontendOptions &FEOpts); 64199482Srdivacky 65193326Sed/// ProcessWarningOptions - Initialize the diagnostic client and process the 66193326Sed/// warning options specified on the command line. 67234353Sdimvoid ProcessWarningOptions(DiagnosticsEngine &Diags, 68249423Sdim const DiagnosticOptions &Opts, 69249423Sdim bool ReportDiags = true); 70193326Sed 71193326Sed/// DoPrintPreprocessedInput - Implement -E mode. 72226633Sdimvoid DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream* OS, 73199482Srdivacky const PreprocessorOutputOptions &Opts); 74193326Sed 75193326Sed/// AttachDependencyFileGen - Create a dependency file generator, and attach 76193326Sed/// it to the given preprocessor. This takes ownership of the output stream. 77199482Srdivackyvoid AttachDependencyFileGen(Preprocessor &PP, 78199482Srdivacky const DependencyOutputOptions &Opts); 79193326Sed 80234353Sdim/// AttachDependencyGraphGen - Create a dependency graph generator, and attach 81234353Sdim/// it to the given preprocessor. 82234353Sdim void AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, 83234353Sdim StringRef SysRoot); 84234353Sdim 85218893Sdim/// AttachHeaderIncludeGen - Create a header include list generator, and attach 86218893Sdim/// it to the given preprocessor. 87218893Sdim/// 88218893Sdim/// \param ShowAllHeaders - If true, show all header information instead of just 89218893Sdim/// headers following the predefines buffer. This is useful for making sure 90218893Sdim/// includes mentioned on the command line are also reported, but differs from 91218893Sdim/// the default behavior used by -H. 92218893Sdim/// \param OutputPath - If non-empty, a path to write the header include 93218893Sdim/// information to, instead of writing to stderr. 94263508Sdim/// \param ShowDepth - Whether to indent to show the nesting of the includes. 95263508Sdim/// \param MSStyle - Whether to print in cl.exe /showIncludes style. 96218893Sdimvoid AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false, 97226633Sdim StringRef OutputPath = "", 98263508Sdim bool ShowDepth = true, bool MSStyle = false); 99218893Sdim 100193326Sed/// CacheTokens - Cache tokens for use with PCH. Note that this requires 101193326Sed/// a seekable stream. 102199482Srdivackyvoid CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS); 103193326Sed 104221345Sdim/// createInvocationFromCommandLine - Construct a compiler invocation object for 105221345Sdim/// a command line argument vector. 106221345Sdim/// 107221345Sdim/// \return A CompilerInvocation, or 0 if none was built for the given 108221345Sdim/// argument vector. 109221345SdimCompilerInvocation * 110226633SdimcreateInvocationFromCommandLine(ArrayRef<const char *> Args, 111234353Sdim IntrusiveRefCntPtr<DiagnosticsEngine> Diags = 112234353Sdim IntrusiveRefCntPtr<DiagnosticsEngine>()); 113221345Sdim 114263508Sdim/// Return the value of the last argument as an integer, or a default. If Diags 115263508Sdim/// is non-null, emits an error if the argument is given, but non-integral. 116263508Sdimint getLastArgIntValue(const llvm::opt::ArgList &Args, 117263508Sdim llvm::opt::OptSpecifier Id, int Default, 118263508Sdim DiagnosticsEngine *Diags = 0); 119193326Sed 120263508Sdiminline int getLastArgIntValue(const llvm::opt::ArgList &Args, 121263508Sdim llvm::opt::OptSpecifier Id, int Default, 122263508Sdim DiagnosticsEngine &Diags) { 123263508Sdim return getLastArgIntValue(Args, Id, Default, &Diags); 124263508Sdim} 125263508Sdim 126263508Sdim} // end namespace clang 127263508Sdim 128193326Sed#endif 129