[clang][Interp][NFC] Add InterpStack::dump()
authorTimm Bäder <tbaeder@redhat.com>
Wed, 19 Jul 2023 11:55:43 +0000 (13:55 +0200)
committerTimm Bäder <tbaeder@redhat.com>
Thu, 20 Jul 2023 12:56:44 +0000 (14:56 +0200)
clang/lib/AST/Interp/InterpStack.cpp
clang/lib/AST/Interp/InterpStack.h

index c5d9a45..5ca5304 100644 (file)
@@ -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;
@@ -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<T>(Offset);
+      llvm::errs() << V;
+    });
+    llvm::errs() << "\n";
+    Offset += align(primSize(Ty));
+    ++Index;
+  }
+#endif
+}
index 14a9b69..ab4351a 100644 (file)
@@ -89,6 +89,9 @@ public:
   /// 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.