X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FConstants.cpp;h=5d7c35f232d0efd87df8c518875df1df3bd23452;hb=f6ffcb6b713c259992b68d6b328f1b806775b9fb;hp=eb68ef68095b65fd5faa7b16c370b012f9c0a557;hpb=9fb96412ae530963cae855ee2dd03da5719c7d6b;p=oota-llvm.git diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index eb68ef68095..5d7c35f232d 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -4,7 +4,6 @@ // //===----------------------------------------------------------------------===// -#define __STDC_LIMIT_MACROS // Get defs for INT64_MAX and friends... #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/iMemory.h" @@ -106,9 +105,7 @@ ConstantIntegral *ConstantIntegral::getMaxValue(const Type *Ty) { case Type::UIntTyID: case Type::ULongTyID: return getAllOnesValue(Ty); - default: - assert(0 && "Non-integral type specified!"); - return 0; + default: return 0; } } @@ -132,9 +129,7 @@ ConstantIntegral *ConstantIntegral::getMinValue(const Type *Ty) { case Type::UIntTyID: case Type::ULongTyID: return ConstantUInt::get(Ty, 0); - default: - assert(0 && "Non-integral type specified!"); - return 0; + default: return 0; } } @@ -157,9 +152,7 @@ ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) { Val >>= 64-TypeBits; // Shift out unwanted 1 bits... return ConstantUInt::get(Ty, Val); } - default: - assert(0 && "Non-integral type specified!"); - return 0; + default: return 0; } } @@ -180,10 +173,14 @@ ConstantInt::ConstantInt(const Type *Ty, uint64_t V) : ConstantIntegral(Ty) { } ConstantSInt::ConstantSInt(const Type *Ty, int64_t V) : ConstantInt(Ty, V) { + assert(Ty->isInteger() && Ty->isSigned() && + "Illegal type for unsigned integer constant!"); assert(isValueValidForType(Ty, V) && "Value too large for type!"); } ConstantUInt::ConstantUInt(const Type *Ty, uint64_t V) : ConstantInt(Ty, V) { + assert(Ty->isInteger() && Ty->isUnsigned() && + "Illegal type for unsigned integer constant!"); assert(isValueValidForType(Ty, V) && "Value too large for type!"); } @@ -242,12 +239,11 @@ ConstantExpr::ConstantExpr(Constant *C, const std::vector &IdxList, // classof implementations bool ConstantIntegral::classof(const Constant *CPV) { - return (CPV->getType()->isIntegral() || CPV->getType() == Type::BoolTy) && - !isa(CPV); + return CPV->getType()->isIntegral() && !isa(CPV); } bool ConstantInt::classof(const Constant *CPV) { - return CPV->getType()->isIntegral() && !isa(CPV); + return CPV->getType()->isInteger() && !isa(CPV); } bool ConstantSInt::classof(const Constant *CPV) { return CPV->getType()->isSigned() && !isa(CPV); @@ -428,6 +424,24 @@ void ConstantArray::destroyConstant() { destroyConstantImpl(); } +// getAsString - If the sub-element type of this array is either sbyte or ubyte, +// then this method converts the array to an std::string and returns it. +// Otherwise, it asserts out. +// +std::string ConstantArray::getAsString() const { + std::string Result; + if (getType()->getElementType() == Type::SByteTy) + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) + Result += (char)cast(getOperand(i))->getValue(); + else { + assert(getType()->getElementType() == Type::UByteTy && "Not a string!"); + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) + Result += (char)cast(getOperand(i))->getValue(); + } + return Result; +} + + //---- ConstantStruct::get() implementation... // static ValueMap, ConstantStruct> StructConstants; @@ -447,6 +461,7 @@ void ConstantStruct::destroyConstant() { destroyConstantImpl(); } + //---- ConstantPointerNull::get() implementation... // static ValueMap NullPtrConstants; @@ -458,6 +473,14 @@ ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) { return Result; } +// destroyConstant - Remove the constant from the constant table... +// +void ConstantPointerNull::destroyConstant() { + NullPtrConstants.remove(this); + destroyConstantImpl(); +} + + //---- ConstantPointerRef::get() implementation... // ConstantPointerRef *ConstantPointerRef::get(GlobalValue *GV) { @@ -467,31 +490,29 @@ ConstantPointerRef *ConstantPointerRef::get(GlobalValue *GV) { return GV->getParent()->getConstantPointerRef(GV); } +// destroyConstant - Remove the constant from the constant table... +// +void ConstantPointerRef::destroyConstant() { + getValue()->getParent()->destroyConstantPointerRef(this); + destroyConstantImpl(); +} + + //---- ConstantExpr::get() implementations... // typedef pair > ExprMapKeyType; static ValueMap ExprConstants; -ConstantExpr *ConstantExpr::get(unsigned Opcode, Constant *C, const Type *Ty) { +ConstantExpr *ConstantExpr::getCast(Constant *C, const Type *Ty) { // Look up the constant in the table first to ensure uniqueness vector argVec(1, C); - const ExprMapKeyType &Key = make_pair(Opcode, argVec); + const ExprMapKeyType &Key = make_pair(Instruction::Cast, argVec); ConstantExpr *Result = ExprConstants.get(Ty, Key); if (Result) return Result; // Its not in the table so create a new one and put it in the table. - // Check the operands for consistency first - assert(Opcode == Instruction::Cast || - (Opcode >= Instruction::FirstUnaryOp && - Opcode < Instruction::NumUnaryOps) && - "Invalid opcode in unary ConstantExpr!"); - - // type of operand will not match result for Cast operation - assert((Opcode == Instruction::Cast || Ty == C->getType()) && - "Type of operand in unary constant expression should match result"); - - Result = new ConstantExpr(Opcode, C, Ty); + Result = new ConstantExpr(Instruction::Cast, C, Ty); ExprConstants.add(Ty, Key, Result); return Result; }