CompilerInvocation.h revision 06057cef0bcd7804e80f3ce2bbe352178396c715
1//===-- CompilerInvocation.h - Compiler Invocation Helper Data --*- 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#ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_
11#define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_
12
13#include "clang/Basic/LangOptions.h"
14#include "clang/Basic/TargetOptions.h"
15#include "clang/Frontend/AnalyzerOptions.h"
16#include "clang/Frontend/CodeGenOptions.h"
17#include "clang/Frontend/DependencyOutputOptions.h"
18#include "clang/Frontend/DiagnosticOptions.h"
19#include "clang/Frontend/FrontendOptions.h"
20#include "clang/Frontend/HeaderSearchOptions.h"
21#include "clang/Frontend/PreprocessorOptions.h"
22#include "clang/Frontend/PreprocessorOutputOptions.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/ADT/StringMap.h"
25#include <string>
26#include <vector>
27
28namespace llvm {
29  template<typename T> class SmallVectorImpl;
30}
31
32namespace clang {
33
34class Diagnostic;
35
36/// CompilerInvocation - Helper class for holding the data necessary to invoke
37/// the compiler.
38///
39/// This class is designed to represent an abstract "invocation" of the
40/// compiler, including data such as the include paths, the code generation
41/// options, the warning flags, and so on.
42class CompilerInvocation {
43  /// Options controlling the static analyzer.
44  AnalyzerOptions AnalyzerOpts;
45
46  /// Options controlling IRgen and the backend.
47  CodeGenOptions CodeGenOpts;
48
49  /// Options controlling dependency output.
50  DependencyOutputOptions DependencyOutputOpts;
51
52  /// Options controlling the diagnostic engine.
53  DiagnosticOptions DiagnosticOpts;
54
55  /// Options controlling the frontend itself.
56  FrontendOptions FrontendOpts;
57
58  /// Options controlling the #include directive.
59  HeaderSearchOptions HeaderSearchOpts;
60
61  /// Options controlling the language variant.
62  LangOptions LangOpts;
63
64  /// Options controlling the preprocessor (aside from #include handling).
65  PreprocessorOptions PreprocessorOpts;
66
67  /// Options controlling preprocessed output.
68  PreprocessorOutputOptions PreprocessorOutputOpts;
69
70  /// Options controlling the target.
71  TargetOptions TargetOpts;
72
73public:
74  CompilerInvocation() {}
75
76  /// @name Utility Methods
77  /// @{
78
79  /// CreateFromArgs - Create a compiler invocation from a list of input
80  /// options.
81  ///
82  /// \param Res [out] - The resulting invocation.
83  /// \param ArgBegin - The first element in the argument vector.
84  /// \param ArgEnd - The last element in the argument vector.
85  /// \param Diags - The diagnostic engine to use for errors.
86  static void CreateFromArgs(CompilerInvocation &Res, const char **ArgBegin,
87                             const char **ArgEnd, Diagnostic &Diags);
88
89  /// GetBuiltinIncludePath - Get the directory where the compiler headers
90  /// reside, relative to the compiler binary (found by the passed in
91  /// arguments).
92  ///
93  /// \param Argv0 - The program path (from argv[0]), for finding the builtin
94  /// compiler path.
95  /// \param MainAddr - The address of main (or some other function in the main
96  /// executable), for finding the builtin compiler path.
97  static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
98
99  /// toArgs - Convert the CompilerInvocation to a list of strings suitable for
100  /// passing to CreateFromArgs.
101  void toArgs(std::vector<std::string> &Res);
102
103  /// @}
104  /// @name Option Subgroups
105  /// @{
106
107  AnalyzerOptions &getAnalyzerOpts() { return AnalyzerOpts; }
108  const AnalyzerOptions &getAnalyzerOpts() const {
109    return AnalyzerOpts;
110  }
111
112  CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
113  const CodeGenOptions &getCodeGenOpts() const {
114    return CodeGenOpts;
115  }
116
117  DependencyOutputOptions &getDependencyOutputOpts() {
118    return DependencyOutputOpts;
119  }
120  const DependencyOutputOptions &getDependencyOutputOpts() const {
121    return DependencyOutputOpts;
122  }
123
124  DiagnosticOptions &getDiagnosticOpts() { return DiagnosticOpts; }
125  const DiagnosticOptions &getDiagnosticOpts() const { return DiagnosticOpts; }
126
127  HeaderSearchOptions &getHeaderSearchOpts() { return HeaderSearchOpts; }
128  const HeaderSearchOptions &getHeaderSearchOpts() const {
129    return HeaderSearchOpts;
130  }
131
132  FrontendOptions &getFrontendOpts() { return FrontendOpts; }
133  const FrontendOptions &getFrontendOpts() const {
134    return FrontendOpts;
135  }
136
137  LangOptions &getLangOpts() { return LangOpts; }
138  const LangOptions &getLangOpts() const { return LangOpts; }
139
140  PreprocessorOptions &getPreprocessorOpts() { return PreprocessorOpts; }
141  const PreprocessorOptions &getPreprocessorOpts() const {
142    return PreprocessorOpts;
143  }
144
145  PreprocessorOutputOptions &getPreprocessorOutputOpts() {
146    return PreprocessorOutputOpts;
147  }
148  const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
149    return PreprocessorOutputOpts;
150  }
151
152  TargetOptions &getTargetOpts() { return TargetOpts; }
153  const TargetOptions &getTargetOpts() const {
154    return TargetOpts;
155  }
156
157  /// @}
158};
159
160} // end namespace clang
161
162#endif
163