diff options
author | Owen Anderson <resistor@mac.com> | 2011-09-15 23:38:46 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2011-09-15 23:38:46 +0000 |
commit | 98c5ddabca1debf935a07d14d0cbc9732374bdb8 (patch) | |
tree | 74e944d1e23e4ead852d53c54a5946ae6f1e56f8 | |
parent | 71280b55a3406c7dd4215449bf4a3ab216e78ffd (diff) | |
download | external_llvm-98c5ddabca1debf935a07d14d0cbc9732374bdb8.zip external_llvm-98c5ddabca1debf935a07d14d0cbc9732374bdb8.tar.gz external_llvm-98c5ddabca1debf935a07d14d0cbc9732374bdb8.tar.bz2 |
Don't attach annotations to MCInst's. Instead, have the disassembler return, and the printer accept, an annotation string which can be passed through if the client cares about annotations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139876 91177308-0d34-0410-b5e6-96231b3b80d8
31 files changed, 88 insertions, 114 deletions
diff --git a/include/llvm/MC/MCDisassembler.h b/include/llvm/MC/MCDisassembler.h index 404b8aa..f7a9f1c 100644 --- a/include/llvm/MC/MCDisassembler.h +++ b/include/llvm/MC/MCDisassembler.h @@ -70,6 +70,7 @@ public: /// @param address - The address, in the memory space of region, of the first /// byte of the instruction. /// @param vStream - The stream to print warnings and diagnostic messages on. + /// @param cStream - The stream to print comments and annotations on. /// @return - MCDisassembler::Success if the instruction is valid, /// MCDisassembler::SoftFail if the instruction was /// disassemblable but invalid, @@ -78,7 +79,8 @@ public: uint64_t& size, const MemoryObject ®ion, uint64_t address, - raw_ostream &vStream) const = 0; + raw_ostream &vStream, + raw_ostream &cStream) const = 0; /// getEDInfo - Returns the enhanced instruction information corresponding to /// the disassembler. diff --git a/include/llvm/MC/MCInst.h b/include/llvm/MC/MCInst.h index d443536..d384764 100644 --- a/include/llvm/MC/MCInst.h +++ b/include/llvm/MC/MCInst.h @@ -129,7 +129,6 @@ public: class MCInst { unsigned Opcode; SmallVector<MCOperand, 8> Operands; - SmallVector<std::string, 1> Annotations; public: MCInst() : Opcode(0) {} @@ -145,15 +144,7 @@ public: Operands.push_back(Op); } - void addAnnotation(const std::string &Annot) { - Annotations.push_back(Annot); - } - - void clear() { - Operands.clear(); - Annotations.clear(); - } - + void clear() { Operands.clear(); } size_t size() { return Operands.size(); } typedef SmallVector<MCOperand, 8>::iterator iterator; @@ -163,9 +154,6 @@ public: return Operands.insert(I, Op); } - size_t getNumAnnotations() const { return Annotations.size(); } - std::string getAnnotation(size_t i) const { return Annotations[i]; } - void print(raw_ostream &OS, const MCAsmInfo *MAI) const; void dump() const; diff --git a/include/llvm/MC/MCInstPrinter.h b/include/llvm/MC/MCInstPrinter.h index 4c12d10..01ad2d3 100644 --- a/include/llvm/MC/MCInstPrinter.h +++ b/include/llvm/MC/MCInstPrinter.h @@ -28,6 +28,9 @@ protected: /// The current set of available features. unsigned AvailableFeatures; + + /// Utility function for printing annotations. + void printAnnotation(raw_ostream &OS, StringRef Annot); public: MCInstPrinter(const MCAsmInfo &mai) : CommentStream(0), MAI(mai), AvailableFeatures(0) {} @@ -39,11 +42,8 @@ public: /// printInst - Print the specified MCInst to the specified raw_ostream. /// - virtual void printInst(const MCInst *MI, raw_ostream &OS) = 0; - - /// printAnnotations - Print the annotation comments attached to specified - /// MCInst to the specified raw_ostream. - void printAnnotations(const MCInst *MI, raw_ostream &OS); + virtual void printInst(const MCInst *MI, raw_ostream &OS, + StringRef Annot) = 0; /// getOpcodeName - Return the name of the specified opcode enum (e.g. /// "MOV32ri") or empty if we can't resolve it. diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index 6815434..3fcbb05 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -1244,7 +1244,7 @@ void MCAsmStreamer::EmitInstruction(const MCInst &Inst) { // If we have an AsmPrinter, use that to print, otherwise print the MCInst. if (InstPrinter) - InstPrinter->printInst(&Inst, OS); + InstPrinter->printInst(&Inst, OS, ""); else Inst.print(OS, &MAI); EmitEOL(); diff --git a/lib/MC/MCDisassembler/Disassembler.cpp b/lib/MC/MCDisassembler/Disassembler.cpp index 858a58c..14fab08 100644 --- a/lib/MC/MCDisassembler/Disassembler.cpp +++ b/lib/MC/MCDisassembler/Disassembler.cpp @@ -144,7 +144,7 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, MCInstPrinter *IP = DC->getIP(); MCDisassembler::DecodeStatus S; S = DisAsm->getInstruction(Inst, Size, MemoryObject, PC, - /*REMOVE*/ nulls()); + /*REMOVE*/ nulls(), DC->CommentStream); switch (S) { case MCDisassembler::Fail: case MCDisassembler::SoftFail: @@ -152,28 +152,16 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, return 0; case MCDisassembler::Success: { - SmallVector<char, 64> InsnStr; - raw_svector_ostream OS(InsnStr); - IP->printInst(&Inst, OS); - OS.flush(); - DC->CommentStream.flush(); - assert(DC->CommentsToEmit.back() == '\n'); - - DC->CommentsToEmit.push_back('\n'); StringRef Comments = DC->CommentsToEmit.str(); - do { - // Emit a line of comments. - size_t Position = Comments.find('\n'); - OS << ' ' << DC->getAsmInfo()->getCommentString() - << ' ' << Comments.substr(0, Position) << '\n'; - - Comments = Comments.substr(Position+1); - } while (!Comments.empty()); + SmallVector<char, 64> InsnStr; + raw_svector_ostream OS(InsnStr); + IP->printInst(&Inst, OS, Comments); + OS.flush(); - DC->CommentsToEmit.clear(); // Tell the comment stream that the vector changed underneath it. + DC->CommentsToEmit.clear(); DC->CommentStream.resync(); assert(OutStringSize != 0 && "Output buffer cannot be zero size"); diff --git a/lib/MC/MCDisassembler/EDDisassembler.cpp b/lib/MC/MCDisassembler/EDDisassembler.cpp index 70b6300..83362a2 100644 --- a/lib/MC/MCDisassembler/EDDisassembler.cpp +++ b/lib/MC/MCDisassembler/EDDisassembler.cpp @@ -246,7 +246,7 @@ EDInst *EDDisassembler::createInst(EDByteReaderCallback byteReader, MCDisassembler::DecodeStatus S; S = Disassembler->getInstruction(*inst, byteSize, memoryObject, address, - ErrorStream); + ErrorStream, nulls()); switch (S) { case MCDisassembler::Fail: case MCDisassembler::SoftFail: @@ -327,7 +327,7 @@ bool EDDisassembler::registerIsProgramCounter(unsigned registerID) { int EDDisassembler::printInst(std::string &str, MCInst &inst) { PrinterMutex.acquire(); - InstPrinter->printInst(&inst, *InstStream); + InstPrinter->printInst(&inst, *InstStream, ""); InstStream->flush(); str = *InstString; InstString->clear(); diff --git a/lib/MC/MCInst.cpp b/lib/MC/MCInst.cpp index ec97acc..4cb628b 100644 --- a/lib/MC/MCInst.cpp +++ b/lib/MC/MCInst.cpp @@ -41,16 +41,6 @@ void MCInst::print(raw_ostream &OS, const MCAsmInfo *MAI) const { OS << " "; getOperand(i).print(OS, MAI); } - - if (getNumAnnotations()) { - OS << " # Annots: "; - for (unsigned i = 0, e = getNumAnnotations(); i != e; ++i) { - OS << " \""; - OS << getAnnotation(i); - OS << '"'; - } - } - OS << ">"; } @@ -67,17 +57,6 @@ void MCInst::dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI, OS << Separator; getOperand(i).print(OS, MAI); } - - if (getNumAnnotations()) { - OS << " # Annots: "; - for (unsigned i = 0, e = getNumAnnotations(); i != e; ++i) { - OS << Separator; - OS << '"'; - OS << getAnnotation(i); - OS << '"'; - } - } - OS << ">"; } diff --git a/lib/MC/MCInstPrinter.cpp b/lib/MC/MCInstPrinter.cpp index f0fa2cd..e15e107 100644 --- a/lib/MC/MCInstPrinter.cpp +++ b/lib/MC/MCInstPrinter.cpp @@ -8,8 +8,6 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCInstPrinter.h" -#include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCInst.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -27,8 +25,6 @@ void MCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { assert(0 && "Target should implement this"); } -void MCInstPrinter::printAnnotations(const MCInst *MI, raw_ostream &OS) { - for (unsigned i = 0, e = MI->getNumAnnotations(); i != e; ++i) { - OS << MI->getAnnotation(i) << "\n"; - } +void MCInstPrinter::printAnnotation(raw_ostream &OS, StringRef Annot) { + if (!Annot.empty()) OS << Annot << "\n"; } diff --git a/lib/Target/ARM/Disassembler/ARMDisassembler.cpp b/lib/Target/ARM/Disassembler/ARMDisassembler.cpp index 6b86e41..685b921 100644 --- a/lib/Target/ARM/Disassembler/ARMDisassembler.cpp +++ b/lib/Target/ARM/Disassembler/ARMDisassembler.cpp @@ -47,7 +47,8 @@ public: uint64_t &size, const MemoryObject ®ion, uint64_t address, - raw_ostream &vStream) const; + raw_ostream &vStream, + raw_ostream &cStream) const; /// getEDInfo - See MCDisassembler. EDInstInfo *getEDInfo() const; @@ -71,7 +72,8 @@ public: uint64_t &size, const MemoryObject ®ion, uint64_t address, - raw_ostream &vStream) const; + raw_ostream &vStream, + raw_ostream &cStream) const; /// getEDInfo - See MCDisassembler. EDInstInfo *getEDInfo() const; @@ -328,7 +330,8 @@ EDInstInfo *ThumbDisassembler::getEDInfo() const { DecodeStatus ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size, const MemoryObject &Region, uint64_t Address, - raw_ostream &os) const { + raw_ostream &os, + raw_ostream &cs) const { uint8_t bytes[4]; assert(!(STI.getFeatureBits() & ARM::ModeThumb) && @@ -527,7 +530,8 @@ void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const { DecodeStatus ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size, const MemoryObject &Region, uint64_t Address, - raw_ostream &os) const { + raw_ostream &os, + raw_ostream &cs) const { uint8_t bytes[4]; assert((STI.getFeatureBits() & ARM::ModeThumb) && diff --git a/lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp b/lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp index 289d192..0a0f1d0 100644 --- a/lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp +++ b/lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp @@ -51,7 +51,8 @@ void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { OS << getRegisterName(RegNo); } -void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { +void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O, + StringRef Annot) { unsigned Opcode = MI->getOpcode(); // Check for MOVs and print canonical forms, instead. @@ -71,9 +72,7 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { O << ", " << getRegisterName(MO2.getReg()); assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0); - - if (CommentStream) printAnnotations(MI, *CommentStream); - + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } @@ -91,13 +90,12 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { << ", " << getRegisterName(MO1.getReg()); if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx) { - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm())); - - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } @@ -111,7 +109,7 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { O << ".w"; O << '\t'; printRegisterList(MI, 4, O); - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP && @@ -119,7 +117,7 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { O << '\t' << "push"; printPredicateOperand(MI, 4, O); O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}"; - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } @@ -132,7 +130,7 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { O << ".w"; O << '\t'; printRegisterList(MI, 4, O); - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP && @@ -140,7 +138,7 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { O << '\t' << "pop"; printPredicateOperand(MI, 5, O); O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}"; - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } @@ -152,7 +150,7 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { printPredicateOperand(MI, 2, O); O << '\t'; printRegisterList(MI, 4, O); - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } @@ -163,7 +161,7 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { printPredicateOperand(MI, 2, O); O << '\t'; printRegisterList(MI, 4, O); - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } @@ -182,7 +180,7 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { if (Writeback) O << "!"; O << ", "; printRegisterList(MI, 3, O); - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } @@ -191,12 +189,12 @@ void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { MI->getOperand(1).getReg() == ARM::R8) { O << "\tnop"; printPredicateOperand(MI, 2, O); - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } printInstruction(MI, O); - if (CommentStream) printAnnotations(MI, *CommentStream); + if (CommentStream) printAnnotation(*CommentStream, Annot); } void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, diff --git a/lib/Target/ARM/InstPrinter/ARMInstPrinter.h b/lib/Target/ARM/InstPrinter/ARMInstPrinter.h index fd4c9c4..a411e92 100644 --- a/lib/Target/ARM/InstPrinter/ARMInstPrinter.h +++ b/lib/Target/ARM/InstPrinter/ARMInstPrinter.h @@ -25,7 +25,7 @@ class ARMInstPrinter : public MCInstPrinter { public: ARMInstPrinter(const MCAsmInfo &MAI, const MCSubtargetInfo &STI); - virtual void printInst(const MCInst *MI, raw_ostream &O); + virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot); virtual StringRef getOpcodeName(unsigned Opcode) const; virtual void printRegName(raw_ostream &OS, unsigned RegNo) const; diff --git a/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp b/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp index 999080a..fd761f1 100644 --- a/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp +++ b/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp @@ -497,7 +497,8 @@ MCDisassembler::DecodeStatus MBlazeDisassembler::getInstruction(MCInst &instr, uint64_t &size, const MemoryObject ®ion, uint64_t address, - raw_ostream &vStream) const { + raw_ostream &vStream, + raw_ostream &cStream) const { // The machine instruction. uint32_t insn; uint64_t read; diff --git a/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.h b/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.h index 3d689db..0ac0d89 100644 --- a/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.h +++ b/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.h @@ -44,7 +44,8 @@ public: uint64_t &size, const MemoryObject ®ion, uint64_t address, - raw_ostream &vStream) const; + raw_ostream &vStream, + raw_ostream &cStream) const; /// getEDInfo - See MCDisassembler. EDInstInfo *getEDInfo() const; diff --git a/lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.cpp b/lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.cpp index a7fd287..7ece492 100644 --- a/lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.cpp +++ b/lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.cpp @@ -25,8 +25,10 @@ using namespace llvm; // Include the auto-generated portion of the assembly writer. #include "MBlazeGenAsmWriter.inc" -void MBlazeInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { +void MBlazeInstPrinter::printInst(const MCInst *MI, raw_ostream &O, + StringRef Annot) { printInstruction(MI, O); + if (CommentStream) printAnnotation(*CommentStream, Annot); } void MBlazeInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, diff --git a/lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.h b/lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.h index eacca41..570ab08 100644 --- a/lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.h +++ b/lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.h @@ -24,7 +24,7 @@ namespace llvm { MBlazeInstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) {} - virtual void printInst(const MCInst *MI, raw_ostream &O); + virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot); // Autogenerated by tblgen. void printInstruction(const MCInst *MI, raw_ostream &O); diff --git a/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.cpp b/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.cpp index e10d4fe..18151f4 100644 --- a/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.cpp +++ b/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.cpp @@ -25,8 +25,10 @@ using namespace llvm; // Include the auto-generated portion of the assembly writer. #include "MSP430GenAsmWriter.inc" -void MSP430InstPrinter::printInst(const MCInst *MI, raw_ostream &O) { +void MSP430InstPrinter::printInst(const MCInst *MI, raw_ostream &O, + StringRef Annot) { printInstruction(MI, O); + if (CommentStream) printAnnotation(*CommentStream, Annot); } void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo, diff --git a/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.h b/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.h index 82b342e..a1984a8 100644 --- a/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.h +++ b/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.h @@ -24,7 +24,7 @@ namespace llvm { MSP430InstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) {} - virtual void printInst(const MCInst *MI, raw_ostream &O); + virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot); // Autogenerated by tblgen. void printInstruction(const MCInst *MI, raw_ostream &O); diff --git a/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp b/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp index cb89929..7c7dca2 100644 --- a/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp +++ b/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp @@ -69,8 +69,10 @@ void MipsInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { OS << '$' << LowercaseString(getRegisterName(RegNo)); } -void MipsInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { +void MipsInstPrinter::printInst(const MCInst *MI, raw_ostream &O, + StringRef Annot) { printInstruction(MI, O); + if (CommentStream) printAnnotation(*CommentStream, Annot); } void MipsInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, diff --git a/lib/Target/Mips/InstPrinter/MipsInstPrinter.h b/lib/Target/Mips/InstPrinter/MipsInstPrinter.h index 76309a2..5c11165 100644 --- a/lib/Target/Mips/InstPrinter/MipsInstPrinter.h +++ b/lib/Target/Mips/InstPrinter/MipsInstPrinter.h @@ -86,7 +86,7 @@ public: virtual StringRef getOpcodeName(unsigned Opcode) const; virtual void printRegName(raw_ostream &OS, unsigned RegNo) const; - virtual void printInst(const MCInst *MI, raw_ostream &O); + virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot); private: void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); diff --git a/lib/Target/PTX/PTXMCAsmStreamer.cpp b/lib/Target/PTX/PTXMCAsmStreamer.cpp index 5003fb5..4925cbf 100644 --- a/lib/Target/PTX/PTXMCAsmStreamer.cpp +++ b/lib/Target/PTX/PTXMCAsmStreamer.cpp @@ -513,7 +513,7 @@ void PTXMCAsmStreamer::EmitInstruction(const MCInst &Inst) { // If we have an AsmPrinter, use that to print, otherwise print the MCInst. if (InstPrinter) - InstPrinter->printInst(&Inst, OS); + InstPrinter->printInst(&Inst, OS, ""); else Inst.print(OS, &MAI); EmitEOL(); diff --git a/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp b/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp index 8f34b19..c22b13a 100644 --- a/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp +++ b/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp @@ -31,7 +31,8 @@ void PPCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { OS << getRegisterName(RegNo); } -void PPCInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { +void PPCInstPrinter::printInst(const MCInst *MI, raw_ostream &O, + StringRef Annot) { // Check for slwi/srwi mnemonics. if (MI->getOpcode() == PPC::RLWINM) { unsigned char SH = MI->getOperand(2).getImm(); @@ -50,6 +51,8 @@ void PPCInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { O << ", "; printOperand(MI, 1, O); O << ", " << (unsigned int)SH; + + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } } @@ -60,6 +63,7 @@ void PPCInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { printOperand(MI, 0, O); O << ", "; printOperand(MI, 1, O); + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } @@ -73,11 +77,13 @@ void PPCInstPrinter::printInst(const MCInst *MI, raw_ostream &O) { O << ", "; printOperand(MI, 1, O); O << ", " << (unsigned int)SH; + if (CommentStream) printAnnotation(*CommentStream, Annot); return; } } printInstruction(MI, O); + if (CommentStream) printAnnotation(*CommentStream, Annot); } diff --git a/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h b/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h index d022a44..4ed4b76 100644 --- a/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h +++ b/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h @@ -32,7 +32,7 @@ public: } virtual void printRegName(raw_ostream &OS, unsigned RegNo) const; - virtual void printInst(const MCInst *MI, raw_ostream &O); + virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot); virtual StringRef getOpcodeName(unsigned Opcode) const; static const char *getInstructionName(unsigned Opcode); diff --git a/lib/Target/X86/Disassembler/X86Disassembler.cpp b/lib/Target/X86/Disassembler/X86Disassembler.cpp index e5774bf..884e690 100644 --- a/lib/Target/X86/Disassembler/X86Disassembler.cpp +++ b/lib/Target/X86/Disassembler/X86Disassembler.cpp @@ -114,7 +114,8 @@ X86GenericDisassembler::getInstruction(MCInst &instr, uint64_t &size, const MemoryObject ®ion, uint64_t address, - raw_ostream &vStream) const { + raw_ostream &vStream, + raw_ostream &cStream) const { InternalInstruction internalInstr; int ret = decodeInstruction(&internalInstr, diff --git a/lib/Target/X86/Disassembler/X86Disassembler.h b/lib/Target/X86/Disassembler/X86Disassembler.h index 419b870..6ac9a0f 100644 --- a/lib/Target/X86/Disassembler/X86Disassembler.h +++ b/lib/Target/X86/Disassembler/X86Disassembler.h @@ -117,7 +117,8 @@ public: uint64_t &size, const MemoryObject ®ion, uint64_t address, - raw_ostream &vStream) const; + raw_ostream &vStream, + raw_ostream &cStream) const; /// getEDInfo - See MCDisassembler. EDInstInfo *getEDInfo() const; diff --git a/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp b/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp index 76a1da4..1fefd57 100644 --- a/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp +++ b/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp @@ -39,14 +39,15 @@ void X86ATTInstPrinter::printRegName(raw_ostream &OS, OS << '%' << getRegisterName(RegNo); } -void X86ATTInstPrinter::printInst(const MCInst *MI, raw_ostream &OS) { +void X86ATTInstPrinter::printInst(const MCInst *MI, raw_ostream &OS, + StringRef Annot) { // Try to print any aliases first. if (!printAliasInstr(MI, OS)) printInstruction(MI, OS); // If verbose assembly is enabled, we can print some informative comments. if (CommentStream) { - printAnnotations(MI, *CommentStream); + printAnnotation(*CommentStream, Annot); EmitAnyX86InstComments(MI, *CommentStream, getRegisterName); } } diff --git a/lib/Target/X86/InstPrinter/X86ATTInstPrinter.h b/lib/Target/X86/InstPrinter/X86ATTInstPrinter.h index 5426e5c..0293869 100644 --- a/lib/Target/X86/InstPrinter/X86ATTInstPrinter.h +++ b/lib/Target/X86/InstPrinter/X86ATTInstPrinter.h @@ -25,7 +25,7 @@ public: X86ATTInstPrinter(const MCAsmInfo &MAI); virtual void printRegName(raw_ostream &OS, unsigned RegNo) const; - virtual void printInst(const MCInst *MI, raw_ostream &OS); + virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot); virtual StringRef getOpcodeName(unsigned Opcode) const; // Autogenerated by tblgen, returns true if we successfully printed an diff --git a/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp b/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp index 6cca1d1..8ff3ac8 100644 --- a/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp +++ b/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp @@ -32,12 +32,13 @@ void X86IntelInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { OS << getRegisterName(RegNo); } -void X86IntelInstPrinter::printInst(const MCInst *MI, raw_ostream &OS) { +void X86IntelInstPrinter::printInst(const MCInst *MI, raw_ostream &OS, + StringRef Annot) { printInstruction(MI, OS); // If verbose assembly is enabled, we can print some informative comments. if (CommentStream) { - printAnnotations(MI, *CommentStream); + printAnnotation(*CommentStream, Annot); EmitAnyX86InstComments(MI, *CommentStream, getRegisterName); } } diff --git a/lib/Target/X86/InstPrinter/X86IntelInstPrinter.h b/lib/Target/X86/InstPrinter/X86IntelInstPrinter.h index e84a194..6d5ec62 100644 --- a/lib/Target/X86/InstPrinter/X86IntelInstPrinter.h +++ b/lib/Target/X86/InstPrinter/X86IntelInstPrinter.h @@ -27,7 +27,7 @@ public: : MCInstPrinter(MAI) {} virtual void printRegName(raw_ostream &OS, unsigned RegNo) const; - virtual void printInst(const MCInst *MI, raw_ostream &OS); + virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot); virtual StringRef getOpcodeName(unsigned Opcode) const; // Autogenerated by tblgen. diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp index 60384f6..a9381b5 100644 --- a/tools/llvm-mc/Disassembler.cpp +++ b/tools/llvm-mc/Disassembler.cpp @@ -68,7 +68,7 @@ static bool PrintInsts(const MCDisassembler &DisAsm, MCDisassembler::DecodeStatus S; S = DisAsm.getInstruction(Inst, Size, memoryObject, Index, - /*REMOVE*/ nulls()); + /*REMOVE*/ nulls(), nulls()); switch (S) { case MCDisassembler::Fail: SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second), @@ -83,7 +83,7 @@ static bool PrintInsts(const MCDisassembler &DisAsm, // Fall through case MCDisassembler::Success: - Printer.printInst(&Inst, Out); + Printer.printInst(&Inst, Out, ""); Out << "\n"; break; } diff --git a/tools/llvm-objdump/MCFunction.cpp b/tools/llvm-objdump/MCFunction.cpp index 418e9d0..5f16496 100644 --- a/tools/llvm-objdump/MCFunction.cpp +++ b/tools/llvm-objdump/MCFunction.cpp @@ -40,7 +40,7 @@ MCFunction::createFunctionFromMC(StringRef Name, const MCDisassembler *DisAsm, for (uint64_t Index = Start; Index < End; Index += Size) { MCInst Inst; - if (DisAsm->getInstruction(Inst, Size, Region, Index, DebugOut)) { + if (DisAsm->getInstruction(Inst, Size, Region, Index, DebugOut, nulls())) { if (Ana->isBranch(Inst)) { uint64_t targ = Ana->evaluateBranch(Inst, Index, Size); // FIXME: Distinguish relocations from nop jumps. diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index c0022d4..4cfd4f4 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -262,13 +262,14 @@ static void DisassembleInput(const StringRef &Filename) { if (!CFG) { for (Index = Start; Index < End; Index += Size) { MCInst Inst; + if (DisAsm->getInstruction(Inst, Size, memoryObject, Index, - DebugOut)) { + DebugOut, nulls())) { 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()); + IP->printInst(&Inst, outs(), ""); outs() << "\n"; } else { errs() << ToolName << ": warning: invalid instruction encoding\n"; @@ -323,7 +324,7 @@ static void DisassembleInput(const StringRef &Filename) { // Simple loops. if (fi->second.contains(&fi->second)) outs() << '\t'; - IP->printInst(&Inst.Inst, outs()); + IP->printInst(&Inst.Inst, outs(), ""); outs() << '\n'; } } @@ -359,7 +360,7 @@ static void DisassembleInput(const StringRef &Filename) { // Escape special chars and print the instruction in mnemonic form. std::string Str; raw_string_ostream OS(Str); - IP->printInst(&i->second.getInsts()[ii].Inst, OS); + IP->printInst(&i->second.getInsts()[ii].Inst, OS, ""); Out << DOT::EscapeString(OS.str()) << '|'; } Out << "<o>\" shape=\"record\" ];\n"; |