Implement a constant pointer value
authorChris Lattner <sabre@nondot.org>
Sun, 30 Sep 2001 20:14:07 +0000 (20:14 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 30 Sep 2001 20:14:07 +0000 (20:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@667 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 71ca6a7a96df812b8e69e5195dfc3c1b9bbf6cd4..7ebe3f3ce282a88ccaadb96b369f1819a9073020 100644 (file)
@@ -13,6 +13,7 @@
 
 class ArrayType;
 class StructType;
+class PointerType;
 
 //===----------------------------------------------------------------------===//
 //                            ConstPoolVal Class
@@ -182,4 +183,24 @@ public:
   inline const vector<Use> &getValues() const { return Operands; }
 };
 
+//===---------------------------------------------------------------------------
+// ConstPoolPointer - Constant Pointer Declarations
+//
+// The ConstPoolPointer class represents a null pointer of a specific type. For
+// a more specific/useful instance, a subclass of ConstPoolPointer should be
+// used.
+//
+class ConstPoolPointer : public ConstPoolVal {
+  ConstPoolPointer(const ConstPoolPointer &);      // DO NOT IMPLEMENT
+protected:
+  ConstPoolPointer(const PointerType *T);
+  ~ConstPoolPointer() {}
+public:
+  static ConstPoolPointer *getNullPointer(const PointerType *T) {
+    return new ConstPoolPointer(T);
+  }
+
+  virtual string getStrValue() const;
+};
+
 #endif
index d53130d6012ecb3cd1ad782d8e7b08a9d2268c75..152209dcc7d9bb4fc08f6d9cf6fb214c5f606d4f 100644 (file)
@@ -43,6 +43,9 @@ ConstPoolVal *ConstPoolVal::getNullConstant(const Type *Ty) {
 
   case Type::FloatTyID:
   case Type::DoubleTyID: return ConstPoolFP::get(Ty, 0);
+
+  case Type::PointerTyID: 
+    return ConstPoolPointer::getNullPointer(Ty->castPointerType());
   default:
     return 0;
   }
@@ -98,6 +101,8 @@ ConstPoolStruct::ConstPoolStruct(const StructType *T,
   }
 }
 
+ConstPoolPointer::ConstPoolPointer(const PointerType *T) : ConstPoolVal(T) {}
+
 
 //===----------------------------------------------------------------------===//
 //                          getStrValue implementations
@@ -144,6 +149,10 @@ string ConstPoolStruct::getStrValue() const {
   return Result + " }";
 }
 
+string ConstPoolPointer::getStrValue() const {
+  return "null";
+}
+
 //===----------------------------------------------------------------------===//
 //                      isValueValidForType implementations