ModuleBuilder.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. namespace llvm {
  21. class Constant;
  22. class LLVMContext;
  23. class Module;
  24. class StringRef;
  25. }
  26. namespace clang {
  27. class CodeGenOptions;
  28. class CoverageSourceInfo;
  29. class Decl;
  30. class DiagnosticsEngine;
  31. class GlobalDecl;
  32. class HeaderSearchOptions;
  33. class LangOptions;
  34. class PreprocessorOptions;
  35. namespace CodeGen {
  36. class CodeGenModule;
  37. class CGDebugInfo;
  38. }
  39. /// The primary public interface to the Clang code generator.
  40. ///
  41. /// This is not really an abstract interface.
  42. class CodeGenerator : public ASTConsumer {
  43. virtual void anchor();
  44. public:
  45. /// Return an opaque reference to the CodeGenModule object, which can
  46. /// be used in various secondary APIs. It is valid as long as the
  47. /// CodeGenerator exists.
  48. CodeGen::CodeGenModule &CGM();
  49. /// Return the module that this code generator is building into.
  50. ///
  51. /// This may return null after HandleTranslationUnit is called;
  52. /// this signifies that there was an error generating code. A
  53. /// diagnostic will have been generated in this case, and the module
  54. /// will be deleted.
  55. ///
  56. /// It will also return null if the module is released.
  57. llvm::Module *GetModule();
  58. /// Release ownership of the module to the caller.
  59. ///
  60. /// It is illegal to call methods other than GetModule on the
  61. /// CodeGenerator after releasing its module.
  62. llvm::Module *ReleaseModule();
  63. /// Return debug info code generator.
  64. CodeGen::CGDebugInfo *getCGDebugInfo();
  65. /// Given a mangled name, return a declaration which mangles that way
  66. /// which has been added to this code generator via a Handle method.
  67. ///
  68. /// This may return null if there was no matching declaration.
  69. const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
  70. /// Given a global declaration, return a mangled name for this declaration
  71. /// which has been added to this code generator via a Handle method.
  72. llvm::StringRef GetMangledName(GlobalDecl GD);
  73. /// Return the LLVM address of the given global entity.
  74. ///
  75. /// \param isForDefinition If true, the caller intends to define the
  76. /// entity; the object returned will be an llvm::GlobalValue of
  77. /// some sort. If false, the caller just intends to use the entity;
  78. /// the object returned may be any sort of constant value, and the
  79. /// code generator will schedule the entity for emission if a
  80. /// definition has been registered with this code generator.
  81. llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
  82. /// Create a new \c llvm::Module after calling HandleTranslationUnit. This
  83. /// enable codegen in interactive processing environments.
  84. llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C);
  85. };
  86. /// CreateLLVMCodeGen - Create a CodeGenerator instance.
  87. /// It is the responsibility of the caller to call delete on
  88. /// the allocated CodeGenerator instance.
  89. CodeGenerator *CreateLLVMCodeGen(DiagnosticsEngine &Diags,
  90. llvm::StringRef ModuleName,
  91. const HeaderSearchOptions &HeaderSearchOpts,
  92. const PreprocessorOptions &PreprocessorOpts,
  93. const CodeGenOptions &CGO,
  94. llvm::LLVMContext& C,
  95. CoverageSourceInfo *CoverageInfo = nullptr);
  96. } // end namespace clang
  97. #endif
  98. #ifdef __GNUC__
  99. #pragma GCC diagnostic pop
  100. #endif