[codeview] Improve readability of type record assembly

Adds the method MCStreamer::EmitBinaryData, which is usually an alias
for EmitBytes. In the MCAsmStreamer case, it is overridden to emit hex
dump output like this:
        .byte   0x0e, 0x00, 0x08, 0x10
        .byte   0x03, 0x00, 0x00, 0x00
        .byte   0x00, 0x00, 0x00, 0x00
        .byte   0x00, 0x10, 0x00, 0x00

Also, when verbose asm comments are enabled, this patch prints the dump
output for each comment before its record, like this:
        # ArgList (0x1000) {
        #   TypeLeafKind: LF_ARGLIST (0x1201)
        #   NumArgs: 0
        #   Arguments [
        #   ]
        # }
        .byte   0x06, 0x00, 0x01, 0x12
        .byte   0x00, 0x00, 0x00, 0x00

This should make debugging easier and testing more convenient.

Reviewers: aaboud

Subscribers: majnemer, zturner, amccarth, aaboud, llvm-commits

Differential Revision: http://reviews.llvm.org/D20711

llvm-svn: 271313
This commit is contained in:
Reid Kleckner
2016-05-31 18:45:36 +00:00
parent 7aa4d977ea
commit fbdbe9e22b
11 changed files with 132 additions and 62 deletions

View File

@@ -162,6 +162,8 @@ public:
void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment = 0) override;
void EmitBinaryData(StringRef Data) override;
void EmitBytes(StringRef Data) override;
void EmitValueImpl(const MCExpr *Value, unsigned Size,
@@ -709,6 +711,20 @@ void MCAsmStreamer::EmitBytes(StringRef Data) {
EmitEOL();
}
void MCAsmStreamer::EmitBinaryData(StringRef Data) {
// This is binary data. Print it in a grid of hex bytes for readability.
const size_t Cols = 4;
for (size_t I = 0, EI = alignTo(Data.size(), Cols); I < EI; I += Cols) {
size_t J = I, EJ = std::min(I + Cols, Data.size());
assert(EJ > 0);
OS << MAI->getData8bitsDirective();
for (; J < EJ - 1; ++J)
OS << format("0x%02x", uint8_t(Data[J])) << ", ";
OS << format("0x%02x", uint8_t(Data[J]));
EmitEOL();
}
}
void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
EmitValue(MCConstantExpr::create(Value, getContext()), Size);
}