return *PI;
}
+struct EqualsType {
+ const Type *T;
+ inline EqualsType(const Type *t) { T = t; }
+ inline bool operator()(const ConstPoolVal *CPV) const {
+ return static_cast<const ConstPoolType*>(CPV)->getValue() == T;
+ }
+};
+
+// ensureTypeAvailable - This is used to make sure that the specified type is
+// in the constant pool. If it is not already in the constant pool, it is
+// added.
+//
+const Type *ConstantPool::ensureTypeAvailable(const Type *Ty) {
+ // Get the type type plane...
+ PlaneType &P = getPlane(Type::TypeTy);
+ PlaneType::const_iterator PI = find_if(P.begin(), P.end(), EqualsType(Ty));
+
+ if (PI == P.end()) {
+ ConstPoolVal *CPT = new ConstPoolType(Ty);
+ insert(CPT);
+ }
+ return Ty;
+}
+
//===----------------------------------------------------------------------===//
// ConstPoolVal Class
//===----------------------------------------------------------------------===//
Val = V;
}
+ConstPoolInt::ConstPoolInt(const Type *Ty, uint64_t V, const string &Name)
+ : ConstPoolVal(Ty, Name) { Val.Unsigned = V; }
+ConstPoolInt::ConstPoolInt(const Type *Ty, int64_t V, const string &Name)
+ : ConstPoolVal(Ty, Name) { Val.Signed = V; }
+
ConstPoolSInt::ConstPoolSInt(const Type *Ty, int64_t V, const string &Name)
- : ConstPoolVal(Ty, Name) {
+ : ConstPoolInt(Ty, V, Name) {
//cerr << "value = " << (int)V << ": " << Ty->getName() << endl;
- assert(isValueValidForType(Ty, V) && "Value to large for type!");
- Val = V;
+ assert(isValueValidForType(Ty, V) && "Value too large for type!");
}
ConstPoolUInt::ConstPoolUInt(const Type *Ty, uint64_t V, const string &Name)
- : ConstPoolVal(Ty, Name) {
+ : ConstPoolInt(Ty, V, Name) {
//cerr << "Uvalue = " << (int)V << ": " << Ty->getName() << endl;
- assert(isValueValidForType(Ty, V) && "Value to large for type!");
- Val = V;
+ assert(isValueValidForType(Ty, V) && "Value too large for type!");
}
ConstPoolFP::ConstPoolFP(const Type *Ty, double V, const string &Name)
: ConstPoolVal(Ty, Name) {
- assert(isValueValidForType(Ty, V) && "Value to large for type!");
+ assert(isValueValidForType(Ty, V) && "Value too large for type!");
Val = V;
}
Val = CPB.Val;
}
-ConstPoolSInt::ConstPoolSInt(const ConstPoolSInt &CPSI)
- : ConstPoolVal(CPSI.getType()) {
- Val = CPSI.Val;
-}
-
-ConstPoolUInt::ConstPoolUInt(const ConstPoolUInt &CPUI)
- : ConstPoolVal(CPUI.getType()) {
- Val = CPUI.Val;
+ConstPoolInt::ConstPoolInt(const ConstPoolInt &CPI)
+ : ConstPoolVal(CPI.getType()) {
+ Val.Signed = CPI.Val.Signed;
}
ConstPoolFP::ConstPoolFP(const ConstPoolFP &CPFP)
}
string ConstPoolSInt::getStrValue() const {
- return itostr(Val);
+ return itostr(Val.Signed);
}
string ConstPoolUInt::getStrValue() const {
- return utostr(Val);
+ return utostr(Val.Unsigned);
}
string ConstPoolFP::getStrValue() const {
return ((ConstPoolBool*)V)->getValue() == Val;
}
-bool ConstPoolSInt::equals(const ConstPoolVal *V) const {
- assert(getType() == V->getType());
- return ((ConstPoolSInt*)V)->getValue() == Val;
-}
-
-bool ConstPoolUInt::equals(const ConstPoolVal *V) const {
+bool ConstPoolInt::equals(const ConstPoolVal *V) const {
assert(getType() == V->getType());
- return ((ConstPoolUInt*)V)->getValue() == Val;
+ return ((ConstPoolInt*)V)->Val.Signed == Val.Signed;
}
bool ConstPoolFP::equals(const ConstPoolVal *V) const {
return true; // This is the largest type...
}
};
+
+
+//===----------------------------------------------------------------------===//
+// Extra Method implementations
+
+ConstPoolInt *ConstPoolInt::get(const Type *Ty, unsigned char V) {
+ assert(V <= 127 && "equals: Can only be used with very small constants!");
+ if (Ty->isSigned()) return new ConstPoolSInt(Ty, V);
+ return new ConstPoolUInt(Ty, V);
+}