[llvm-commits] [llvm] r73743 - in /llvm/trunk: include/llvm/MC/ include/llvm/MC/MCInst.h lib/Target/X86/AsmPrinter/CMakeLists.txt lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h

Chris Lattner sabre at nondot.org
Thu Jun 18 17:47:42 PDT 2009


Author: lattner
Date: Thu Jun 18 19:47:33 2009
New Revision: 73743

URL: http://llvm.org/viewvc/llvm-project?rev=73743&view=rev
Log:
Add some scaffolding for a new experimental asmprinter
implementation.  The idea is that we want asmprinting to
work by converting MachineInstrs into a new MCInst class,
then the per-instruction asmprinter works on MCInst.  MCInst
and the new asmprinters will not depend on most of the 
llvm code generators.  This allows building diassemblers
that don't link in the whole llvm code generator.  This is
step #1 of many.

Added:
    llvm/trunk/include/llvm/MC/
    llvm/trunk/include/llvm/MC/MCInst.h
Modified:
    llvm/trunk/lib/Target/X86/AsmPrinter/CMakeLists.txt
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h

Added: llvm/trunk/include/llvm/MC/MCInst.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCInst.h?rev=73743&view=auto

==============================================================================
--- llvm/trunk/include/llvm/MC/MCInst.h (added)
+++ llvm/trunk/include/llvm/MC/MCInst.h Thu Jun 18 19:47:33 2009
@@ -0,0 +1,93 @@
+//===-- llvm/MC/MCInst.h - MCInst class -------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the declaration of the MCInst and MCOperand classes, which
+// is the basic representation used to represent low-level machine code
+// instructions.
+//
+//===----------------------------------------------------------------------===//
+
+
+#ifndef LLVM_MC_MCINST_H
+#define LLVM_MC_MCINST_H
+
+#include "llvm/ADT/SmallVector.h"
+
+namespace llvm {
+
+/// MCOperand - Instances of this class represent operands of the MCInst class.
+/// This is a simple discriminated union.
+class MCOperand {
+  enum MachineOperandType {
+    kInvalid,                 ///< Uninitialized.
+    kRegister,                ///< Register operand.
+    kImmediate                ///< Immediate operand.
+  };
+  unsigned char Kind;
+  
+  union {
+    unsigned RegVal;
+    uint64_t ImmVal;
+  };
+public:
+  
+  MCOperand() : Kind(kInvalid) {}
+  MCOperand(const MCOperand &RHS) { *this = RHS; }
+
+  bool isReg() const { return Kind == kRegister; }
+  bool isImm() const { return Kind == kImmediate; }
+  
+  /// getReg - Returns the register number.
+  unsigned getReg() const {
+    assert(isReg() && "This is not a register operand!");
+    return RegVal;
+  }
+
+  /// setReg - Set the register number.
+  void setReg(unsigned Reg) {
+    assert(isReg() && "This is not a register operand!");
+    RegVal = Reg;
+  }
+  
+  uint64_t getImm() const {
+    assert(isImm() && "This is not an immediate");
+    return ImmVal;
+  }
+  void setImm(uint64_t Val) {
+    assert(isImm() && "This is not an immediate");
+    ImmVal = Val;
+  }
+  
+  void MakeReg(unsigned Reg) {
+    Kind = kRegister;
+    RegVal = Reg;
+  }
+  void MakeImm(uint64_t Val) {
+    Kind = kImmediate;
+    ImmVal = Val;
+  }
+};
+
+  
+/// MCInst - Instances of this class represent a single low-level machine
+/// instruction. 
+class MCInst {
+  unsigned Opcode;
+  SmallVector<MCOperand, 8> Operands;
+public:
+  MCInst() : Opcode(~0U) {}
+  
+  
+  
+};
+
+
+} // end namespace llvm
+
+#endif

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/CMakeLists.txt?rev=73743&r1=73742&r2=73743&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/CMakeLists.txt (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/CMakeLists.txt Thu Jun 18 19:47:33 2009
@@ -2,6 +2,7 @@
 
 add_partially_linked_object(LLVMX86AsmPrinter
   X86ATTAsmPrinter.cpp
+  X86ATTInstPrinter.cpp
   X86AsmPrinter.cpp
   X86IntelAsmPrinter.cpp
   )

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=73743&r1=73742&r2=73743&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Thu Jun 18 19:47:33 2009
@@ -26,8 +26,10 @@
 #include "llvm/Type.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/MC/MCInst.h"
 #include "llvm/CodeGen/DwarfWriter.h"
 #include "llvm/CodeGen/MachineJumpTableInfo.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetAsmInfo.h"
@@ -36,6 +38,9 @@
 
 STATISTIC(EmittedInsts, "Number of machine instrs printed");
 
+static cl::opt<bool> NewAsmPrinter("experimental-asm-printer",
+                                   cl::Hidden);
+
 static std::string getPICLabelString(unsigned FnNum,
                                      const TargetAsmInfo *TAI,
                                      const X86Subtarget* Subtarget) {
@@ -763,6 +768,12 @@
 void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
   ++EmittedInsts;
 
+  if (NewAsmPrinter) {
+    MCInst TmpInst;
+    // FIXME: Convert TmpInst.
+    printInstruction(TmpInst);
+  }
+  
   // Call the autogenerated instruction printer routines.
   printInstruction(MI);
 }

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h?rev=73743&r1=73742&r2=73743&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h Thu Jun 18 19:47:33 2009
@@ -27,6 +27,7 @@
 namespace llvm {
 
 class MachineJumpTableInfo;
+class MCInst;
 
 class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
   DwarfWriter *DW;
@@ -63,6 +64,9 @@
   /// machine instruction was sufficiently described to print it, otherwise it
   /// returns false.
   bool printInstruction(const MachineInstr *MI);
+  
+  bool printInstruction(const MCInst &TmpInst);
+
 
   // These methods are used by the tablegen'erated instruction printer.
   void printOperand(const MachineInstr *MI, unsigned OpNo,





More information about the llvm-commits mailing list