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" 55 assert(Idx < Globals.size());
56 return Globals[Idx]->block();
75 template <
typename... Ts>
77 auto *Func =
new Function(*
this, Def, std::forward<Ts>(Args)...);
78 Funcs.insert({Def, std::unique_ptr<Function>(Func)});
82 template <
typename... Ts>
84 auto *Func =
new Function(*
this, std::forward<Ts>(Args)...);
85 AnonFuncs.emplace_back(Func);
102 bool IsConst =
false,
103 bool IsTemporary =
false,
104 bool IsMutable =
false) {
105 return allocateDescriptor(D, Type, IsConst, IsTemporary, IsMutable);
110 bool IsConst =
false,
bool IsTemporary =
false,
111 bool IsMutable =
false);
125 if (CurrentDeclaration == NoDeclaration)
127 return LastDeclaration;
139 llvm::DenseMap<const FunctionDecl *, std::unique_ptr<Function>> Funcs;
141 std::vector<std::unique_ptr<Function>> AnonFuncs;
144 llvm::DenseMap<const FunctionDecl *, std::vector<unsigned>> Relocs;
147 using PoolAllocTy = llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator>;
155 template <
typename... Tys>
156 Global(Tys... Args) : B(
std::forward<Tys>(Args)...) {}
159 void *
operator new(
size_t Meta, PoolAllocTy &Alloc,
size_t Data) {
160 return Alloc.Allocate(Meta + Data,
alignof(
void *));
164 char *data() {
return B.data(); }
166 Block *block() {
return &B; }
174 PoolAllocTy Allocator;
177 std::vector<Global *> Globals;
179 llvm::DenseMap<const void *, unsigned> GlobalIndices;
182 llvm::DenseMap<const RecordDecl *, Record *> Records;
185 llvm::DenseMap<const ParmVarDecl *, unsigned> DummyParams;
188 template <
typename... Ts>
189 Descriptor *allocateDescriptor(Ts &&... Args) {
190 return new (Allocator)
Descriptor(std::forward<Ts>(Args)...);
194 static constexpr
unsigned NoDeclaration = (unsigned)-1;
196 unsigned LastDeclaration = 0;
198 unsigned CurrentDeclaration = NoDeclaration;
202 LastDeclaration += 1;
203 CurrentDeclaration = LastDeclaration;
207 void endDeclaration() {
208 CurrentDeclaration = NoDeclaration;
214 void dump(llvm::raw_ostream &OS)
const;
Represents a function declaration or definition.
unsigned llvm::PointerUnion< const Decl *, const Expr * > DeclTy
A (possibly-)qualified type.
unsigned createGlobalString(const StringLiteral *S)
Emits a string literal among global data.
Decl - This represents one declaration (or definition), e.g.
Descriptor * createDescriptor(const DeclTy &D, PrimType Type, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false)
Creates a descriptor for a primitive type.
The base class of the type hierarchy.
llvm::Optional< unsigned > getCurrentDecl() const
Returns the current declaration ID.
Represents a variable declaration or definition.
Holds all information required to evaluate constexpr code in a module.
Represents a parameter to a function.
Represents a struct/union/class.
A pointer to a memory block, live or dead.
A memory block, either on the stack or in the heap.
Pointer getPtrGlobal(unsigned Idx)
Returns a pointer to a global.
Structure/Class descriptor.
Function * createFunction(Ts &&... Args)
Creates an anonymous function.
PrimType
Enumeration of the primitive types of the VM.
Context to manage declaration lifetimes.
Describes a memory block created by an allocation site.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
Record * getOrCreateRecord(const RecordDecl *RD)
Returns a record or creates one if it does not exist.
Block * getGlobal(unsigned Idx)
Returns the value of a global.
llvm::Optional< unsigned > getOrCreateDummy(const ParmVarDecl *PD)
Returns or creates a dummy value for parameters.
The program contains and links the bytecode for all functions.
Function * createFunction(const FunctionDecl *Def, Ts &&... Args)
Creates a new function from a code range.
llvm::Expected< Function * > getOrCreateFunction(const FunctionDecl *F)
Returns a pointer to a function if it exists and can be compiled.
Dataflow Directional Tag Classes.
llvm::Optional< unsigned > createGlobal(const ValueDecl *VD)
Creates a global and returns its index.
llvm::Optional< unsigned > getOrCreateGlobal(const ValueDecl *VD)
Returns or creates a global an creates an index to it.
StringLiteral - This represents a string literal expression, e.g.
DeclScope(Program &P, const VarDecl *VD)
void dump() const
Dumps the disassembled bytecode to llvm::errs().