[PATCH] Add method to MCInstPrinter for printing with disassembly context
colinl at codeaurora.org
colinl at codeaurora.org
Thu Mar 19 13:57:45 PDT 2015
This is a sketch of looping we use to generate bundles:
for(auto i(MI.begin()), j (MI.end()); i != j; ++i) {
OS << format("%8" PRIx64 ":", Address);
Address += HEXAGON_INSTR_SIZE;
if (ShowRawInsn) {
OS << "\t";
DumpBytes(StringRef(
reinterpret_cast<const char *>(Bytes.data()), HEXAGON_INSTR_SIZE),
HEXAGON_INSTR_SIZE, true, true);
Bytes = Bytes.slice(HEXAGON_INSTR_SIZE);
}
if(i == MI.begin())
OS << " { ";
else
OS << " ";
MCInst const * Inst = i->getInst();
PrintOneInst(*Inst, OS);
if(i + 1 == MI.end())
OS << " }";
else
OS << '\n';
}
if(HexagonMCInstrInfo::IsEnd0(MI))
OS << ":endloop0";
if(HexagonMCInstrInfo::IsEnd1(MI))
OS << ":endloop1";
And it produces output like this:
0: a3 43 02 8e 8e0243a3 { r3 += lsr(r2, #3)
4: 00 40 20 5c 5c204000 if (!p0) jump 0x0
8: 24 40 c1 41 41c14024 if (p0) r5:4 = memd(r1 + #8)
c: 08 e4 c0 ab abc0e408 if (p0) memd(r0++#8) = r5:4 }
REPOSITORY
rL LLVM
================
Comment at: lib/MC/MCInstPrinter.cpp:20
@@ -18,1 +19,3 @@
+void llvm::DumpBytes(ArrayRef<uint8_t> bytes, raw_ostream &OS) {
+ static const char hex_rep[] = "0123456789abcdef";
----------------
rafael wrote:
> This can now be static, no?
It's still used inside MachODump in a couple places.
================
Comment at: lib/MC/MCInstPrinter.cpp:26
@@ +25,3 @@
+ output.push_back(hex_rep[(i & 0xF0) >> 4]);
+ output.push_back(hex_rep[i & 0xF]);
+ output.push_back(' ');
----------------
rafael wrote:
> Why not send the chars to OS directly?
Good point, I'll make that change.
http://reviews.llvm.org/D8427
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the llvm-commits
mailing list