Utils.h revision cb381eac84e5a14a8c7e7654eadbe1d3d54d795c
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/StringRef.h"
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/IntrusiveRefCntPtr.h"
21#include "llvm/Support/raw_ostream.h"
22#include "clang/Basic/Diagnostic.h"
23
24namespace llvm {
25class Triple;
26}
27
28namespace clang {
29class ASTConsumer;
30class CompilerInstance;
31class CompilerInvocation;
32class Decl;
33class DependencyOutputOptions;
34class DiagnosticsEngine;
35class DiagnosticOptions;
36class FileManager;
37class HeaderSearch;
38class HeaderSearchOptions;
39class IdentifierTable;
40class LangOptions;
41class Preprocessor;
42class PreprocessorOptions;
43class PreprocessorOutputOptions;
44class SourceManager;
45class Stmt;
46class TargetInfo;
47class FrontendOptions;
48
49/// Apply the header search options to get given HeaderSearch object.
50void ApplyHeaderSearchOptions(HeaderSearch &HS,
51                              const HeaderSearchOptions &HSOpts,
52                              const LangOptions &Lang,
53                              const llvm::Triple &triple);
54
55/// InitializePreprocessor - Initialize the preprocessor getting it and the
56/// environment ready to process a single file.
57void InitializePreprocessor(Preprocessor &PP,
58                            const PreprocessorOptions &PPOpts,
59                            const HeaderSearchOptions &HSOpts,
60                            const FrontendOptions &FEOpts);
61
62/// ProcessWarningOptions - Initialize the diagnostic client and process the
63/// warning options specified on the command line.
64void ProcessWarningOptions(DiagnosticsEngine &Diags,
65                           const DiagnosticOptions &Opts);
66
67/// DoPrintPreprocessedInput - Implement -E mode.
68void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream* OS,
69                              const PreprocessorOutputOptions &Opts);
70
71/// AttachDependencyFileGen - Create a dependency file generator, and attach
72/// it to the given preprocessor.  This takes ownership of the output stream.
73void AttachDependencyFileGen(Preprocessor &PP,
74                             const DependencyOutputOptions &Opts);
75
76/// AttachHeaderIncludeGen - Create a header include list generator, and attach
77/// it to the given preprocessor.
78///
79/// \param ShowAllHeaders - If true, show all header information instead of just
80/// headers following the predefines buffer. This is useful for making sure
81/// includes mentioned on the command line are also reported, but differs from
82/// the default behavior used by -H.
83/// \param OutputPath - If non-empty, a path to write the header include
84/// information to, instead of writing to stderr.
85void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false,
86                            StringRef OutputPath = "",
87                            bool ShowDepth = true);
88
89/// CacheTokens - Cache tokens for use with PCH. Note that this requires
90/// a seekable stream.
91void CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS);
92
93/// createInvocationFromCommandLine - Construct a compiler invocation object for
94/// a command line argument vector.
95///
96/// \return A CompilerInvocation, or 0 if none was built for the given
97/// argument vector.
98CompilerInvocation *
99createInvocationFromCommandLine(ArrayRef<const char *> Args,
100                            llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
101                                llvm::IntrusiveRefCntPtr<DiagnosticsEngine>());
102
103}  // end namespace clang
104
105#endif
106