[llvm-commits] [llvm] r137057 - /llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Benjamin Kramer
benny.kra at googlemail.com
Mon Aug 8 11:32:13 PDT 2011
Author: d0k
Date: Mon Aug 8 13:32:12 2011
New Revision: 137057
URL: http://llvm.org/viewvc/llvm-project?rev=137057&view=rev
Log:
llvm-objdump: Use help of CFG to print assembly when --cfg is passed.
This way we can avoid printing unreachable code (data).
Modified:
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=137057&r1=137056&r2=137057&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Mon Aug 8 13:32:12 2011
@@ -248,28 +248,57 @@
raw_ostream &DebugOut = nulls();
#endif
- for (Index = Start; Index < End; Index += Size) {
- MCInst Inst;
- if (DisAsm->getInstruction(Inst, Size, memoryObject, Index, DebugOut)) {
- uint64_t addr;
- if (error(i->getAddress(addr))) break;
- outs() << format("%8x:\t", addr + Index);
- DumpBytes(StringRef(Bytes.data() + Index, Size));
- IP->printInst(&Inst, outs());
- outs() << "\n";
- } else {
- errs() << ToolName << ": warning: invalid instruction encoding\n";
- if (Size == 0)
- Size = 1; // skip illegible bytes
+ if (!CFG) {
+ for (Index = Start; Index < End; Index += Size) {
+ MCInst Inst;
+ if (DisAsm->getInstruction(Inst, Size, memoryObject, Index,
+ DebugOut)) {
+ uint64_t addr;
+ if (error(i->getAddress(addr))) break;
+ outs() << format("%8x:\t", addr + Index);
+ DumpBytes(StringRef(Bytes.data() + Index, Size));
+ IP->printInst(&Inst, outs());
+ outs() << "\n";
+ } else {
+ errs() << ToolName << ": warning: invalid instruction encoding\n";
+ if (Size == 0)
+ Size = 1; // skip illegible bytes
+ }
}
- }
- if (CFG) {
+ } else {
+ // Create CFG and use it for disassembly.
MCFunction f =
MCFunction::createFunctionFromMC(Symbols[si].second, DisAsm.get(),
memoryObject, Start, End, InstrInfo,
DebugOut);
+ for (MCFunction::iterator fi = f.begin(), fe = f.end(); fi != fe; ++fi){
+ bool hasPreds = false;
+ // Only print blocks that have predecessors.
+ // FIXME: Slow.
+ for (MCFunction::iterator pi = f.begin(), pe = f.end(); pi != pe;
+ ++pi)
+ if (pi->second.contains(&fi->second)) {
+ hasPreds = true;
+ break;
+ }
+
+ if (!hasPreds && fi != f.begin())
+ continue;
+
+ for (unsigned ii = 0, ie = fi->second.getInsts().size(); ii != ie;
+ ++ii) {
+ uint64_t addr;
+ if (error(i->getAddress(addr))) break;
+ const MCDecodedInst &Inst = fi->second.getInsts()[ii];
+ outs() << format("%8x:\t", addr + Inst.Address);
+ DumpBytes(StringRef(Bytes.data() + Inst.Address, Inst.Size));
+ IP->printInst(&Inst.Inst, outs());
+ outs() << '\n';
+ }
+ }
+
// Start a new dot file.
std::string Error;
raw_fd_ostream Out((f.getName().str() + ".dot").c_str(), Error);
More information about the llvm-commits
mailing list