[llvm-commits] [llvm] r95929 - in /llvm/trunk: include/llvm/MC/MCInstPrinter.h lib/MC/MCAsmStreamer.cpp lib/MC/MCInstPrinter.cpp lib/Target/X86/X86MCCodeEmitter.cpp

Chris Lattner sabre at nondot.org
Thu Feb 11 14:39:11 PST 2010


Author: lattner
Date: Thu Feb 11 16:39:10 2010
New Revision: 95929

URL: http://llvm.org/viewvc/llvm-project?rev=95929&view=rev
Log:
add a new MCInstPrinter::getOpcodeName interface, when it is 
implemented, llvm-mc --show-inst now uses it to print the
instruction opcode as well as the number.

Modified:
    llvm/trunk/include/llvm/MC/MCInstPrinter.h
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCInstPrinter.cpp
    llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp

Modified: llvm/trunk/include/llvm/MC/MCInstPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCInstPrinter.h?rev=95929&r1=95928&r2=95929&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCInstPrinter.h (original)
+++ llvm/trunk/include/llvm/MC/MCInstPrinter.h Thu Feb 11 16:39:10 2010
@@ -14,8 +14,8 @@
 class MCInst;
 class raw_ostream;
 class MCAsmInfo;
+class StringRef;
 
-  
 /// MCInstPrinter - This is an instance of a target assembly language printer
 /// that converts an MCInst to valid target assembly syntax.
 class MCInstPrinter {
@@ -40,6 +40,10 @@
   /// printInst - Print the specified MCInst to the current raw_ostream.
   ///
   virtual void printInst(const MCInst *MI) = 0;
+  
+  /// getOpcodeName - Return the name of the specified opcode enum (e.g.
+  /// "MOV32ri") or empty if we can't resolve it.
+  virtual StringRef getOpcodeName(unsigned Opcode) const;
 };
   
 } // namespace llvm

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=95929&r1=95928&r2=95929&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Thu Feb 11 16:39:10 2010
@@ -617,6 +617,12 @@
     raw_ostream &OS = GetCommentOS();
     OS << "<MCInst #" << Inst.getOpcode();
     
+    StringRef InstName;
+    if (InstPrinter)
+      InstName = InstPrinter->getOpcodeName(Inst.getOpcode());
+    if (!InstName.empty())
+      OS << ' ' << InstName;
+    
     for (unsigned i = 0, e = Inst.getNumOperands(); i != e; ++i) {
       OS << "\n  ";
       Inst.getOperand(i).print(OS, &MAI);

Modified: llvm/trunk/lib/MC/MCInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCInstPrinter.cpp?rev=95929&r1=95928&r2=95929&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCInstPrinter.cpp (original)
+++ llvm/trunk/lib/MC/MCInstPrinter.cpp Thu Feb 11 16:39:10 2010
@@ -8,7 +8,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/MC/MCInstPrinter.h"
+#include "llvm/ADT/StringRef.h"
 using namespace llvm;
 
 MCInstPrinter::~MCInstPrinter() {
 }
+
+/// getOpcodeName - Return the name of the specified opcode enum (e.g.
+/// "MOV32ri") or empty if we can't resolve it.
+StringRef MCInstPrinter::getOpcodeName(unsigned Opcode) const {
+  return "";
+}

Modified: llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp?rev=95929&r1=95928&r2=95929&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp Thu Feb 11 16:39:10 2010
@@ -282,11 +282,11 @@
 /// size, and 3) use of X86-64 extended registers.
 static unsigned DetermineREXPrefix(const MCInst &MI, unsigned TSFlags,
                                    const TargetInstrDesc &Desc) {
-  unsigned REX = 0;
+  // Pseudo instructions shouldn't get here.
+  assert((TSFlags & X86II::FormMask) != X86II::Pseudo &&
+         "Can't encode pseudo instrs");
   
-  // Pseudo instructions do not need REX prefix byte.
-  if ((TSFlags & X86II::FormMask) == X86II::Pseudo)
-    return 0;
+  unsigned REX = 0;
   if (TSFlags & X86II::REX_W)
     REX |= 1 << 3;
   





More information about the llvm-commits mailing list