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