aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/AST/Interp/InterpStack.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-09-02 21:17:18 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-12-08 17:34:50 +0000
commit06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e (patch)
tree62f873df87c7c675557a179e0c4c83fe9f3087bc /contrib/llvm-project/clang/lib/AST/Interp/InterpStack.cpp
parentcf037972ea8863e2bab7461d77345367d2c1e054 (diff)
parent7fa27ce4a07f19b07799a767fc29416f3b625afb (diff)
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/Interp/InterpStack.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/AST/Interp/InterpStack.cpp39
1 files changed, 33 insertions, 6 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/Interp/InterpStack.cpp b/contrib/llvm-project/clang/lib/AST/Interp/InterpStack.cpp
index 7fe678e62192..da4b36f8c1bf 100644
--- a/contrib/llvm-project/clang/lib/AST/Interp/InterpStack.cpp
+++ b/contrib/llvm-project/clang/lib/AST/Interp/InterpStack.cpp
@@ -6,9 +6,12 @@
//
//===----------------------------------------------------------------------===//
+#include "InterpStack.h"
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
#include <cassert>
#include <cstdlib>
-#include "InterpStack.h"
using namespace clang;
using namespace clang::interp;
@@ -19,11 +22,14 @@ InterpStack::~InterpStack() {
void InterpStack::clear() {
if (Chunk && Chunk->Next)
- free(Chunk->Next);
+ std::free(Chunk->Next);
if (Chunk)
- free(Chunk);
+ std::free(Chunk);
Chunk = nullptr;
StackSize = 0;
+#ifndef NDEBUG
+ ItemTypes.clear();
+#endif
}
void *InterpStack::grow(size_t Size) {
@@ -33,7 +39,7 @@ void *InterpStack::grow(size_t Size) {
if (Chunk && Chunk->Next) {
Chunk = Chunk->Next;
} else {
- StackChunk *Next = new (malloc(ChunkSize)) StackChunk(Chunk);
+ StackChunk *Next = new (std::malloc(ChunkSize)) StackChunk(Chunk);
if (Chunk)
Chunk->Next = Next;
Chunk = Next;
@@ -46,7 +52,7 @@ void *InterpStack::grow(size_t Size) {
return Object;
}
-void *InterpStack::peek(size_t Size) const {
+void *InterpStack::peekData(size_t Size) const {
assert(Chunk && "Stack is empty!");
StackChunk *Ptr = Chunk;
@@ -65,7 +71,7 @@ void InterpStack::shrink(size_t Size) {
while (Size > Chunk->size()) {
Size -= Chunk->size();
if (Chunk->Next) {
- free(Chunk->Next);
+ std::free(Chunk->Next);
Chunk->Next = nullptr;
}
Chunk->End = Chunk->start();
@@ -76,3 +82,24 @@ void InterpStack::shrink(size_t Size) {
Chunk->End -= Size;
StackSize -= Size;
}
+
+void InterpStack::dump() const {
+#ifndef NDEBUG
+ llvm::errs() << "Items: " << ItemTypes.size() << ". Size: " << size() << "\n";
+ if (ItemTypes.empty())
+ return;
+
+ size_t Index = 0;
+ size_t Offset = align(primSize(ItemTypes[0]));
+ for (PrimType Ty : ItemTypes) {
+ llvm::errs() << Index << "/" << Offset << ": ";
+ TYPE_SWITCH(Ty, {
+ const T &V = peek<T>(Offset);
+ llvm::errs() << V;
+ });
+ llvm::errs() << "\n";
+ Offset += align(primSize(Ty));
+ ++Index;
+ }
+#endif
+}