[clang] [clang][bytecode] Add Descriptor::dumpFull (PR #127386)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 16 02:47:03 PST 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/127386
This is useful to print all (or most) of the valid offsets into a block of the given descriptor.
>From 990d0cf197e94d23fa8d9ef4be295bbb4dbacb84 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sun, 16 Feb 2025 11:41:51 +0100
Subject: [PATCH] [clang][bytecode] Add Descriptor::dumpFull
This is useful to print all (or most) of the valid offsets into a block
of the given descriptor.
---
clang/lib/AST/ByteCode/Descriptor.h | 1 +
clang/lib/AST/ByteCode/Disasm.cpp | 32 +++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h
index 96c82a18913e0..01fa4b198de67 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -274,6 +274,7 @@ struct Descriptor final {
void dump() const;
void dump(llvm::raw_ostream &OS) const;
+ void dumpFull(unsigned Offset = 0, unsigned Indent = 0) const;
};
/// Bitfield tracking the initialisation status of elements of primitive arrays.
diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp
index 92a169a37c365..85fc30482b003 100644
--- a/clang/lib/AST/ByteCode/Disasm.cpp
+++ b/clang/lib/AST/ByteCode/Disasm.cpp
@@ -251,6 +251,38 @@ LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream &OS) const {
OS << " dummy";
}
+/// Dump descriptor, including all valid offsets.
+LLVM_DUMP_METHOD void Descriptor::dumpFull(unsigned Offset,
+ unsigned Indent) const {
+ unsigned Spaces = Indent * 2;
+ llvm::raw_ostream &OS = llvm::errs();
+ OS.indent(Spaces);
+ dump(OS);
+ OS << '\n';
+ OS.indent(Spaces) << "Metadata: " << getMetadataSize() << " bytes\n";
+ OS.indent(Spaces) << "Size: " << getSize() << " bytes\n";
+ OS.indent(Spaces) << "AllocSize: " << getAllocSize() << " bytes\n";
+ Offset += getMetadataSize();
+ if (isCompositeArray()) {
+ OS.indent(Spaces) << "Elements: " << getNumElems() << '\n';
+ unsigned FO = Offset;
+ for (unsigned I = 0; I != getNumElems(); ++I) {
+ FO += sizeof(InlineDescriptor);
+ assert(ElemDesc->getMetadataSize() == 0);
+ OS.indent(Spaces) << "Element " << I << " offset: " << FO << '\n';
+ ElemDesc->dumpFull(FO, Indent + 1);
+
+ FO += ElemDesc->getAllocSize();
+ }
+ } else if (isRecord()) {
+ ElemRecord->dump(OS, Indent + 1, Offset);
+ } else if (isPrimitive()) {
+ } else {
+ }
+
+ OS << '\n';
+}
+
LLVM_DUMP_METHOD void InlineDescriptor::dump(llvm::raw_ostream &OS) const {
{
ColorScope SC(OS, true, {llvm::raw_ostream::BLUE, true});
More information about the cfe-commits
mailing list