1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

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.

llvm-svn: 32663
This commit is contained in:
Reid Spencer 2006-12-19 01:28:19 +00:00
parent 28c15ed860
commit e9d6e54b36
2 changed files with 25 additions and 17 deletions

View File

@ -181,9 +181,12 @@ public:
/// This static method returns true if the type Ty is big enough to
/// represent the value V. This can be used to avoid having the get method
/// assert when V is larger than Ty can represent.
/// assert when V is larger than Ty can represent. Note that values are
/// always treated as unsigned so if the intention is to represent a signed
/// type, you must do the conversion first.
/// @returns true if V is a valid value for type Ty
/// @brief Determine if the value is in range for the given type.
static bool isValueValidForType(const Type *Ty, uint64_t V);
static bool isValueValidForType(const Type *Ty, int64_t V);
/// @returns true if this is the null integer value.
@ -205,7 +208,7 @@ public:
int64_t V = getSExtValue();
if (V < 0) return false; // Be careful about wrap-around on 'long's
++V;
return !isValueValidForType(getType()->getSignedVersion(), V) || V < 0;
return !isValueValidForType(getType(), V) || V < 0;
}
return isAllOnesValue();
}
@ -219,7 +222,7 @@ public:
int64_t V = getSExtValue();
if (V > 0) return false; // Be careful about wrap-around on 'long's
--V;
return !isValueValidForType(getType()->getSignedVersion(), V) || V > 0;
return !isValueValidForType(getType(), V) || V > 0;
}
return getZExtValue() == 0;
}

View File

@ -592,26 +592,31 @@ getWithOperands(const std::vector<Constant*> &Ops) const {
//===----------------------------------------------------------------------===//
// 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
}
}