aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin@accesssoftek.com>2021-06-28 14:24:39 +0700
committerIgor Kudrin <ikudrin@accesssoftek.com>2021-06-28 14:25:22 +0700
commitd25e572421a66270c0ee8d51c96256f2958a6f1d (patch)
tree4e69f4fcbb339f89016010da9c69a6106a824505 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parente7fffa6f032b58d2cf04b05c3992c5195c2dfd56 (diff)
downloadllvm-d25e572421a66270c0ee8d51c96256f2958a6f1d.zip
llvm-d25e572421a66270c0ee8d51c96256f2958a6f1d.tar.gz
llvm-d25e572421a66270c0ee8d51c96256f2958a6f1d.tar.bz2
[llvm-objdump] Print memory operand addresses as regular comments
The patch reuses the common code to print memory operand addresses as instruction comments. This helps to align the comments and enables using target-specific comment markers when `evaluateMemoryOperandAddress()` is implemented for them. Differential Revision: https://reviews.llvm.org/D104861
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index c75d0e4..39ce32d 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1433,6 +1433,8 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
// address (jump target or memory operand address) and print it on the
// right of the instruction.
if (Disassembled && MIA) {
+ // Branch targets are printed just after the instructions.
+ llvm::raw_ostream *TargetOS = &FOS;
uint64_t Target;
bool PrintTarget =
MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target);
@@ -1443,8 +1445,11 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
Target = *MaybeTarget;
PrintTarget = true;
// Do not print real address when symbolizing.
- if (!SymbolizeOperands)
- FOS << " # 0x" << Twine::utohexstr(Target);
+ if (!SymbolizeOperands) {
+ // Memory operand addresses are printed as comments.
+ TargetOS = &CommentStream;
+ *TargetOS << "0x" << Twine::utohexstr(Target);
+ }
}
if (PrintTarget) {
// In a relocatable object, the target's section must reside in
@@ -1503,22 +1508,26 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
if (Demangle)
TargetName = demangle(TargetName);
- FOS << " <";
+ *TargetOS << " <";
if (!Disp) {
// Always Print the binary symbol precisely corresponding to
// the target address.
- FOS << TargetName;
+ *TargetOS << TargetName;
} else if (!LabelAvailable) {
// Always Print the binary symbol plus an offset if there's no
// local label corresponding to the target address.
- FOS << TargetName << "+0x" << Twine::utohexstr(Disp);
+ *TargetOS << TargetName << "+0x" << Twine::utohexstr(Disp);
} else {
- FOS << AllLabels[Target];
+ *TargetOS << AllLabels[Target];
}
- FOS << ">";
+ *TargetOS << ">";
} else if (LabelAvailable) {
- FOS << " <" << AllLabels[Target] << ">";
+ *TargetOS << " <" << AllLabels[Target] << ">";
}
+ // By convention, each record in the comment stream should be
+ // terminated.
+ if (TargetOS == &CommentStream)
+ *TargetOS << "\n";
}
}
}