diff --git a/clang/lib/AST/Interp/InterpStack.cpp b/clang/lib/AST/Interp/InterpStack.cpp index c5d9a459ce824..5ca530409c8bf 100644 --- a/clang/lib/AST/Interp/InterpStack.cpp +++ b/clang/lib/AST/Interp/InterpStack.cpp @@ -6,9 +6,12 @@ // //===----------------------------------------------------------------------===// +#include "InterpStack.h" +#include "Boolean.h" +#include "Floating.h" +#include "Integral.h" #include #include -#include "InterpStack.h" using namespace clang; using namespace clang::interp; @@ -79,3 +82,21 @@ 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"; + 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(Offset); + llvm::errs() << V; + }); + llvm::errs() << "\n"; + Offset += align(primSize(Ty)); + ++Index; + } +#endif +} diff --git a/clang/lib/AST/Interp/InterpStack.h b/clang/lib/AST/Interp/InterpStack.h index 14a9b69a557c1..ab4351a6dc679 100644 --- a/clang/lib/AST/Interp/InterpStack.h +++ b/clang/lib/AST/Interp/InterpStack.h @@ -89,6 +89,9 @@ class InterpStack final { /// Returns whether the stack is empty. bool empty() const { return StackSize == 0; } + /// dump the stack contents to stderr. + void dump() const; + private: /// All stack slots are aligned to the native pointer alignment for storage. /// The size of an object is rounded up to a pointer alignment multiple.