Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:52

0001 //===--- CodeGen/ModuleBuilder.h - Build LLVM from ASTs ---------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the ModuleBuilder interface.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_CODEGEN_MODULEBUILDER_H
0014 #define LLVM_CLANG_CODEGEN_MODULEBUILDER_H
0015 
0016 #include "clang/AST/ASTConsumer.h"
0017 #include "clang/Basic/LLVM.h"
0018 #include "llvm/ADT/StringRef.h"
0019 
0020 namespace llvm {
0021   class Constant;
0022   class LLVMContext;
0023   class Module;
0024   class StringRef;
0025 
0026   namespace vfs {
0027   class FileSystem;
0028   }
0029 }
0030 
0031 // Prefix of the name of the artificial inline frame.
0032 inline constexpr llvm::StringRef ClangTrapPrefix = "__clang_trap_msg";
0033 
0034 namespace clang {
0035   class CodeGenOptions;
0036   class CoverageSourceInfo;
0037   class Decl;
0038   class DiagnosticsEngine;
0039   class GlobalDecl;
0040   class HeaderSearchOptions;
0041   class LangOptions;
0042   class PreprocessorOptions;
0043 
0044 namespace CodeGen {
0045   class CodeGenModule;
0046   class CGDebugInfo;
0047 }
0048 
0049 /// The primary public interface to the Clang code generator.
0050 ///
0051 /// This is not really an abstract interface.
0052 class CodeGenerator : public ASTConsumer {
0053   virtual void anchor();
0054 
0055 public:
0056   /// Return an opaque reference to the CodeGenModule object, which can
0057   /// be used in various secondary APIs.  It is valid as long as the
0058   /// CodeGenerator exists.
0059   CodeGen::CodeGenModule &CGM();
0060 
0061   /// Return the module that this code generator is building into.
0062   ///
0063   /// This may return null after HandleTranslationUnit is called;
0064   /// this signifies that there was an error generating code.  A
0065   /// diagnostic will have been generated in this case, and the module
0066   /// will be deleted.
0067   ///
0068   /// It will also return null if the module is released.
0069   llvm::Module *GetModule();
0070 
0071   /// Release ownership of the module to the caller.
0072   ///
0073   /// It is illegal to call methods other than GetModule on the
0074   /// CodeGenerator after releasing its module.
0075   llvm::Module *ReleaseModule();
0076 
0077   /// Return debug info code generator.
0078   CodeGen::CGDebugInfo *getCGDebugInfo();
0079 
0080   /// Given a mangled name, return a declaration which mangles that way
0081   /// which has been added to this code generator via a Handle method.
0082   ///
0083   /// This may return null if there was no matching declaration.
0084   const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
0085 
0086   /// Given a global declaration, return a mangled name for this declaration
0087   /// which has been added to this code generator via a Handle method.
0088   llvm::StringRef GetMangledName(GlobalDecl GD);
0089 
0090   /// Return the LLVM address of the given global entity.
0091   ///
0092   /// \param isForDefinition If true, the caller intends to define the
0093   ///   entity; the object returned will be an llvm::GlobalValue of
0094   ///   some sort.  If false, the caller just intends to use the entity;
0095   ///   the object returned may be any sort of constant value, and the
0096   ///   code generator will schedule the entity for emission if a
0097   ///   definition has been registered with this code generator.
0098   llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
0099 
0100   /// Create a new \c llvm::Module after calling HandleTranslationUnit. This
0101   /// enable codegen in interactive processing environments.
0102   llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C);
0103 };
0104 
0105 /// CreateLLVMCodeGen - Create a CodeGenerator instance.
0106 /// It is the responsibility of the caller to call delete on
0107 /// the allocated CodeGenerator instance.
0108 CodeGenerator *CreateLLVMCodeGen(DiagnosticsEngine &Diags,
0109                                  llvm::StringRef ModuleName,
0110                                  IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
0111                                  const HeaderSearchOptions &HeaderSearchOpts,
0112                                  const PreprocessorOptions &PreprocessorOpts,
0113                                  const CodeGenOptions &CGO,
0114                                  llvm::LLVMContext &C,
0115                                  CoverageSourceInfo *CoverageInfo = nullptr);
0116 
0117 } // end namespace clang
0118 
0119 #endif