X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FConstants.cpp;h=8bf1d9cc199ad6cb51730b344b12ff84ca7733e0;hb=67e08db3b97e83637c596e3ef4866e64552762cc;hp=257bd7622c9dd9c5cb2588cadb832fcdb5f1550b;hpb=e917eaec6a473580033887d5745cc4e83240a36d;p=oota-llvm.git diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 257bd7622c9..8bf1d9cc199 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -10,10 +10,13 @@ #include "llvm/SymbolTable.h" #include "llvm/GlobalValue.h" #include "llvm/Module.h" -#include "llvm/Analysis/SlotCalculator.h" +#include "llvm/SlotCalculator.h" #include "Support/StringExtras.h" #include -#include + +using std::map; +using std::pair; +using std::make_pair; ConstantBool *ConstantBool::True = new ConstantBool(true); ConstantBool *ConstantBool::False = new ConstantBool(false); @@ -24,14 +27,14 @@ ConstantBool *ConstantBool::False = new ConstantBool(false); //===----------------------------------------------------------------------===// // Specialize setName to take care of symbol table majik -void Constant::setName(const string &Name, SymbolTable *ST) { +void Constant::setName(const std::string &Name, SymbolTable *ST) { assert(ST && "Type::setName - Must provide symbol table argument!"); if (Name.size()) ST->insert(Name, this); } // Static constructor to create a '0' constant of arbitrary type... -Constant *Constant::getNullConstant(const Type *Ty) { +Constant *Constant::getNullValue(const Type *Ty) { switch (Ty->getPrimitiveID()) { case Type::BoolTyID: return ConstantBool::get(false); case Type::SByteTyID: @@ -54,10 +57,6 @@ Constant *Constant::getNullConstant(const Type *Ty) { } } -#ifndef NDEBUG -#include "llvm/Assembly/Writer.h" -#endif - void Constant::destroyConstantImpl() { // When a Constant is destroyed, there may be lingering // references to the constant by other constants in the constant pool. These @@ -70,8 +69,11 @@ void Constant::destroyConstantImpl() { Value *V = use_back(); #ifndef NDEBUG // Only in -g mode... if (!isa(V)) { - cerr << "While deleting: " << this << endl; - cerr << "Use still stuck around after Def is destroyed: " << V << endl; + std::cerr << "While deleting: "; + dump(); + std::cerr << "\nUse still stuck around after Def is destroyed: "; + V->dump(); + std::cerr << "\n"; } #endif assert(isa(V) && "References remain to ConstantPointerRef!"); @@ -115,7 +117,7 @@ ConstantFP::ConstantFP(const Type *Ty, double V) : Constant(Ty) { } ConstantArray::ConstantArray(const ArrayType *T, - const vector &V) : Constant(T) { + const std::vector &V) : Constant(T) { for (unsigned i = 0; i < V.size(); i++) { assert(V[i]->getType() == T->getElementType()); Operands.push_back(Use(V[i], this)); @@ -123,7 +125,7 @@ ConstantArray::ConstantArray(const ArrayType *T, } ConstantStruct::ConstantStruct(const StructType *T, - const vector &V) : Constant(T) { + const std::vector &V) : Constant(T) { const StructType::ElementTypes &ETypes = T->getElementTypes(); for (unsigned i = 0; i < V.size(); i++) { @@ -139,105 +141,6 @@ ConstantPointerRef::ConstantPointerRef(GlobalValue *GV) -//===----------------------------------------------------------------------===// -// getStrValue implementations - -string ConstantBool::getStrValue() const { - return Val ? "true" : "false"; -} - -string ConstantSInt::getStrValue() const { - return itostr(Val.Signed); -} - -string ConstantUInt::getStrValue() const { - return utostr(Val.Unsigned); -} - -string ConstantFP::getStrValue() const { - return ftostr(Val); -} - -string ConstantArray::getStrValue() const { - string Result; - - // As a special case, print the array as a string if it is an array of - // ubytes or an array of sbytes with positive values. - // - const Type *ETy = cast(getType())->getElementType(); - bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy); - - if (ETy == Type::SByteTy) { - for (unsigned i = 0; i < Operands.size(); ++i) - if (ETy == Type::SByteTy && - cast(Operands[i])->getValue() < 0) { - isString = false; - break; - } - } - - if (isString) { - Result = "c\""; - for (unsigned i = 0; i < Operands.size(); ++i) { - unsigned char C = (ETy == Type::SByteTy) ? - (unsigned char)cast(Operands[i])->getValue() : - (unsigned char)cast(Operands[i])->getValue(); - - if (isprint(C)) { - Result += C; - } else { - Result += '\\'; - Result += ( C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A'); - Result += ((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A'); - } - } - Result += "\""; - - } else { - Result = "["; - if (Operands.size()) { - Result += " " + Operands[0]->getType()->getDescription() + - " " + cast(Operands[0])->getStrValue(); - for (unsigned i = 1; i < Operands.size(); i++) - Result += ", " + Operands[i]->getType()->getDescription() + - " " + cast(Operands[i])->getStrValue(); - } - Result += " ]"; - } - - return Result; -} - -string ConstantStruct::getStrValue() const { - string Result = "{"; - if (Operands.size()) { - Result += " " + Operands[0]->getType()->getDescription() + - " " + cast(Operands[0])->getStrValue(); - for (unsigned i = 1; i < Operands.size(); i++) - Result += ", " + Operands[i]->getType()->getDescription() + - " " + cast(Operands[i])->getStrValue(); - } - - return Result + " }"; -} - -string ConstantPointerNull::getStrValue() const { - return "null"; -} - -string ConstantPointerRef::getStrValue() const { - const GlobalValue *V = getValue(); - if (V->hasName()) return "%" + V->getName(); - - SlotCalculator *Table = new SlotCalculator(V->getParent(), true); - int Slot = Table->getValSlot(V); - delete Table; - - if (Slot >= 0) return string(" %") + itostr(Slot); - else return ""; -} - - //===----------------------------------------------------------------------===// // classof implementations @@ -321,38 +224,6 @@ bool ConstantFP::isValueValidForType(const Type *Ty, double Val) { } }; -//===----------------------------------------------------------------------===// -// Hash Function Implementations -#if 0 -unsigned ConstantSInt::hash(const Type *Ty, int64_t V) { - return unsigned(Ty->getPrimitiveID() ^ V); -} - -unsigned ConstantUInt::hash(const Type *Ty, uint64_t V) { - return unsigned(Ty->getPrimitiveID() ^ V); -} - -unsigned ConstantFP::hash(const Type *Ty, double V) { - return Ty->getPrimitiveID() ^ unsigned(V); -} - -unsigned ConstantArray::hash(const ArrayType *Ty, - const vector &V) { - unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7); - for (unsigned i = 0; i < V.size(); ++i) - Result ^= V[i]->getHash() << (i & 7); - return Result; -} - -unsigned ConstantStruct::hash(const StructType *Ty, - const vector &V) { - unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7); - for (unsigned i = 0; i < V.size(); ++i) - Result ^= V[i]->getHash() << (i & 7); - return Result; -} -#endif - //===----------------------------------------------------------------------===// // Factory Function Implementation @@ -418,10 +289,10 @@ ConstantFP *ConstantFP::get(const Type *Ty, double V) { //---- ConstantArray::get() implementation... // -static ValueMap, ConstantArray> ArrayConstants; +static ValueMap, ConstantArray> ArrayConstants; ConstantArray *ConstantArray::get(const ArrayType *Ty, - const vector &V) { + const std::vector &V) { ConstantArray *Result = ArrayConstants.get(Ty, V); if (!Result) // If no preexisting value, create one now... ArrayConstants.add(Ty, V, Result = new ConstantArray(Ty, V)); @@ -432,8 +303,8 @@ ConstantArray *ConstantArray::get(const ArrayType *Ty, // contain the specified string. A null terminator is added to the specified // string so that it may be used in a natural way... // -ConstantArray *ConstantArray::get(const string &Str) { - vector ElementVals; +ConstantArray *ConstantArray::get(const std::string &Str) { + std::vector ElementVals; for (unsigned i = 0; i < Str.length(); ++i) ElementVals.push_back(ConstantSInt::get(Type::SByteTy, Str[i])); @@ -455,10 +326,10 @@ void ConstantArray::destroyConstant() { //---- ConstantStruct::get() implementation... // -static ValueMap, ConstantStruct> StructConstants; +static ValueMap, ConstantStruct> StructConstants; ConstantStruct *ConstantStruct::get(const StructType *Ty, - const vector &V) { + const std::vector &V) { ConstantStruct *Result = StructConstants.get(Ty, V); if (!Result) // If no preexisting value, create one now... StructConstants.add(Ty, V, Result = new ConstantStruct(Ty, V));