@@ -1039,6 +1039,29 @@ static StringRef getSegmentName(const MachOObjectFile *MachO,
1039
1039
return " " ;
1040
1040
}
1041
1041
1042
+ static void emitPostInstructionInfo (formatted_raw_ostream &FOS,
1043
+ const MCAsmInfo &MAI,
1044
+ const MCSubtargetInfo &STI,
1045
+ StringRef Comments,
1046
+ LiveVariablePrinter &LVP) {
1047
+ do {
1048
+ if (!Comments.empty ()) {
1049
+ // Emit a line of comments.
1050
+ StringRef Comment;
1051
+ std::tie (Comment, Comments) = Comments.split (' \n ' );
1052
+ // MAI.getCommentColumn() assumes that instructions are printed at the
1053
+ // position of 8, while getInstStartColumn() returns the actual position.
1054
+ unsigned CommentColumn =
1055
+ MAI.getCommentColumn () - 8 + getInstStartColumn (STI);
1056
+ FOS.PadToColumn (CommentColumn);
1057
+ FOS << MAI.getCommentString () << ' ' << Comment;
1058
+ }
1059
+ LVP.printAfterInst (FOS);
1060
+ FOS << ' \n ' ;
1061
+ } while (!Comments.empty ());
1062
+ FOS.flush ();
1063
+ }
1064
+
1042
1065
static void disassembleObject (const Target *TheTarget, const ObjectFile *Obj,
1043
1066
MCContext &Ctx, MCDisassembler *PrimaryDisAsm,
1044
1067
MCDisassembler *SecondaryDisAsm,
@@ -1396,12 +1419,14 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
1396
1419
LVP.update ({Index, Section.getIndex ()},
1397
1420
{Index + Size , Section.getIndex ()}, Index + Size != End);
1398
1421
1422
+ IP->setCommentStream (CommentStream);
1423
+
1399
1424
PIP.printInst (
1400
1425
*IP, Disassembled ? &Inst : nullptr , Bytes.slice (Index, Size ),
1401
1426
{SectionAddr + Index + VMAAdjustment, Section.getIndex ()}, FOS,
1402
1427
" " , *STI, &SP, Obj->getFileName (), &Rels, LVP);
1403
- FOS << CommentStream. str ();
1404
- Comments. clear ( );
1428
+
1429
+ IP-> setCommentStream ( llvm::nulls () );
1405
1430
1406
1431
// If disassembly has failed, avoid analysing invalid/incomplete
1407
1432
// instruction information. Otherwise, try to resolve the target
@@ -1498,8 +1523,10 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
1498
1523
}
1499
1524
}
1500
1525
1501
- LVP.printAfterInst (FOS);
1502
- FOS << " \n " ;
1526
+ assert (Ctx.getAsmInfo ());
1527
+ emitPostInstructionInfo (FOS, *Ctx.getAsmInfo (), *STI,
1528
+ CommentStream.str (), LVP);
1529
+ Comments.clear ();
1503
1530
1504
1531
// Hexagon does this in pretty printer
1505
1532
if (Obj->getArch () != Triple::hexagon) {
0 commit comments