forked from OSchip/llvm-project
* Remove dead function
* Print C strings correctly * Expand C escape sequences nicely (ie \n \t, etc get generated instead of hex escapes) llvm-svn: 2572
This commit is contained in:
parent
af14c8d51f
commit
2fca988a57
|
@ -72,11 +72,6 @@ static string makeNameProper(string x) {
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string getConstantName(const Constant *CPV) {
|
|
||||||
return CPV->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static std::string getConstArrayStrValue(const Constant* CPV) {
|
static std::string getConstArrayStrValue(const Constant* CPV) {
|
||||||
std::string Result;
|
std::string Result;
|
||||||
|
|
||||||
|
@ -94,10 +89,17 @@ static std::string getConstArrayStrValue(const Constant* CPV) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isString) {
|
||||||
|
// Make sure the last character is a null char, as automatically added by C
|
||||||
|
if (CPV->getNumOperands() == 0 ||
|
||||||
|
!cast<Constant>(*(CPV->op_end()-1))->isNullValue())
|
||||||
|
isString = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isString) {
|
if (isString) {
|
||||||
Result = "\"";
|
Result = "\"";
|
||||||
for (unsigned i = 0; i < CPV->getNumOperands(); ++i) {
|
// Do not include the last character, which we know is null
|
||||||
|
for (unsigned i = 0, e = CPV->getNumOperands()-1; i != e; ++i) {
|
||||||
unsigned char C = (ETy == Type::SByteTy) ?
|
unsigned char C = (ETy == Type::SByteTy) ?
|
||||||
(unsigned char)cast<ConstantSInt>(CPV->getOperand(i))->getValue() :
|
(unsigned char)cast<ConstantSInt>(CPV->getOperand(i))->getValue() :
|
||||||
(unsigned char)cast<ConstantUInt>(CPV->getOperand(i))->getValue();
|
(unsigned char)cast<ConstantUInt>(CPV->getOperand(i))->getValue();
|
||||||
|
@ -105,9 +107,18 @@ static std::string getConstArrayStrValue(const Constant* CPV) {
|
||||||
if (isprint(C)) {
|
if (isprint(C)) {
|
||||||
Result += C;
|
Result += C;
|
||||||
} else {
|
} else {
|
||||||
Result += "\\x";
|
switch (C) {
|
||||||
Result += ( C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A');
|
case '\n': Result += "\\n"; break;
|
||||||
Result += ((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A');
|
case '\t': Result += "\\t"; break;
|
||||||
|
case '\r': Result += "\\r"; break;
|
||||||
|
case '\v': Result += "\\v"; break;
|
||||||
|
case '\a': Result += "\\a"; break;
|
||||||
|
default:
|
||||||
|
Result += "\\x";
|
||||||
|
Result += ( C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A');
|
||||||
|
Result += ((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A');
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Result += "\"";
|
Result += "\"";
|
||||||
|
|
Loading…
Reference in New Issue