25 if (Chunk && Chunk->Next)
26 std::free(Chunk->Next);
36void *InterpStack::grow(
size_t Size) {
37 assert(Size < ChunkSize -
sizeof(StackChunk) &&
"Object too large");
39 if (!Chunk ||
sizeof(StackChunk) + Chunk->size() + Size > ChunkSize) {
40 if (Chunk && Chunk->Next) {
43 StackChunk *Next =
new (std::malloc(ChunkSize)) StackChunk(Chunk);
50 auto *
Object =
reinterpret_cast<void *
>(Chunk->End);
56void *InterpStack::peekData(
size_t Size)
const {
57 assert(Chunk &&
"Stack is empty!");
59 StackChunk *Ptr = Chunk;
60 while (Size > Ptr->size()) {
63 assert(Ptr &&
"Offset too large");
66 return reinterpret_cast<void *
>(Ptr->End -
Size);
69void InterpStack::shrink(
size_t Size) {
70 assert(Chunk &&
"Chunk is empty!");
72 while (Size > Chunk->size()) {
73 Size -= Chunk->size();
75 std::free(Chunk->Next);
76 Chunk->Next =
nullptr;
78 Chunk->End = Chunk->start();
80 assert(Chunk &&
"Offset too large");
89 llvm::errs() <<
"Items: " << ItemTypes.size() <<
". Size: " <<
size() <<
'\n';
90 if (ItemTypes.empty())
98 for (
auto TyIt = ItemTypes.rbegin(); TyIt != ItemTypes.rend(); ++TyIt) {
101 llvm::errs() << Index <<
'/' << Offset <<
": ";
103 const T &
V = peek<T>(Offset);
106 llvm::errs() <<
'\n';
#define TYPE_SWITCH(Expr, B)
void dump() const
dump the stack contents to stderr.
void clear()
Clears the stack without calling any destructors.
size_t size() const
Returns the size of the stack in bytes.
~InterpStack()
Destroys the stack, freeing up storage.
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.