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

Reid Spencer reid at x10sys.com
Mon Dec 18 17:28:37 PST 2006



Changes in directory llvm/lib/VMCore:

Constants.cpp updated: 1.189 -> 1.190
---
Log message:

Make ConstantInt not care about sign any more. To ensure the AsmParser can
still check the validity of signed values an overload to isValueValidForType
was added to allow passing in an int64_t to check.


---
Diffs of the changes:  (+19 -14)

 Constants.cpp |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.189 llvm/lib/VMCore/Constants.cpp:1.190
--- llvm/lib/VMCore/Constants.cpp:1.189	Mon Dec 18 02:18:46 2006
+++ llvm/lib/VMCore/Constants.cpp	Mon Dec 18 19:28:19 2006
@@ -592,26 +592,31 @@
 //===----------------------------------------------------------------------===//
 //                      isValueValidForType implementations
 
+bool ConstantInt::isValueValidForType(const Type *Ty, uint64_t Val) {
+  switch (Ty->getTypeID()) {
+  default:              return false; // These can't be represented as integers!
+  case Type::SByteTyID:
+  case Type::UByteTyID: return Val <= UINT8_MAX;
+  case Type::ShortTyID:
+  case Type::UShortTyID:return Val <= UINT16_MAX;
+  case Type::IntTyID:
+  case Type::UIntTyID:  return Val <= UINT32_MAX;
+  case Type::LongTyID:
+  case Type::ULongTyID: return true; // always true, has to fit in largest type
+  }
+}
+
 bool ConstantInt::isValueValidForType(const Type *Ty, int64_t Val) {
   switch (Ty->getTypeID()) {
-  default:
-    return false;         // These can't be represented as integers!!!
-    // Signed types...
+  default:              return false; // These can't be represented as integers!
   case Type::SByteTyID:
-    return (Val <= INT8_MAX && Val >= INT8_MIN);
-  case Type::UByteTyID:
-    return (Val >= 0) && (Val <= UINT8_MAX);
+  case Type::UByteTyID: return (Val >= INT8_MIN && Val <= INT8_MAX);
   case Type::ShortTyID:
-    return (Val <= INT16_MAX && Val >= INT16_MIN);
-  case Type::UShortTyID:
-    return (Val >= 0) && (Val <= UINT16_MAX);
+  case Type::UShortTyID:return (Val >= INT16_MIN && Val <= UINT16_MAX);
   case Type::IntTyID:
-    return (Val <= int(INT32_MAX) && Val >= int(INT32_MIN));
-  case Type::UIntTyID:
-    return (Val >= 0) && (Val <= UINT32_MAX);
+  case Type::UIntTyID:  return (Val >= INT32_MIN && Val <= UINT32_MAX);
   case Type::LongTyID:
-  case Type::ULongTyID:
-    return true; // always true, has to fit in largest type
+  case Type::ULongTyID: return true; // always true, has to fit in largest type
   }
 }
 






More information about the llvm-commits mailing list