#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 <algorithm>
-#include <assert.h>
+
+using std::map;
+using std::pair;
+using std::make_pair;
ConstantBool *ConstantBool::True = new ConstantBool(true);
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:
}
}
-#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
Value *V = use_back();
#ifndef NDEBUG // Only in -g mode...
if (!isa<Constant>(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<Constant>(V) && "References remain to ConstantPointerRef!");
}
ConstantArray::ConstantArray(const ArrayType *T,
- const vector<Constant*> &V) : Constant(T) {
+ const std::vector<Constant*> &V) : Constant(T) {
for (unsigned i = 0; i < V.size(); i++) {
assert(V[i]->getType() == T->getElementType());
Operands.push_back(Use(V[i], this));
}
ConstantStruct::ConstantStruct(const StructType *T,
- const vector<Constant*> &V) : Constant(T) {
+ const std::vector<Constant*> &V) : Constant(T) {
const StructType::ElementTypes &ETypes = T->getElementTypes();
for (unsigned i = 0; i < V.size(); i++) {
-//===----------------------------------------------------------------------===//
-// 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<ArrayType>(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<ConstantSInt>(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<ConstantSInt>(Operands[i])->getValue() :
- (unsigned char)cast<ConstantUInt>(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<Constant>(Operands[0])->getStrValue();
- for (unsigned i = 1; i < Operands.size(); i++)
- Result += ", " + Operands[i]->getType()->getDescription() +
- " " + cast<Constant>(Operands[i])->getStrValue();
- }
- Result += " ]";
- }
-
- return Result;
-}
-
-string ConstantStruct::getStrValue() const {
- string Result = "{";
- if (Operands.size()) {
- Result += " " + Operands[0]->getType()->getDescription() +
- " " + cast<Constant>(Operands[0])->getStrValue();
- for (unsigned i = 1; i < Operands.size(); i++)
- Result += ", " + Operands[i]->getType()->getDescription() +
- " " + cast<Constant>(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 "<pointer reference badref>";
-}
-
-
//===----------------------------------------------------------------------===//
// classof implementations
}
};
-//===----------------------------------------------------------------------===//
-// 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<Constant*> &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<Constant*> &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
//---- ConstantArray::get() implementation...
//
-static ValueMap<vector<Constant*>, ConstantArray> ArrayConstants;
+static ValueMap<std::vector<Constant*>, ConstantArray> ArrayConstants;
ConstantArray *ConstantArray::get(const ArrayType *Ty,
- const vector<Constant*> &V) {
+ const std::vector<Constant*> &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));
// 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<Constant*> ElementVals;
+ConstantArray *ConstantArray::get(const std::string &Str) {
+ std::vector<Constant*> ElementVals;
for (unsigned i = 0; i < Str.length(); ++i)
ElementVals.push_back(ConstantSInt::get(Type::SByteTy, Str[i]));
//---- ConstantStruct::get() implementation...
//
-static ValueMap<vector<Constant*>, ConstantStruct> StructConstants;
+static ValueMap<std::vector<Constant*>, ConstantStruct> StructConstants;
ConstantStruct *ConstantStruct::get(const StructType *Ty,
- const vector<Constant*> &V) {
+ const std::vector<Constant*> &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));