mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-16 23:19:37 +00:00
Move asmwriter/getStrValue cruft into AsmWriter.cpp file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2300 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
66e810be9f
commit
68d892dc0d
@ -141,134 +141,6 @@ ConstantPointerRef::ConstantPointerRef(GlobalValue *GV)
|
||||
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// getStrValue implementations
|
||||
|
||||
std::string ConstantBool::getStrValue() const {
|
||||
return Val ? "true" : "false";
|
||||
}
|
||||
|
||||
std::string ConstantSInt::getStrValue() const {
|
||||
return itostr(Val.Signed);
|
||||
}
|
||||
|
||||
std::string ConstantUInt::getStrValue() const {
|
||||
return utostr(Val.Unsigned);
|
||||
}
|
||||
|
||||
// ConstantFP::getStrValue - We would like to output the FP constant value in
|
||||
// exponential notation, but we cannot do this if doing so will lose precision.
|
||||
// Check here to make sure that we only output it in exponential format if we
|
||||
// can parse the value back and get the same value.
|
||||
//
|
||||
std::string ConstantFP::getStrValue() const {
|
||||
std::string StrVal = ftostr(Val);
|
||||
|
||||
// Check to make sure that the stringized number is not some string like "Inf"
|
||||
// or NaN, that atof will accept, but the lexer will not. Check that the
|
||||
// string matches the "[-+]?[0-9]" regex.
|
||||
//
|
||||
if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
|
||||
((StrVal[0] == '-' || StrVal[0] == '+') &&
|
||||
(StrVal[0] >= '0' && StrVal[0] <= '9'))) {
|
||||
double TestVal = atof(StrVal.c_str()); // Reparse stringized version!
|
||||
if (TestVal == Val)
|
||||
return StrVal;
|
||||
}
|
||||
|
||||
// Otherwise we could not reparse it to exactly the same value, so we must
|
||||
// output the string in hexadecimal format!
|
||||
//
|
||||
// Behave nicely in the face of C TBAA rules... see:
|
||||
// http://www.nullstone.com/htmls/category/aliastyp.htm
|
||||
//
|
||||
char *Ptr = (char*)&Val;
|
||||
assert(sizeof(double) == sizeof(uint64_t) && sizeof(double) == 8 &&
|
||||
"assuming that double is 64 bits!");
|
||||
return "0x"+utohexstr(*(uint64_t*)Ptr);
|
||||
}
|
||||
|
||||
std::string ConstantArray::getStrValue() const {
|
||||
std::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 = 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;
|
||||
}
|
||||
|
||||
std::string ConstantStruct::getStrValue() const {
|
||||
std::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 + " }";
|
||||
}
|
||||
|
||||
std::string ConstantPointerNull::getStrValue() const {
|
||||
return "null";
|
||||
}
|
||||
|
||||
std::string ConstantPointerRef::getStrValue() const {
|
||||
const GlobalValue *V = getValue();
|
||||
if (V->hasName()) return "%" + V->getName();
|
||||
|
||||
// FIXME: This is a gross hack.
|
||||
SlotCalculator *Table = new SlotCalculator(V->getParent(), true);
|
||||
int Slot = Table->getValSlot(V);
|
||||
delete Table;
|
||||
|
||||
if (Slot >= 0) return std::string(" %") + itostr(Slot);
|
||||
else return "<pointer reference badref>";
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// classof implementations
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user