1 //===--- Utils.h - Misc utilities for the front-end -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header contains miscellaneous utilities for various front-end actions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_FRONTEND_UTILS_H
15 #define LLVM_CLANG_FRONTEND_UTILS_H
17 #include "clang/Basic/Diagnostic.h"
18 #include "llvm/ADT/IntrusiveRefCntPtr.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Option/OptSpecifier.h"
33 class CompilerInstance;
34 class CompilerInvocation;
36 class DependencyOutputOptions;
37 class DiagnosticsEngine;
38 class DiagnosticOptions;
41 class HeaderSearchOptions;
42 class IdentifierTable;
45 class PreprocessorOptions;
46 class PreprocessorOutputOptions;
50 class FrontendOptions;
52 /// Apply the header search options to get given HeaderSearch object.
53 void ApplyHeaderSearchOptions(HeaderSearch &HS,
54 const HeaderSearchOptions &HSOpts,
55 const LangOptions &Lang,
56 const llvm::Triple &triple);
58 /// InitializePreprocessor - Initialize the preprocessor getting it and the
59 /// environment ready to process a single file.
60 void InitializePreprocessor(Preprocessor &PP,
61 const PreprocessorOptions &PPOpts,
62 const HeaderSearchOptions &HSOpts,
63 const FrontendOptions &FEOpts);
65 /// ProcessWarningOptions - Initialize the diagnostic client and process the
66 /// warning options specified on the command line.
67 void ProcessWarningOptions(DiagnosticsEngine &Diags,
68 const DiagnosticOptions &Opts,
69 bool ReportDiags = true);
71 /// DoPrintPreprocessedInput - Implement -E mode.
72 void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream* OS,
73 const PreprocessorOutputOptions &Opts);
75 /// AttachDependencyFileGen - Create a dependency file generator, and attach
76 /// it to the given preprocessor. This takes ownership of the output stream.
77 void AttachDependencyFileGen(Preprocessor &PP,
78 const DependencyOutputOptions &Opts);
80 /// AttachDependencyGraphGen - Create a dependency graph generator, and attach
81 /// it to the given preprocessor.
82 void AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile,
85 /// AttachHeaderIncludeGen - Create a header include list generator, and attach
86 /// it to the given preprocessor.
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.
96 void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false,
97 StringRef OutputPath = "",
98 bool ShowDepth = true, bool MSStyle = false);
100 /// CacheTokens - Cache tokens for use with PCH. Note that this requires
101 /// a seekable stream.
102 void CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS);
104 /// createInvocationFromCommandLine - Construct a compiler invocation object for
105 /// a command line argument vector.
107 /// \return A CompilerInvocation, or 0 if none was built for the given
110 createInvocationFromCommandLine(ArrayRef<const char *> Args,
111 IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
112 IntrusiveRefCntPtr<DiagnosticsEngine>());
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.
116 int getLastArgIntValue(const llvm::opt::ArgList &Args,
117 llvm::opt::OptSpecifier Id, int Default,
118 DiagnosticsEngine *Diags = 0);
120 inline int getLastArgIntValue(const llvm::opt::ArgList &Args,
121 llvm::opt::OptSpecifier Id, int Default,
122 DiagnosticsEngine &Diags) {
123 return getLastArgIntValue(Args, Id, Default, &Diags);
126 } // end namespace clang