[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Constants.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Jul 23 10:23:09 PDT 2003


Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.91 -> 1.92
Constants.cpp updated: 1.46 -> 1.47

---
Log message:

Simplify code by using ConstantInt::getRawValue instead of checking to see 
whether the constant is signed or unsigned, then casting


---
Diffs of the changes:

Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.91 llvm/lib/VMCore/AsmWriter.cpp:1.92
--- llvm/lib/VMCore/AsmWriter.cpp:1.91	Mon Jul 14 12:18:22 2003
+++ llvm/lib/VMCore/AsmWriter.cpp	Wed Jul 23 10:22:26 2003
@@ -274,9 +274,7 @@
     if (isString) {
       Out << "c\"";
       for (unsigned i = 0; i < CA->getNumOperands(); ++i) {
-        unsigned char C = (ETy == Type::SByteTy) ?
-          (unsigned char)cast<ConstantSInt>(CA->getOperand(i))->getValue() :
-          (unsigned char)cast<ConstantUInt>(CA->getOperand(i))->getValue();
+        unsigned char C = cast<ConstantInt>(CA->getOperand(i))->getRawValue();
         
         if (isprint(C) && C != '"' && C != '\\') {
           Out << C;


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.46 llvm/lib/VMCore/Constants.cpp:1.47
--- llvm/lib/VMCore/Constants.cpp:1.46	Sun Jun 22 15:48:30 2003
+++ llvm/lib/VMCore/Constants.cpp	Wed Jul 23 10:22:26 2003
@@ -601,15 +601,12 @@
 // Otherwise, it asserts out.
 //
 std::string ConstantArray::getAsString() const {
+  assert((getType()->getElementType() == Type::UByteTy ||
+          getType()->getElementType() == Type::SByteTy) && "Not a string!");
+
   std::string Result;
-  if (getType()->getElementType() == Type::SByteTy)
-    for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
-      Result += (char)cast<ConstantSInt>(getOperand(i))->getValue();
-  else {
-    assert(getType()->getElementType() == Type::UByteTy && "Not a string!");
-    for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
-      Result += (char)cast<ConstantUInt>(getOperand(i))->getValue();
-  }
+  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
+    Result += (char)cast<ConstantInt>(getOperand(i))->getRawValue();
   return Result;
 }
 





More information about the llvm-commits mailing list