mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 21:24:00 +00:00
Sign-extend array index expressions to work correctly on non-32 bit machines.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3496 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -210,7 +210,8 @@ ostream &CWriter::printType(const Type *Ty, const string &NameSoFar,
|
|||||||
|
|
||||||
case Type::PointerTyID: {
|
case Type::PointerTyID: {
|
||||||
const PointerType *PTy = cast<PointerType>(Ty);
|
const PointerType *PTy = cast<PointerType>(Ty);
|
||||||
return printType(PTy->getElementType(), "(*" + NameSoFar + ")");
|
std::string ptrName = NameSoFar.length()? "(*"+NameSoFar+")" : string("*");
|
||||||
|
return printType(PTy->getElementType(), ptrName);
|
||||||
}
|
}
|
||||||
|
|
||||||
case Type::ArrayTyID: {
|
case Type::ArrayTyID: {
|
||||||
@ -844,16 +845,20 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
|
|||||||
Out << (HasImplicitAddress ? "." : "->");
|
Out << (HasImplicitAddress ? "." : "->");
|
||||||
Out << "field" << cast<ConstantUInt>(*(I+1))->getValue();
|
Out << "field" << cast<ConstantUInt>(*(I+1))->getValue();
|
||||||
I += 2;
|
I += 2;
|
||||||
} else { // Performing array indexing. Just skip the 0
|
} else { // First array index of 0: Just skip it
|
||||||
++I;
|
++I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; I != E; ++I)
|
for (; I != E; ++I)
|
||||||
if ((*I)->getType() == Type::UIntTy) {
|
if ((*I)->getType() == Type::UIntTy) {
|
||||||
Out << "[";
|
Out << "[((int) ("; // sign-extend from 32 (to 64) bits
|
||||||
writeOperand(*I);
|
writeOperand(*I);
|
||||||
Out << "]";
|
Out << " * sizeof(";
|
||||||
|
printType(cast<PointerType>(Ptr->getType())->getElementType());
|
||||||
|
Out << "))) / sizeof(";
|
||||||
|
printType(cast<PointerType>(Ptr->getType())->getElementType());
|
||||||
|
Out << ")]";
|
||||||
} else {
|
} else {
|
||||||
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,8 @@ ostream &CWriter::printType(const Type *Ty, const string &NameSoFar,
|
|||||||
|
|
||||||
case Type::PointerTyID: {
|
case Type::PointerTyID: {
|
||||||
const PointerType *PTy = cast<PointerType>(Ty);
|
const PointerType *PTy = cast<PointerType>(Ty);
|
||||||
return printType(PTy->getElementType(), "(*" + NameSoFar + ")");
|
std::string ptrName = NameSoFar.length()? "(*"+NameSoFar+")" : string("*");
|
||||||
|
return printType(PTy->getElementType(), ptrName);
|
||||||
}
|
}
|
||||||
|
|
||||||
case Type::ArrayTyID: {
|
case Type::ArrayTyID: {
|
||||||
@ -844,16 +845,20 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
|
|||||||
Out << (HasImplicitAddress ? "." : "->");
|
Out << (HasImplicitAddress ? "." : "->");
|
||||||
Out << "field" << cast<ConstantUInt>(*(I+1))->getValue();
|
Out << "field" << cast<ConstantUInt>(*(I+1))->getValue();
|
||||||
I += 2;
|
I += 2;
|
||||||
} else { // Performing array indexing. Just skip the 0
|
} else { // First array index of 0: Just skip it
|
||||||
++I;
|
++I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; I != E; ++I)
|
for (; I != E; ++I)
|
||||||
if ((*I)->getType() == Type::UIntTy) {
|
if ((*I)->getType() == Type::UIntTy) {
|
||||||
Out << "[";
|
Out << "[((int) ("; // sign-extend from 32 (to 64) bits
|
||||||
writeOperand(*I);
|
writeOperand(*I);
|
||||||
Out << "]";
|
Out << " * sizeof(";
|
||||||
|
printType(cast<PointerType>(Ptr->getType())->getElementType());
|
||||||
|
Out << "))) / sizeof(";
|
||||||
|
printType(cast<PointerType>(Ptr->getType())->getElementType());
|
||||||
|
Out << ")]";
|
||||||
} else {
|
} else {
|
||||||
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user