CompilerInvocation.h 5.4 KB

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