[clang] [clang][bytecode] Add Descriptor::dumpFull (PR #127386)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 16 02:47:33 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This is useful to print all (or most) of the valid offsets into a block of the given descriptor.
---
Full diff: https://github.com/llvm/llvm-project/pull/127386.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Descriptor.h (+1)
- (modified) clang/lib/AST/ByteCode/Disasm.cpp (+32)
``````````diff
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});
``````````
</details>
https://github.com/llvm/llvm-project/pull/127386
More information about the cfe-commits
mailing list