diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 13 | ||||
-rw-r--r-- | lib/Target/CBackend/Writer.cpp | 13 |
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index e33622f71f..f4fb7a2458 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -210,7 +210,8 @@ ostream &CWriter::printType(const Type *Ty, const string &NameSoFar, case Type::PointerTyID: { 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: { @@ -844,16 +845,20 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I, Out << (HasImplicitAddress ? "." : "->"); Out << "field" << cast<ConstantUInt>(*(I+1))->getValue(); I += 2; - } else { // Performing array indexing. Just skip the 0 + } else { // First array index of 0: Just skip it ++I; } } for (; I != E; ++I) if ((*I)->getType() == Type::UIntTy) { - Out << "["; + Out << "[((int) ("; // sign-extend from 32 (to 64) bits writeOperand(*I); - Out << "]"; + Out << " * sizeof("; + printType(cast<PointerType>(Ptr->getType())->getElementType()); + Out << "))) / sizeof("; + printType(cast<PointerType>(Ptr->getType())->getElementType()); + Out << ")]"; } else { Out << ".field" << cast<ConstantUInt>(*I)->getValue(); } diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index e33622f71f..f4fb7a2458 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -210,7 +210,8 @@ ostream &CWriter::printType(const Type *Ty, const string &NameSoFar, case Type::PointerTyID: { 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: { @@ -844,16 +845,20 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I, Out << (HasImplicitAddress ? "." : "->"); Out << "field" << cast<ConstantUInt>(*(I+1))->getValue(); I += 2; - } else { // Performing array indexing. Just skip the 0 + } else { // First array index of 0: Just skip it ++I; } } for (; I != E; ++I) if ((*I)->getType() == Type::UIntTy) { - Out << "["; + Out << "[((int) ("; // sign-extend from 32 (to 64) bits writeOperand(*I); - Out << "]"; + Out << " * sizeof("; + printType(cast<PointerType>(Ptr->getType())->getElementType()); + Out << "))) / sizeof("; + printType(cast<PointerType>(Ptr->getType())->getElementType()); + Out << ")]"; } else { Out << ".field" << cast<ConstantUInt>(*I)->getValue(); } |