///
class ConstantIntegral : public Constant {
protected:
- ConstantIntegral(const Type *Ty) : Constant(Ty) {}
+ union {
+ int64_t Signed;
+ uint64_t Unsigned;
+ } Val;
+ ConstantIntegral(const Type *Ty, uint64_t V);
public:
+ /// getRawValue - return the underlying value of this constant as a 64-bit
+ /// unsigned integer value.
+ ///
+ inline uint64_t getRawValue() const { return Val.Unsigned; }
+
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue.
///
/// ConstantBool - Boolean Values
///
class ConstantBool : public ConstantIntegral {
- bool Val;
ConstantBool(bool V);
public:
static ConstantBool *True, *False; // The True & False values
/// getValue - return the boolean value of this constant.
///
- inline bool getValue() const { return Val; }
+ inline bool getValue() const { return static_cast<bool>(getRawValue()); }
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue.
///
class ConstantInt : public ConstantIntegral {
protected:
- union {
- int64_t Signed;
- uint64_t Unsigned;
- } Val;
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
ConstantInt(const Type *Ty, uint64_t V);
public:
///
static ConstantInt *get(const Type *Ty, unsigned char V);
- /// getRawValue - return the underlying value of this constant as a 64-bit
- /// unsigned integer value.
- ///
- inline uint64_t getRawValue() const { return Val.Unsigned; }
-
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue.
virtual bool isNullValue() const { return Val.Unsigned == 0; }
//===----------------------------------------------------------------------===//
// Normal Constructors
-ConstantBool::ConstantBool(bool V) : ConstantIntegral(Type::BoolTy) {
- Val = V;
+ConstantIntegral::ConstantIntegral(const Type *Ty, uint64_t V)
+ : Constant(Ty) {
+ Val.Unsigned = V;
+}
+
+ConstantBool::ConstantBool(bool V) : ConstantIntegral(Type::BoolTy, V) {
}
-ConstantInt::ConstantInt(const Type *Ty, uint64_t V) : ConstantIntegral(Ty) {
- Val.Unsigned = V;
+ConstantInt::ConstantInt(const Type *Ty, uint64_t V) : ConstantIntegral(Ty, V) {
}
ConstantSInt::ConstantSInt(const Type *Ty, int64_t V) : ConstantInt(Ty, V) {