13#ifndef LLVM_CLANG_AST_INTERP_PROGRAM_H
14#define LLVM_CLANG_AST_INTERP_PROGRAM_H
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/Support/Allocator.h"
46 for (
Block *G : Globals)
47 if (G->isInitialized())
53 for (
const auto &RecordPair : Records) {
54 if (
Record *R = RecordPair.second)
69 assert(Idx < Globals.size());
87 bool IsConstexprUnknown =
false,
88 bool CanBeExtern =
true);
94 template <
typename... Ts>
98 Function(Def, std::forward<Ts>(Args)...);
99 Funcs.insert({Def,
Func});
105 AnonFuncs.emplace_back(
Func);
117 const Type *SourceTy =
nullptr,
118 bool IsConst =
false,
bool IsTemporary =
false,
119 bool IsMutable =
false,
120 bool IsVolatile =
false) {
121 return allocateDescriptor(D, SourceTy,
T, IsConst, IsTemporary, IsMutable,
127 bool IsConst =
false,
bool IsTemporary =
false,
128 bool IsMutable =
false,
bool IsVolatile =
false,
132 return Allocator.Allocate(Size, Align);
144 P.CurrentDeclaration = P.LastDeclaration;
155 if (CurrentDeclaration == NoDeclaration)
157 return CurrentDeclaration;
164 bool IsWeak,
bool IsConstexprUnknown,
170 llvm::DenseMap<const FunctionDecl *, Function *> Funcs;
172 std::vector<std::unique_ptr<Function>> AnonFuncs;
175 llvm::BumpPtrAllocator Allocator;
178 std::vector<Block *> Globals;
180 llvm::DenseMap<const void *, unsigned> GlobalIndices;
183 llvm::DenseMap<const RecordDecl *, Record *> Records;
186 template <
typename... Ts>
Descriptor *allocateDescriptor(Ts &&...Args) {
187 return new (Allocator)
Descriptor(std::forward<Ts>(Args)...);
191 static constexpr unsigned NoDeclaration = ~0u;
193 unsigned LastDeclaration = 0;
195 unsigned CurrentDeclaration = NoDeclaration;
200 void dump(llvm::raw_ostream &OS)
const;
207 size_t Alignment = 8) {
208 return C.Allocate(Bytes, Alignment);
215 size_t Alignment = 8) {
216 return C.Allocate(Bytes, Alignment);
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
This represents one expression.
Represents a function declaration or definition.
A (possibly-)qualified type.
Represents a struct/union/class.
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
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 ...
Represents a variable declaration or definition.
A memory block, either on the stack or in the heap.
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.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Block * getGlobal(unsigned Idx)
Returns the value of a global.
Descriptor * createDescriptor(DeclOrExpr D, PrimType T, const Type *SourceTy=nullptr, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false, bool IsVolatile=false)
Creates a descriptor for a primitive type.
T * Allocate(size_t Num=1)
const Context & getContext() const
UnsignedOrNone getOrCreateGlobal(const ValueDecl *VD, const Expr *Init=nullptr)
Returns or creates a global an creates an index to it.
UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init, bool IsConstexprUnknown=false, bool CanBeExtern=true)
Creates a global and returns its index.
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.
void dump() const
Dumps the disassembled bytecode to llvm::errs().
void Deallocate(void *Ptr) const
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.
void * Allocate(size_t Size, unsigned Align=8)
Structure/Class descriptor.
PrimType
Enumeration of the primitive types of the VM.
bool Init(InterpState &S, CodePtr OpPC)
Top level wrappers for InstallAPI frontend operations.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
Describes a memory block created by an allocation site.