Make ConstantBool act like a 1 bit ConstantInt, in order to simplify client
authorChris Lattner <sabre@nondot.org>
Mon, 21 Jun 2004 12:12:12 +0000 (12:12 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 21 Jun 2004 12:12:12 +0000 (12:12 +0000)
code.  Patch contributed by Vladimir Prus.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14280 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Constants.h
lib/VMCore/Constants.cpp

index 9016f1a611cb91ede6999e15c0446fda4d2987ea..fbb7a42f5dbc227f01a94c2828c1531ae0e62b45 100644 (file)
@@ -37,9 +37,18 @@ struct ConvertConstantType;
 ///
 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.
   ///
@@ -79,7 +88,6 @@ public:
 /// ConstantBool - Boolean Values
 ///
 class ConstantBool : public ConstantIntegral {
-  bool Val;
   ConstantBool(bool V);
 public:
   static ConstantBool *True, *False;  // The True & False values
@@ -93,7 +101,7 @@ public:
 
   /// 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.
@@ -120,10 +128,6 @@ public:
 ///
 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:
@@ -143,11 +147,6 @@ 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; }
index e18f9b2e543f57094ddf9f67328a263c03da1266..9957327bfcab12443f9fd381db4626773ec097cd 100644 (file)
@@ -212,12 +212,15 @@ bool ConstantUInt::isAllOnesValue() const {
 //===----------------------------------------------------------------------===//
 //                             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) {