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
22 namespace llvm {
23 class raw_fd_ostream;
24 class Triple;
25
26 namespace opt {
27 class ArgList;
28 }
29 }
30
31 namespace clang {
32 class ASTConsumer;
33 class CompilerInstance;
34 class CompilerInvocation;
35 class Decl;
36 class DependencyOutputOptions;
37 class DiagnosticsEngine;
38 class DiagnosticOptions;
39 class FileManager;
40 class HeaderSearch;
41 class HeaderSearchOptions;
42 class IdentifierTable;
43 class LangOptions;
44 class Preprocessor;
45 class PreprocessorOptions;
46 class PreprocessorOutputOptions;
47 class SourceManager;
48 class Stmt;
49 class TargetInfo;
50 class FrontendOptions;
51
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);
57
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);
64
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);
70
71 /// DoPrintPreprocessedInput - Implement -E mode.
72 void 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.
77 void 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 void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false,
95 StringRef OutputPath = "",
96 bool ShowDepth = true);
97
98 /// CacheTokens - Cache tokens for use with PCH. Note that this requires
99 /// a seekable stream.
100 void CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS);
101
102 /// createInvocationFromCommandLine - Construct a compiler invocation object for
103 /// a command line argument vector.
104 ///
105 /// \return A CompilerInvocation, or 0 if none was built for the given
106 /// argument vector.
107 CompilerInvocation *
108 createInvocationFromCommandLine(ArrayRef<const char *> Args,
109 IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
110 IntrusiveRefCntPtr<DiagnosticsEngine>());
111
112 /// Return the value of the last argument as an integer, or a default. If Diags
113 /// is non-null, emits an error if the argument is given, but non-integral.
114 int getLastArgIntValue(const llvm::opt::ArgList &Args,
115 llvm::opt::OptSpecifier Id, int Default,
116 DiagnosticsEngine *Diags = 0);
117
getLastArgIntValue(const llvm::opt::ArgList & Args,llvm::opt::OptSpecifier Id,int Default,DiagnosticsEngine & Diags)118 inline int getLastArgIntValue(const llvm::opt::ArgList &Args,
119 llvm::opt::OptSpecifier Id, int Default,
120 DiagnosticsEngine &Diags) {
121 return getLastArgIntValue(Args, Id, Default, &Diags);
122 }
123
124 } // end namespace clang
125
126 #endif
127