[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Mar 3 13:12:20 PST 2005



Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.226 -> 1.227
---
Log message:

Print -X like this:

double test(double l1_X) {
  return (-l1_X);
}

instead of like this:

double test(double l1_X) {
  return (-0x0p+0 - l1_X);
}



---
Diffs of the changes:  (+30 -22)

 Writer.cpp |   52 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 30 insertions(+), 22 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.226 llvm/lib/Target/CBackend/Writer.cpp:1.227
--- llvm/lib/Target/CBackend/Writer.cpp:1.226	Wed Mar  2 19:04:50 2005
+++ llvm/lib/Target/CBackend/Writer.cpp	Thu Mar  3 15:12:04 2005
@@ -1358,30 +1358,38 @@
     printType(Out, I.getType());
     Out << ")(";
   }
-      
-  writeOperand(I.getOperand(0));
 
-  switch (I.getOpcode()) {
-  case Instruction::Add: Out << " + "; break;
-  case Instruction::Sub: Out << " - "; break;
-  case Instruction::Mul: Out << '*'; break;
-  case Instruction::Div: Out << '/'; break;
-  case Instruction::Rem: Out << '%'; break;
-  case Instruction::And: Out << " & "; break;
-  case Instruction::Or: Out << " | "; break;
-  case Instruction::Xor: Out << " ^ "; break;
-  case Instruction::SetEQ: Out << " == "; break;
-  case Instruction::SetNE: Out << " != "; break;
-  case Instruction::SetLE: Out << " <= "; break;
-  case Instruction::SetGE: Out << " >= "; break;
-  case Instruction::SetLT: Out << " < "; break;
-  case Instruction::SetGT: Out << " > "; break;
-  case Instruction::Shl : Out << " << "; break;
-  case Instruction::Shr : Out << " >> "; break;
-  default: std::cerr << "Invalid operator type!" << I; abort();
-  }
+  // If this is a negation operation, print it out as such.  For FP, we don't
+  // want to print "-0.0 - X".
+  if (BinaryOperator::isNeg(&I)) {
+    Out << "-";
+    writeOperand(BinaryOperator::getNegArgument(cast<BinaryOperator>(&I)));
+
+  } else {
+    writeOperand(I.getOperand(0));
 
-  writeOperand(I.getOperand(1));
+    switch (I.getOpcode()) {
+    case Instruction::Add: Out << " + "; break;
+    case Instruction::Sub: Out << " - "; break;
+    case Instruction::Mul: Out << '*'; break;
+    case Instruction::Div: Out << '/'; break;
+    case Instruction::Rem: Out << '%'; break;
+    case Instruction::And: Out << " & "; break;
+    case Instruction::Or: Out << " | "; break;
+    case Instruction::Xor: Out << " ^ "; break;
+    case Instruction::SetEQ: Out << " == "; break;
+    case Instruction::SetNE: Out << " != "; break;
+    case Instruction::SetLE: Out << " <= "; break;
+    case Instruction::SetGE: Out << " >= "; break;
+    case Instruction::SetLT: Out << " < "; break;
+    case Instruction::SetGT: Out << " > "; break;
+    case Instruction::Shl : Out << " << "; break;
+    case Instruction::Shr : Out << " >> "; break;
+    default: std::cerr << "Invalid operator type!" << I; abort();
+    }
+
+    writeOperand(I.getOperand(1));
+  }
 
   if (needsCast) {
     Out << "))";






More information about the llvm-commits mailing list