ModuleBuilder.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- CodeGen/ModuleBuilder.h - Build LLVM from ASTs ---------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the ModuleBuilder interface.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_CODEGEN_MODULEBUILDER_H
  18. #define LLVM_CLANG_CODEGEN_MODULEBUILDER_H
  19. #include "clang/AST/ASTConsumer.h"
  20. #include "clang/Basic/LLVM.h"
  21. namespace llvm {
  22. class Constant;
  23. class LLVMContext;
  24. class Module;
  25. class StringRef;
  26. namespace vfs {
  27. class FileSystem;
  28. }
  29. }
  30. namespace clang {
  31. class CodeGenOptions;
  32. class CoverageSourceInfo;
  33. class Decl;
  34. class DiagnosticsEngine;
  35. class GlobalDecl;
  36. class HeaderSearchOptions;
  37. class LangOptions;
  38. class PreprocessorOptions;
  39. namespace CodeGen {
  40. class CodeGenModule;
  41. class CGDebugInfo;
  42. }
  43. /// The primary public interface to the Clang code generator.
  44. ///
  45. /// This is not really an abstract interface.
  46. class CodeGenerator : public ASTConsumer {
  47. virtual void anchor();
  48. public:
  49. /// Return an opaque reference to the CodeGenModule object, which can
  50. /// be used in various secondary APIs. It is valid as long as the
  51. /// CodeGenerator exists.
  52. CodeGen::CodeGenModule &CGM();
  53. /// Return the module that this code generator is building into.
  54. ///
  55. /// This may return null after HandleTranslationUnit is called;
  56. /// this signifies that there was an error generating code. A
  57. /// diagnostic will have been generated in this case, and the module
  58. /// will be deleted.
  59. ///
  60. /// It will also return null if the module is released.
  61. llvm::Module *GetModule();
  62. /// Release ownership of the module to the caller.
  63. ///
  64. /// It is illegal to call methods other than GetModule on the
  65. /// CodeGenerator after releasing its module.
  66. llvm::Module *ReleaseModule();
  67. /// Return debug info code generator.
  68. CodeGen::CGDebugInfo *getCGDebugInfo();
  69. /// Given a mangled name, return a declaration which mangles that way
  70. /// which has been added to this code generator via a Handle method.
  71. ///
  72. /// This may return null if there was no matching declaration.
  73. const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
  74. /// Given a global declaration, return a mangled name for this declaration
  75. /// which has been added to this code generator via a Handle method.
  76. llvm::StringRef GetMangledName(GlobalDecl GD);
  77. /// Return the LLVM address of the given global entity.
  78. ///
  79. /// \param isForDefinition If true, the caller intends to define the
  80. /// entity; the object returned will be an llvm::GlobalValue of
  81. /// some sort. If false, the caller just intends to use the entity;
  82. /// the object returned may be any sort of constant value, and the
  83. /// code generator will schedule the entity for emission if a
  84. /// definition has been registered with this code generator.
  85. llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
  86. /// Create a new \c llvm::Module after calling HandleTranslationUnit. This
  87. /// enable codegen in interactive processing environments.
  88. llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C);
  89. };
  90. /// CreateLLVMCodeGen - Create a CodeGenerator instance.
  91. /// It is the responsibility of the caller to call delete on
  92. /// the allocated CodeGenerator instance.
  93. CodeGenerator *CreateLLVMCodeGen(DiagnosticsEngine &Diags,
  94. llvm::StringRef ModuleName,
  95. IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
  96. const HeaderSearchOptions &HeaderSearchOpts,
  97. const PreprocessorOptions &PreprocessorOpts,
  98. const CodeGenOptions &CGO,
  99. llvm::LLVMContext &C,
  100. CoverageSourceInfo *CoverageInfo = nullptr);
  101. } // end namespace clang
  102. #endif
  103. #ifdef __GNUC__
  104. #pragma GCC diagnostic pop
  105. #endif