diff options
author | Chris Lattner <sabre@nondot.org> | 2010-02-10 00:10:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-02-10 00:10:18 +0000 |
commit | 5d672cfab096390690a1a5f33b0057c4cf252c55 (patch) | |
tree | 8b302847f85f74e88fce57840961a054fae60ae3 | |
parent | 51898d7a8948f7d9b1b498cf22609241945e994e (diff) | |
download | external_llvm-5d672cfab096390690a1a5f33b0057c4cf252c55.zip external_llvm-5d672cfab096390690a1a5f33b0057c4cf252c55.tar.gz external_llvm-5d672cfab096390690a1a5f33b0057c4cf252c55.tar.bz2 |
Add ability for MCInstPrinters to add comments for instructions.
Enhance the x86 backend to show the hex values of immediates in
comments when they are large. For example:
movl $1072693248, 4(%esp) ## imm = 0x3FF00000
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95728 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/MC/MCFixup.h | 2 | ||||
-rw-r--r-- | include/llvm/MC/MCInstPrinter.h | 12 | ||||
-rw-r--r-- | lib/MC/MCAsmStreamer.cpp | 5 | ||||
-rw-r--r-- | lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp | 5 |
4 files changed, 21 insertions, 3 deletions
diff --git a/include/llvm/MC/MCFixup.h b/include/llvm/MC/MCFixup.h index da8e92e..3c2edfb 100644 --- a/include/llvm/MC/MCFixup.h +++ b/include/llvm/MC/MCFixup.h @@ -16,7 +16,7 @@ namespace llvm { // Private constants, do not use. // -// This is currently layed out so that the MCFixup fields can be efficiently +// This is currently laid out so that the MCFixup fields can be efficiently // accessed, while keeping the offset field large enought that the assembler // backend can reasonably use the MCFixup representation for an entire fragment // (splitting any overly large fragments). diff --git a/include/llvm/MC/MCInstPrinter.h b/include/llvm/MC/MCInstPrinter.h index d62a9da..8829518 100644 --- a/include/llvm/MC/MCInstPrinter.h +++ b/include/llvm/MC/MCInstPrinter.h @@ -20,12 +20,22 @@ class MCAsmInfo; /// that converts an MCInst to valid target assembly syntax. class MCInstPrinter { protected: + /// O - The main stream to emit instruction text to. raw_ostream &O; + + /// CommentStream - a stream that comments can be emitted to if desired. + /// Each comment must end with a newline. This will be null if verbose + /// assembly emission is disable. + raw_ostream *CommentStream; const MCAsmInfo &MAI; public: - MCInstPrinter(raw_ostream &o, const MCAsmInfo &mai) : O(o), MAI(mai) {} + MCInstPrinter(raw_ostream &o, const MCAsmInfo &mai) + : O(o), CommentStream(0), MAI(mai) {} virtual ~MCInstPrinter(); + + /// setCommentStream - Specify a stream to emit comments to. + void setCommentStream(raw_ostream &OS) { CommentStream = &OS; } /// printInst - Print the specified MCInst to the current raw_ostream. /// diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index 0abd485..b63427a 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -48,7 +48,10 @@ public: : MCStreamer(Context), OS(os), MAI(mai), InstPrinter(printer), Emitter(emitter), CommentStream(CommentToEmit), IsLittleEndian(isLittleEndian), IsVerboseAsm(isVerboseAsm), - ShowFixups(showFixups), ShowInst(showInst) {} + ShowFixups(showFixups), ShowInst(showInst) { + if (InstPrinter && IsVerboseAsm) + InstPrinter->setCommentStream(CommentStream); + } ~MCAsmStreamer() {} bool isLittleEndian() const { return IsLittleEndian; } diff --git a/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp index 81b0e8f..38ccbf9 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp @@ -18,6 +18,7 @@ #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCExpr.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/Format.h" #include "llvm/Support/FormattedStream.h" #include "X86GenInstrNames.inc" using namespace llvm; @@ -65,6 +66,10 @@ void X86ATTInstPrinter::printOperand(const MCInst *MI, unsigned OpNo) { O << '%' << getRegisterName(Op.getReg()); } else if (Op.isImm()) { O << '$' << Op.getImm(); + + if (CommentStream && (Op.getImm() > 255 || Op.getImm() < -256)) + *CommentStream << format("imm = 0x%X\n", Op.getImm()); + } else { assert(Op.isExpr() && "unknown operand kind in printOperand"); O << '$' << *Op.getExpr(); |