[llvm-commits] [llvm] r95227 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/MC/MCAsmStreamer.cpp tools/llvm-mc/llvm-mc.cpp
Daniel Dunbar
daniel at zuster.org
Wed Feb 3 10:18:30 PST 2010
Author: ddunbar
Date: Wed Feb 3 12:18:30 2010
New Revision: 95227
URL: http://llvm.org/viewvc/llvm-project?rev=95227&view=rev
Log:
llvm-mc: Add --show-inst option, for showing the MCInst inline with the assembly
output.
Modified:
llvm/trunk/include/llvm/MC/MCStreamer.h
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/tools/llvm-mc/llvm-mc.cpp
Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=95227&r1=95226&r2=95227&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Wed Feb 3 12:18:30 2010
@@ -269,11 +269,21 @@
/// createAsmStreamer - Create a machine code streamer which will print out
/// assembly for the native target, suitable for compiling with a native
/// assembler.
+ ///
+ /// \param InstPrint - If given, the instruction printer to use. If not given
+ /// the MCInst representation will be printed.
+ ///
+ /// \param CE - If given, a code emitter to use to show the instruction
+ /// encoding inline with the assembly.
+ ///
+ /// \param ShowInst - Whether to show the MCInst representation inline with
+ /// the assembly.
MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
const MCAsmInfo &MAI, bool isLittleEndian,
bool isVerboseAsm,
MCInstPrinter *InstPrint = 0,
- MCCodeEmitter *CE = 0);
+ MCCodeEmitter *CE = 0,
+ bool ShowInst = false);
// FIXME: These two may end up getting rolled into a single
// createObjectStreamer interface, which implements the assembler backend, and
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=95227&r1=95226&r2=95227&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Wed Feb 3 12:18:30 2010
@@ -29,20 +29,25 @@
class MCAsmStreamer : public MCStreamer {
formatted_raw_ostream &OS;
const MCAsmInfo &MAI;
- bool IsLittleEndian, IsVerboseAsm;
MCInstPrinter *InstPrinter;
MCCodeEmitter *Emitter;
SmallString<128> CommentToEmit;
raw_svector_ostream CommentStream;
+
+ unsigned IsLittleEndian : 1;
+ unsigned IsVerboseAsm : 1;
+ unsigned ShowInst : 1;
+
public:
MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os,
const MCAsmInfo &mai,
bool isLittleEndian, bool isVerboseAsm, MCInstPrinter *printer,
- MCCodeEmitter *emitter)
- : MCStreamer(Context), OS(os), MAI(mai), IsLittleEndian(isLittleEndian),
- IsVerboseAsm(isVerboseAsm), InstPrinter(printer), Emitter(emitter),
- CommentStream(CommentToEmit) {}
+ MCCodeEmitter *emitter, bool showInst)
+ : MCStreamer(Context), OS(os), MAI(mai), InstPrinter(printer),
+ Emitter(emitter), CommentStream(CommentToEmit),
+ IsLittleEndian(isLittleEndian), IsVerboseAsm(isVerboseAsm),
+ ShowInst(showInst) {}
~MCAsmStreamer() {}
bool isLittleEndian() const { return IsLittleEndian; }
@@ -527,13 +532,21 @@
void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
assert(CurSection && "Cannot emit contents before setting section!");
+ // Show the MCInst if enabled.
+ if (ShowInst) {
+ raw_ostream &OS = GetCommentOS();
+ OS << "inst: ";
+ Inst.print(OS, &MAI);
+ OS << "\n";
+ }
+
// Show the encoding in a comment if we have a code emitter.
if (Emitter) {
SmallString<256> Code;
raw_svector_ostream VecOS(Code);
Emitter->EncodeInstruction(Inst, VecOS);
VecOS.flush();
-
+
raw_ostream &OS = GetCommentOS();
OS << "encoding: [";
for (unsigned i = 0, e = Code.size(); i != e; ++i) {
@@ -543,29 +556,24 @@
}
OS << "]\n";
}
-
- // If we have an AsmPrinter, use that to print.
- if (InstPrinter) {
- InstPrinter->printInst(&Inst);
- EmitEOL();
- return;
- }
- // Otherwise fall back to a structural printing for now. Eventually we should
- // always have access to the target specific printer.
- Inst.print(OS, &MAI);
+ // If we have an AsmPrinter, use that to print, otherwise dump the MCInst.
+ if (InstPrinter)
+ InstPrinter->printInst(&Inst);
+ else
+ Inst.print(OS, &MAI);
EmitEOL();
}
void MCAsmStreamer::Finish() {
OS.flush();
}
-
+
MCStreamer *llvm::createAsmStreamer(MCContext &Context,
formatted_raw_ostream &OS,
const MCAsmInfo &MAI, bool isLittleEndian,
bool isVerboseAsm, MCInstPrinter *IP,
- MCCodeEmitter *CE) {
+ MCCodeEmitter *CE, bool ShowInst) {
return new MCAsmStreamer(Context, OS, MAI, isLittleEndian, isVerboseAsm,
- IP, CE);
+ IP, CE, ShowInst);
}
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=95227&r1=95226&r2=95227&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Wed Feb 3 12:18:30 2010
@@ -46,6 +46,9 @@
static cl::opt<bool>
ShowEncoding("show-encoding", cl::desc("Show instruction encodings"));
+static cl::opt<bool>
+ShowInst("show-inst", cl::desc("Show internal instruction representation"));
+
static cl::opt<unsigned>
OutputAsmVariant("output-asm-variant",
cl::desc("Syntax variant to use for output printing"));
@@ -266,7 +269,8 @@
CE.reset(TheTarget->createCodeEmitter(*TM));
Str.reset(createAsmStreamer(Ctx, *Out, *MAI,
TM->getTargetData()->isLittleEndian(),
- /*asmverbose*/true, IP.get(), CE.get()));
+ /*asmverbose*/true, IP.get(), CE.get(),
+ ShowInst));
} else {
assert(FileType == OFT_ObjectFile && "Invalid file type!");
CE.reset(TheTarget->createCodeEmitter(*TM));
More information about the llvm-commits
mailing list