mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-28 22:55:52 +00:00
Fix bug: CBackend/2003-06-11-HexConstant.ll
Fix bug: CBackend/2003-06-11-LiteralStringProblem.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6697 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e158b19a3c
commit
02da6c0f08
@ -285,24 +285,35 @@ void CWriter::printConstantArray(ConstantArray *CPA) {
|
|||||||
bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
|
bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
|
||||||
|
|
||||||
// Make sure the last character is a null char, as automatically added by C
|
// Make sure the last character is a null char, as automatically added by C
|
||||||
if (CPA->getNumOperands() == 0 ||
|
if (isString && (CPA->getNumOperands() == 0 ||
|
||||||
!cast<Constant>(*(CPA->op_end()-1))->isNullValue())
|
!cast<Constant>(*(CPA->op_end()-1))->isNullValue()))
|
||||||
isString = false;
|
isString = false;
|
||||||
|
|
||||||
if (isString) {
|
if (isString) {
|
||||||
Out << "\"";
|
Out << "\"";
|
||||||
|
// Keep track of whether the last number was a hexadecimal escape
|
||||||
|
bool LastWasHex = false;
|
||||||
|
|
||||||
// Do not include the last character, which we know is null
|
// Do not include the last character, which we know is null
|
||||||
for (unsigned i = 0, e = CPA->getNumOperands()-1; i != e; ++i) {
|
for (unsigned i = 0, e = CPA->getNumOperands()-1; i != e; ++i) {
|
||||||
unsigned char C = (ETy == Type::SByteTy) ?
|
unsigned char C = (ETy == Type::SByteTy) ?
|
||||||
(unsigned char)cast<ConstantSInt>(CPA->getOperand(i))->getValue() :
|
(unsigned char)cast<ConstantSInt>(CPA->getOperand(i))->getValue() :
|
||||||
(unsigned char)cast<ConstantUInt>(CPA->getOperand(i))->getValue();
|
(unsigned char)cast<ConstantUInt>(CPA->getOperand(i))->getValue();
|
||||||
|
|
||||||
if (isprint(C)) {
|
// Print it out literally if it is a printable character. The only thing
|
||||||
|
// to be careful about is when the last letter output was a hex escape
|
||||||
|
// code, in which case we have to be careful not to print out hex digits
|
||||||
|
// explicitly (the C compiler things it is a continuation of the previous
|
||||||
|
// character, arg...)
|
||||||
|
//
|
||||||
|
if (isprint(C) && (!LastWasHex || !isxdigit(C))) {
|
||||||
|
LastWasHex = false;
|
||||||
if (C == '"' || C == '\\')
|
if (C == '"' || C == '\\')
|
||||||
Out << "\\" << C;
|
Out << "\\" << C;
|
||||||
else
|
else
|
||||||
Out << C;
|
Out << C;
|
||||||
} else {
|
} else {
|
||||||
|
LastWasHex = false;
|
||||||
switch (C) {
|
switch (C) {
|
||||||
case '\n': Out << "\\n"; break;
|
case '\n': Out << "\\n"; break;
|
||||||
case '\t': Out << "\\t"; break;
|
case '\t': Out << "\\t"; break;
|
||||||
@ -313,8 +324,9 @@ void CWriter::printConstantArray(ConstantArray *CPA) {
|
|||||||
case '\'': Out << "\\\'"; break;
|
case '\'': Out << "\\\'"; break;
|
||||||
default:
|
default:
|
||||||
Out << "\\x";
|
Out << "\\x";
|
||||||
Out << ( C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A');
|
Out << (char)(( C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A'));
|
||||||
Out << ((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A');
|
Out << (char)(((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A'));
|
||||||
|
LastWasHex = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,24 +285,35 @@ void CWriter::printConstantArray(ConstantArray *CPA) {
|
|||||||
bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
|
bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
|
||||||
|
|
||||||
// Make sure the last character is a null char, as automatically added by C
|
// Make sure the last character is a null char, as automatically added by C
|
||||||
if (CPA->getNumOperands() == 0 ||
|
if (isString && (CPA->getNumOperands() == 0 ||
|
||||||
!cast<Constant>(*(CPA->op_end()-1))->isNullValue())
|
!cast<Constant>(*(CPA->op_end()-1))->isNullValue()))
|
||||||
isString = false;
|
isString = false;
|
||||||
|
|
||||||
if (isString) {
|
if (isString) {
|
||||||
Out << "\"";
|
Out << "\"";
|
||||||
|
// Keep track of whether the last number was a hexadecimal escape
|
||||||
|
bool LastWasHex = false;
|
||||||
|
|
||||||
// Do not include the last character, which we know is null
|
// Do not include the last character, which we know is null
|
||||||
for (unsigned i = 0, e = CPA->getNumOperands()-1; i != e; ++i) {
|
for (unsigned i = 0, e = CPA->getNumOperands()-1; i != e; ++i) {
|
||||||
unsigned char C = (ETy == Type::SByteTy) ?
|
unsigned char C = (ETy == Type::SByteTy) ?
|
||||||
(unsigned char)cast<ConstantSInt>(CPA->getOperand(i))->getValue() :
|
(unsigned char)cast<ConstantSInt>(CPA->getOperand(i))->getValue() :
|
||||||
(unsigned char)cast<ConstantUInt>(CPA->getOperand(i))->getValue();
|
(unsigned char)cast<ConstantUInt>(CPA->getOperand(i))->getValue();
|
||||||
|
|
||||||
if (isprint(C)) {
|
// Print it out literally if it is a printable character. The only thing
|
||||||
|
// to be careful about is when the last letter output was a hex escape
|
||||||
|
// code, in which case we have to be careful not to print out hex digits
|
||||||
|
// explicitly (the C compiler things it is a continuation of the previous
|
||||||
|
// character, arg...)
|
||||||
|
//
|
||||||
|
if (isprint(C) && (!LastWasHex || !isxdigit(C))) {
|
||||||
|
LastWasHex = false;
|
||||||
if (C == '"' || C == '\\')
|
if (C == '"' || C == '\\')
|
||||||
Out << "\\" << C;
|
Out << "\\" << C;
|
||||||
else
|
else
|
||||||
Out << C;
|
Out << C;
|
||||||
} else {
|
} else {
|
||||||
|
LastWasHex = false;
|
||||||
switch (C) {
|
switch (C) {
|
||||||
case '\n': Out << "\\n"; break;
|
case '\n': Out << "\\n"; break;
|
||||||
case '\t': Out << "\\t"; break;
|
case '\t': Out << "\\t"; break;
|
||||||
@ -313,8 +324,9 @@ void CWriter::printConstantArray(ConstantArray *CPA) {
|
|||||||
case '\'': Out << "\\\'"; break;
|
case '\'': Out << "\\\'"; break;
|
||||||
default:
|
default:
|
||||||
Out << "\\x";
|
Out << "\\x";
|
||||||
Out << ( C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A');
|
Out << (char)(( C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A'));
|
||||||
Out << ((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A');
|
Out << (char)(((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A'));
|
||||||
|
LastWasHex = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user