Go to the documentation of this file.
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/ADT/PointerUnion.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Support/Allocator.h"
58 assert(Idx < Globals.size());
59 return Globals[Idx]->block();
78 template <
typename... Ts>
80 auto *Func =
new Function(*
this, Def, std::forward<Ts>(Args)...);
81 Funcs.insert({Def, std::unique_ptr<Function>(Func)});
85 template <
typename... Ts>
87 auto *Func =
new Function(*
this, std::forward<Ts>(Args)...);
88 AnonFuncs.emplace_back(Func);
105 bool IsConst =
false,
106 bool IsTemporary =
false,
107 bool IsMutable =
false) {
108 return allocateDescriptor(D,
Type, IsConst, IsTemporary, IsMutable);
113 bool IsConst =
false,
bool IsTemporary =
false,
114 bool IsMutable =
false);
128 if (CurrentDeclaration == NoDeclaration)
130 return LastDeclaration;
142 llvm::DenseMap<const FunctionDecl *, std::unique_ptr<Function>> Funcs;
144 std::vector<std::unique_ptr<Function>> AnonFuncs;
147 llvm::DenseMap<const FunctionDecl *, std::vector<unsigned>> Relocs;
150 std::vector<const void *> NativePointers;
152 llvm::DenseMap<const void *, unsigned> NativePointerIndices;
155 using PoolAllocTy = llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator>;
163 template <
typename... Tys>
164 Global(Tys... Args) : B(
std::forward<Tys>(Args)...) {}
167 void *
operator new(
size_t Meta, PoolAllocTy &Alloc,
size_t Data) {
168 return Alloc.Allocate(Meta + Data,
alignof(
void *));
172 char *data() {
return B.data(); }
174 Block *block() {
return &B; }
182 PoolAllocTy Allocator;
185 std::vector<Global *> Globals;
187 llvm::DenseMap<const void *, unsigned> GlobalIndices;
190 llvm::DenseMap<const RecordDecl *, Record *> Records;
193 llvm::DenseMap<const ParmVarDecl *, unsigned> DummyParams;
196 template <
typename... Ts>
197 Descriptor *allocateDescriptor(Ts &&... Args) {
198 return new (Allocator) Descriptor(std::forward<Ts>(Args)...);
202 static constexpr
unsigned NoDeclaration = (
unsigned)-1;
204 unsigned LastDeclaration = 0;
206 unsigned CurrentDeclaration = NoDeclaration;
209 void startDeclaration(
const VarDecl *Decl) {
210 LastDeclaration += 1;
211 CurrentDeclaration = LastDeclaration;
215 void endDeclaration() {
216 CurrentDeclaration = NoDeclaration;
222 void dump(llvm::raw_ostream &OS)
const;
Function * createFunction(Ts &&... Args)
Creates an anonymous function.
A (possibly-)qualified type.
Context to manage declaration lifetimes.
Represents a parameter to a function.
Holds all information required to evaluate constexpr code in a module.
llvm::Optional< unsigned > getCurrentDecl() const
Returns the current declaration ID.
Function * getFunction(const FunctionDecl *F)
Returns a function.
A pointer to a memory block, live or dead.
The base class of the type hierarchy.
Block * getGlobal(unsigned Idx)
Returns the value of a global.
DeclScope(Program &P, const VarDecl *VD)
Descriptor * createDescriptor(const DeclTy &D, PrimType Type, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false)
Creates a descriptor for a primitive type.
A memory block, either on the stack or in the heap.
PrimType
Enumeration of the primitive types of the VM.
Represents a variable declaration or definition.
StringLiteral - This represents a string literal expression, e.g.
unsigned getOrCreateNativePointer(const void *Ptr)
Marshals a native pointer to an ID for embedding in bytecode.
llvm::Expected< Function * > getOrCreateFunction(const FunctionDecl *F)
Returns a pointer to a function if it exists and can be compiled.
llvm::Optional< unsigned > getOrCreateGlobal(const ValueDecl *VD)
Returns or creates a global an creates an index to it.
Record * getOrCreateRecord(const RecordDecl *RD)
Returns a record or creates one if it does not exist.
Pointer getPtrGlobal(unsigned Idx)
Returns a pointer to a global.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
void dump() const
Dumps the disassembled bytecode to llvm::errs().
llvm::Optional< unsigned > getOrCreateDummy(const ParmVarDecl *PD)
Returns or creates a dummy value for parameters.
Describes a memory block created by an allocation site.
Function * createFunction(const FunctionDecl *Def, Ts &&... Args)
Creates a new function from a code range.
unsigned llvm::PointerUnion< const Decl *, const Expr * > DeclTy
unsigned createGlobalString(const StringLiteral *S)
Emits a string literal among global data.
The program contains and links the bytecode for all functions.
This represents one expression.
llvm::Optional< unsigned > createGlobal(const ValueDecl *VD)
Creates a global and returns its index.
Structure/Class descriptor.
Represents a function declaration or definition.
Represents a struct/union/class.
const void * getNativePointer(unsigned Idx)
Returns the value of a marshalled native pointer.