clang 19.0.0git
ModuleBuilder.h
Go to the documentation of this file.
1//===--- CodeGen/ModuleBuilder.h - Build LLVM from ASTs ---------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ModuleBuilder interface.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_CODEGEN_MODULEBUILDER_H
14#define LLVM_CLANG_CODEGEN_MODULEBUILDER_H
15
17#include "clang/Basic/LLVM.h"
18
19namespace llvm {
20 class Constant;
21 class LLVMContext;
22 class Module;
23 class StringRef;
24
25 namespace vfs {
26 class FileSystem;
27 }
28}
29
30namespace 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
40namespace CodeGen {
41 class CodeGenModule;
42 class CGDebugInfo;
43}
44
45/// The primary public interface to the Clang code generator.
46///
47/// This is not really an abstract interface.
48class CodeGenerator : public ASTConsumer {
49 virtual void anchor();
50
51public:
52 /// Return an opaque reference to the CodeGenModule object, which can
53 /// be used in various secondary APIs. It is valid as long as the
54 /// CodeGenerator exists.
56
57 /// Return the module that this code generator is building into.
58 ///
59 /// This may return null after HandleTranslationUnit is called;
60 /// this signifies that there was an error generating code. A
61 /// diagnostic will have been generated in this case, and the module
62 /// will be deleted.
63 ///
64 /// It will also return null if the module is released.
65 llvm::Module *GetModule();
66
67 /// Release ownership of the module to the caller.
68 ///
69 /// It is illegal to call methods other than GetModule on the
70 /// CodeGenerator after releasing its module.
71 llvm::Module *ReleaseModule();
72
73 /// Return debug info code generator.
75
76 /// Given a mangled name, return a declaration which mangles that way
77 /// which has been added to this code generator via a Handle method.
78 ///
79 /// This may return null if there was no matching declaration.
80 const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
81
82 /// Given a global declaration, return a mangled name for this declaration
83 /// which has been added to this code generator via a Handle method.
84 llvm::StringRef GetMangledName(GlobalDecl GD);
85
86 /// Return the LLVM address of the given global entity.
87 ///
88 /// \param isForDefinition If true, the caller intends to define the
89 /// entity; the object returned will be an llvm::GlobalValue of
90 /// some sort. If false, the caller just intends to use the entity;
91 /// the object returned may be any sort of constant value, and the
92 /// code generator will schedule the entity for emission if a
93 /// definition has been registered with this code generator.
94 llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
95
96 /// Create a new \c llvm::Module after calling HandleTranslationUnit. This
97 /// enable codegen in interactive processing environments.
98 llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C);
99};
100
101/// CreateLLVMCodeGen - Create a CodeGenerator instance.
102/// It is the responsibility of the caller to call delete on
103/// the allocated CodeGenerator instance.
105 llvm::StringRef ModuleName,
107 const HeaderSearchOptions &HeaderSearchOpts,
108 const PreprocessorOptions &PreprocessorOpts,
109 const CodeGenOptions &CGO,
110 llvm::LLVMContext &C,
111 CoverageSourceInfo *CoverageInfo = nullptr);
112
113} // end namespace clang
114
115#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:33
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:55
This class organizes the cross-function state that is used while generating LLVM code.
The primary public interface to the Clang code generator.
Definition: ModuleBuilder.h:48
llvm::Module * ReleaseModule()
Release ownership of the module to the caller.
const Decl * GetDeclForMangledName(llvm::StringRef MangledName)
Given a mangled name, return a declaration which mangles that way which has been added to this code g...
llvm::Module * StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C)
Create a new llvm::Module after calling HandleTranslationUnit.
llvm::Constant * GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition)
Return the LLVM address of the given global entity.
llvm::StringRef GetMangledName(GlobalDecl GD)
Given a global declaration, return a mangled name for this declaration which has been added to this c...
CodeGen::CGDebugInfo * getCGDebugInfo()
Return debug info code generator.
CodeGen::CodeGenModule & CGM()
Return an opaque reference to the CodeGenModule object, which can be used in various secondary APIs.
llvm::Module * GetModule()
Return the module that this code generator is building into.
Stores additional source code information like skipped ranges which is required by the coverage mappi...
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
CodeGenerator * CreateLLVMCodeGen(DiagnosticsEngine &Diags, llvm::StringRef ModuleName, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, const HeaderSearchOptions &HeaderSearchOpts, const PreprocessorOptions &PreprocessorOpts, const CodeGenOptions &CGO, llvm::LLVMContext &C, CoverageSourceInfo *CoverageInfo=nullptr)
CreateLLVMCodeGen - Create a CodeGenerator instance.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30