split DEBUG_VALUE printing stuff out to its own method.
authorChris Lattner <sabre@nondot.org>
Sun, 4 Apr 2010 05:38:19 +0000 (05:38 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 4 Apr 2010 05:38:19 +0000 (05:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100315 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/AsmPrinter/X86AsmPrinter.h
lib/Target/X86/AsmPrinter/X86MCInstLower.cpp

index 8e35b907f5ed138e48903d3f17f7d47769c42407..b98ad44069d98d139fa42116291d1fa755d73d9b 100644 (file)
@@ -87,6 +87,8 @@ class VISIBILITY_HIDDEN X86AsmPrinter : public AsmPrinter {
   void PrintPICBaseSymbol(raw_ostream &O) const;
   
   bool runOnMachineFunction(MachineFunction &F);
+  
+  void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
 };
 
 } // end namespace llvm
index 4732b2f4aa9acfadee1d7f5ce0e7840f416f0ad3..004ff1ef83d4dec21bccbb00621449dbd005fa36 100644 (file)
@@ -326,70 +326,73 @@ void X86MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
   }
 }
 
+void X86AsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
+                                           raw_ostream &O) {
+  // FIXME: if this is implemented for another target before it goes
+  // away completely, the common part should be moved into AsmPrinter.
+  O << '\t' << MAI->getCommentString() << "DEBUG_VALUE: ";
+  unsigned NOps = MI->getNumOperands();
+  // cast away const; DIetc do not take const operands for some reason.
+  DIVariable V((MDNode*)(MI->getOperand(NOps-1).getMetadata()));
+  O << V.getName();
+  O << " <- ";
+  if (NOps==3) {
+    // Register or immediate value. Register 0 means undef.
+    assert(MI->getOperand(0).isReg() ||
+           MI->getOperand(0).isImm() ||
+           MI->getOperand(0).isFPImm());
+    if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg() == 0) {
+      // Suppress offset in this case, it is not meaningful.
+      O << "undef";
+      OutStreamer.AddBlankLine();
+      return;
+    }
+    
+    if (MI->getOperand(0).isFPImm()) {
+      // This is more naturally done in printOperand, but since the only use
+      // of such an operand is in this comment and that is temporary (and it's
+      // ugly), we prefer to keep this localized.
+      // The include of Type.h may be removable when this code is.
+      if (MI->getOperand(0).getFPImm()->getType()->isFloatTy() ||
+          MI->getOperand(0).getFPImm()->getType()->isDoubleTy())
+        MI->getOperand(0).print(O, &TM);
+      else {
+        // There is no good way to print long double.  Convert a copy to
+        // double.  Ah well, it's only a comment.
+        bool ignored;
+        APFloat APF = APFloat(MI->getOperand(0).getFPImm()->getValueAPF());
+        APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
+                    &ignored);
+        O << "(long double) " << APF.convertToDouble();
+      }
+    } else
+      printOperand(MI, 0, O);
+  } else {
+    if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg() == 0) {
+      // Suppress offset in this case, it is not meaningful.
+      O << "undef";
+      OutStreamer.AddBlankLine();
+      return;
+    }
+    // Frame address.  Currently handles register +- offset only.
+    assert(MI->getOperand(0).isReg() && MI->getOperand(3).isImm());
+    O << '['; printOperand(MI, 0, O); O << '+'; printOperand(MI, 3, O);
+    O << ']';
+  }
+  O << "+";
+  printOperand(MI, NOps-2, O);
+  OutStreamer.AddBlankLine();
+}
 
 
 void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) {
   X86MCInstLower MCInstLowering(OutContext, Mang, *this);
   switch (MI->getOpcode()) {
-  case TargetOpcode::DBG_VALUE: {
-    // FIXME: if this is implemented for another target before it goes
-    // away completely, the common part should be moved into AsmPrinter.
-    if (!VerboseAsm)
-      return;
-    O << '\t' << MAI->getCommentString() << "DEBUG_VALUE: ";
-    unsigned NOps = MI->getNumOperands();
-    // cast away const; DIetc do not take const operands for some reason.
-    DIVariable V((MDNode*)(MI->getOperand(NOps-1).getMetadata()));
-    O << V.getName();
-    O << " <- ";
-    if (NOps==3) {
-      // Register or immediate value. Register 0 means undef.
-      assert(MI->getOperand(0).isReg() ||
-             MI->getOperand(0).isImm() ||
-             MI->getOperand(0).isFPImm());
-      if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg() == 0) {
-        // Suppress offset in this case, it is not meaningful.
-        O << "undef";
-        OutStreamer.AddBlankLine();
-        return;
-      }
-      
-      if (MI->getOperand(0).isFPImm()) {
-        // This is more naturally done in printOperand, but since the only use
-        // of such an operand is in this comment and that is temporary (and it's
-        // ugly), we prefer to keep this localized.
-        // The include of Type.h may be removable when this code is.
-        if (MI->getOperand(0).getFPImm()->getType()->isFloatTy() ||
-            MI->getOperand(0).getFPImm()->getType()->isDoubleTy())
-          MI->getOperand(0).print(O, &TM);
-        else {
-          // There is no good way to print long double.  Convert a copy to
-          // double.  Ah well, it's only a comment.
-          bool ignored;
-          APFloat APF = APFloat(MI->getOperand(0).getFPImm()->getValueAPF());
-          APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
-                      &ignored);
-          O << "(long double) " << APF.convertToDouble();
-        }
-      } else
-        printOperand(MI, 0, O);
-    } else {
-      if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg() == 0) {
-        // Suppress offset in this case, it is not meaningful.
-        O << "undef";
-        OutStreamer.AddBlankLine();
-        return;
-      }
-      // Frame address.  Currently handles register +- offset only.
-      assert(MI->getOperand(0).isReg() && MI->getOperand(3).isImm());
-      O << '['; printOperand(MI, 0, O); O << '+'; printOperand(MI, 3, O);
-      O << ']';
-    }
-    O << "+";
-    printOperand(MI, NOps-2, O);
-    OutStreamer.AddBlankLine();
+  case TargetOpcode::DBG_VALUE:
+    if (VerboseAsm)
+      PrintDebugValueComment(MI, O);
     return;
-  }
+      
   case X86::MOVPC32r: {
     MCInst TmpInst;
     // This is a pseudo op for a two instruction sequence with a label, which