Skip to content

Commit

Permalink
[clang][Interp][NFC] Add InterpStack::dump()
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Jul 20, 2023
1 parent cc77da5 commit 3203d3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 22 additions & 1 deletion clang/lib/AST/Interp/InterpStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions clang/lib/AST/Interp/InterpStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3203d3e

Please sign in to comment.