Skip to content

Commit d64cf19

Browse files
authored
[clang][bytecode] Add Descriptor::dumpFull (llvm#127386)
This is useful to print all (or most) of the valid offsets into a block of the given descriptor.
1 parent a422bc7 commit d64cf19

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

clang/lib/AST/ByteCode/Descriptor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ struct Descriptor final {
274274

275275
void dump() const;
276276
void dump(llvm::raw_ostream &OS) const;
277+
void dumpFull(unsigned Offset = 0, unsigned Indent = 0) const;
277278
};
278279

279280
/// Bitfield tracking the initialisation status of elements of primitive arrays.

clang/lib/AST/ByteCode/Disasm.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,38 @@ LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream &OS) const {
251251
OS << " dummy";
252252
}
253253

254+
/// Dump descriptor, including all valid offsets.
255+
LLVM_DUMP_METHOD void Descriptor::dumpFull(unsigned Offset,
256+
unsigned Indent) const {
257+
unsigned Spaces = Indent * 2;
258+
llvm::raw_ostream &OS = llvm::errs();
259+
OS.indent(Spaces);
260+
dump(OS);
261+
OS << '\n';
262+
OS.indent(Spaces) << "Metadata: " << getMetadataSize() << " bytes\n";
263+
OS.indent(Spaces) << "Size: " << getSize() << " bytes\n";
264+
OS.indent(Spaces) << "AllocSize: " << getAllocSize() << " bytes\n";
265+
Offset += getMetadataSize();
266+
if (isCompositeArray()) {
267+
OS.indent(Spaces) << "Elements: " << getNumElems() << '\n';
268+
unsigned FO = Offset;
269+
for (unsigned I = 0; I != getNumElems(); ++I) {
270+
FO += sizeof(InlineDescriptor);
271+
assert(ElemDesc->getMetadataSize() == 0);
272+
OS.indent(Spaces) << "Element " << I << " offset: " << FO << '\n';
273+
ElemDesc->dumpFull(FO, Indent + 1);
274+
275+
FO += ElemDesc->getAllocSize();
276+
}
277+
} else if (isRecord()) {
278+
ElemRecord->dump(OS, Indent + 1, Offset);
279+
} else if (isPrimitive()) {
280+
} else {
281+
}
282+
283+
OS << '\n';
284+
}
285+
254286
LLVM_DUMP_METHOD void InlineDescriptor::dump(llvm::raw_ostream &OS) const {
255287
{
256288
ColorScope SC(OS, true, {llvm::raw_ostream::BLUE, true});

0 commit comments

Comments
 (0)