[llvm-commits] [llvm] r95728 - in /llvm/trunk: include/llvm/MC/MCFixup.h include/llvm/MC/MCInstPrinter.h lib/MC/MCAsmStreamer.cpp lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp
Chris Lattner
sabre at nondot.org
Tue Feb 9 16:10:18 PST 2010
Author: lattner
Date: Tue Feb 9 18:10:18 2010
New Revision: 95728
URL: http://llvm.org/viewvc/llvm-project?rev=95728&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/MC/MCFixup.h
llvm/trunk/include/llvm/MC/MCInstPrinter.h
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp
Modified: llvm/trunk/include/llvm/MC/MCFixup.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCFixup.h?rev=95728&r1=95727&r2=95728&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCFixup.h (original)
+++ llvm/trunk/include/llvm/MC/MCFixup.h Tue Feb 9 18:10:18 2010
@@ -16,7 +16,7 @@
// 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).
Modified: llvm/trunk/include/llvm/MC/MCInstPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCInstPrinter.h?rev=95728&r1=95727&r2=95728&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCInstPrinter.h (original)
+++ llvm/trunk/include/llvm/MC/MCInstPrinter.h Tue Feb 9 18:10:18 2010
@@ -20,12 +20,22 @@
/// 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.
///
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=95728&r1=95727&r2=95728&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Tue Feb 9 18:10:18 2010
@@ -48,7 +48,10 @@
: 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; }
Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp?rev=95728&r1=95727&r2=95728&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp Tue Feb 9 18:10:18 2010
@@ -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 @@
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();
More information about the llvm-commits
mailing list