Utils.h revision 263508
1//===--- Utils.h - Misc utilities for the front-end -------------*- 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// This header contains miscellaneous utilities for various front-end actions. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_FRONTEND_UTILS_H 15#define LLVM_CLANG_FRONTEND_UTILS_H 16 17#include "clang/Basic/Diagnostic.h" 18#include "llvm/ADT/IntrusiveRefCntPtr.h" 19#include "llvm/ADT/StringRef.h" 20#include "llvm/Option/OptSpecifier.h" 21 22namespace llvm { 23class raw_fd_ostream; 24class Triple; 25 26namespace opt { 27class ArgList; 28} 29} 30 31namespace clang { 32class ASTConsumer; 33class CompilerInstance; 34class CompilerInvocation; 35class Decl; 36class DependencyOutputOptions; 37class DiagnosticsEngine; 38class DiagnosticOptions; 39class FileManager; 40class HeaderSearch; 41class HeaderSearchOptions; 42class IdentifierTable; 43class LangOptions; 44class Preprocessor; 45class PreprocessorOptions; 46class PreprocessorOutputOptions; 47class SourceManager; 48class Stmt; 49class TargetInfo; 50class FrontendOptions; 51 52/// Apply the header search options to get given HeaderSearch object. 53void ApplyHeaderSearchOptions(HeaderSearch &HS, 54 const HeaderSearchOptions &HSOpts, 55 const LangOptions &Lang, 56 const llvm::Triple &triple); 57 58/// InitializePreprocessor - Initialize the preprocessor getting it and the 59/// environment ready to process a single file. 60void InitializePreprocessor(Preprocessor &PP, 61 const PreprocessorOptions &PPOpts, 62 const HeaderSearchOptions &HSOpts, 63 const FrontendOptions &FEOpts); 64 65/// ProcessWarningOptions - Initialize the diagnostic client and process the 66/// warning options specified on the command line. 67void ProcessWarningOptions(DiagnosticsEngine &Diags, 68 const DiagnosticOptions &Opts, 69 bool ReportDiags = true); 70 71/// DoPrintPreprocessedInput - Implement -E mode. 72void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream* OS, 73 const PreprocessorOutputOptions &Opts); 74 75/// AttachDependencyFileGen - Create a dependency file generator, and attach 76/// it to the given preprocessor. This takes ownership of the output stream. 77void AttachDependencyFileGen(Preprocessor &PP, 78 const DependencyOutputOptions &Opts); 79 80/// AttachDependencyGraphGen - Create a dependency graph generator, and attach 81/// it to the given preprocessor. 82 void AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, 83 StringRef SysRoot); 84 85/// AttachHeaderIncludeGen - Create a header include list generator, and attach 86/// it to the given preprocessor. 87/// 88/// \param ShowAllHeaders - If true, show all header information instead of just 89/// headers following the predefines buffer. This is useful for making sure 90/// includes mentioned on the command line are also reported, but differs from 91/// the default behavior used by -H. 92/// \param OutputPath - If non-empty, a path to write the header include 93/// information to, instead of writing to stderr. 94/// \param ShowDepth - Whether to indent to show the nesting of the includes. 95/// \param MSStyle - Whether to print in cl.exe /showIncludes style. 96void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false, 97 StringRef OutputPath = "", 98 bool ShowDepth = true, bool MSStyle = false); 99 100/// CacheTokens - Cache tokens for use with PCH. Note that this requires 101/// a seekable stream. 102void CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS); 103 104/// createInvocationFromCommandLine - Construct a compiler invocation object for 105/// a command line argument vector. 106/// 107/// \return A CompilerInvocation, or 0 if none was built for the given 108/// argument vector. 109CompilerInvocation * 110createInvocationFromCommandLine(ArrayRef<const char *> Args, 111 IntrusiveRefCntPtr<DiagnosticsEngine> Diags = 112 IntrusiveRefCntPtr<DiagnosticsEngine>()); 113 114/// Return the value of the last argument as an integer, or a default. If Diags 115/// is non-null, emits an error if the argument is given, but non-integral. 116int getLastArgIntValue(const llvm::opt::ArgList &Args, 117 llvm::opt::OptSpecifier Id, int Default, 118 DiagnosticsEngine *Diags = 0); 119 120inline int getLastArgIntValue(const llvm::opt::ArgList &Args, 121 llvm::opt::OptSpecifier Id, int Default, 122 DiagnosticsEngine &Diags) { 123 return getLastArgIntValue(Args, Id, Default, &Diags); 124} 125 126} // end namespace clang 127 128#endif 129