13#ifndef LLVM_CLANG_AST_INTERP_PROGRAM_H
14#define LLVM_CLANG_AST_INTERP_PROGRAM_H
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/Support/Allocator.h"
51 for (
auto RecordPair :
Records) {
52 if (
Record *R = RecordPair.second)
72 assert(Idx < Globals.size());
73 return Globals[Idx]->block();
98 template <
typename... Ts>
101 auto *
Func =
new Function(*
this, Def, std::forward<Ts>(Args)...);
102 Funcs.insert({Def, std::unique_ptr<Function>(
Func)});
107 auto *
Func =
new Function(*
this, std::forward<Ts>(Args)...);
108 AnonFuncs.emplace_back(
Func);
120 const Type *SourceTy =
nullptr,
122 bool IsConst =
false,
bool IsTemporary =
false,
123 bool IsMutable =
false,
124 bool IsVolatile =
false) {
125 return allocateDescriptor(
D, SourceTy,
T, MDSize, IsConst, IsTemporary,
126 IsMutable, IsVolatile);
132 bool IsConst =
false,
bool IsTemporary =
false,
133 bool IsMutable =
false,
bool IsVolatile =
false,
136 void *
Allocate(
size_t Size,
unsigned Align = 8)
const {
137 return Allocator.Allocate(Size, Align);
149 P.CurrentDeclaration =
P.LastDeclaration;
160 if (CurrentDeclaration == NoDeclaration)
162 return CurrentDeclaration;
170 bool IsWeak,
const Expr *
Init =
nullptr);
175 llvm::DenseMap<const FunctionDecl *, std::unique_ptr<Function>> Funcs;
177 std::vector<std::unique_ptr<Function>> AnonFuncs;
180 std::vector<const void *> NativePointers;
182 llvm::DenseMap<const void *, unsigned> NativePointerIndices;
185 using PoolAllocTy = llvm::BumpPtrAllocator;
193 template <
typename... Tys>
197 void *
operator new(
size_t Meta, PoolAllocTy &
Alloc,
size_t Data) {
198 return Alloc.Allocate(Meta +
Data,
alignof(
void *));
202 std::byte *data() {
return B.data(); }
204 Block *block() {
return &B; }
205 const Block *block()
const {
return &B; }
213 mutable PoolAllocTy Allocator;
216 std::vector<Global *> Globals;
218 llvm::DenseMap<const void *, unsigned> GlobalIndices;
221 llvm::DenseMap<const RecordDecl *, Record *>
Records;
224 llvm::DenseMap<const void *, unsigned> DummyVariables;
227 template <
typename... Ts> Descriptor *allocateDescriptor(Ts &&...Args) {
228 return new (Allocator) Descriptor(std::forward<Ts>(Args)...);
232 static constexpr unsigned NoDeclaration = ~0u;
234 unsigned LastDeclaration = 0;
236 unsigned CurrentDeclaration = NoDeclaration;
241 void dump(llvm::raw_ostream &OS)
const;
248 size_t Alignment = 8) {
249 return C.Allocate(Bytes, Alignment);
257 size_t Alignment = 8) {
258 return C.Allocate(Bytes, Alignment);
llvm::MachO::Records Records
This represents one expression.
Represents a function declaration or definition.
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
A (possibly-)qualified type.
Represents a struct/union/class.
StringLiteral - This represents a string literal expression, e.g.
The base class of the type hierarchy.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
A memory block, either on the stack or in the heap.
bool isInitialized() const
Returns whether the data of this block has been initialized via invoking the Ctor func.
Holds all information required to evaluate constexpr code in a module.
A pointer to a memory block, live or dead.
bool isInitialized() const
Checks if an object was initialized.
Context to manage declaration lifetimes.
The program contains and links the bytecode for all functions.
void * Allocate(size_t Size, unsigned Align=8) const
std::optional< unsigned > getOrCreateGlobal(const ValueDecl *VD, const Expr *Init=nullptr)
Returns or creates a global an creates an index to it.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Block * getGlobal(unsigned Idx)
Returns the value of a global.
std::optional< unsigned > createGlobal(const ValueDecl *VD, const Expr *Init)
Creates a global and returns its index.
const void * getNativePointer(unsigned Idx)
Returns the value of a marshalled native pointer.
unsigned getOrCreateNativePointer(const void *Ptr)
Marshals a native pointer to an ID for embedding in bytecode.
Function * createFunction(const FunctionDecl *Def, Ts &&...Args)
Creates a new function from a code range.
bool isGlobalInitialized(unsigned Index) const
Pointer getPtrGlobal(unsigned Idx) const
Returns a pointer to a global.
unsigned getOrCreateDummy(const DeclTy &D)
Returns or creates a dummy value for unknown declarations.
void dump() const
Dumps the disassembled bytecode to llvm::errs().
T * Allocate(size_t Num=1) const
void Deallocate(void *Ptr) const
Descriptor * createDescriptor(const DeclTy &D, PrimType T, const Type *SourceTy=nullptr, Descriptor::MetadataSize MDSize=std::nullopt, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false, bool IsVolatile=false)
Creates a descriptor for a primitive type.
unsigned createGlobalString(const StringLiteral *S, const Expr *Base=nullptr)
Emits a string literal among global data.
Function * createFunction(Ts &&...Args)
Creates an anonymous function.
UnsignedOrNone getCurrentDecl() const
Returns the current declaration ID.
Record * getOrCreateRecord(const RecordDecl *RD)
Returns a record or creates one if it does not exist.
Structure/Class descriptor.
PrimType
Enumeration of the primitive types of the VM.
bool Alloc(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
Describes a memory block created by an allocation site.
std::optional< unsigned > MetadataSize