diff options
author | Chris Lattner <sabre@nondot.org> | 2002-05-07 20:00:33 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-05-07 20:00:33 +0000 |
commit | a163fdfc80e46ad93afe2fab5bd1d99a550c3868 (patch) | |
tree | a1d5b3f0f91fcdc07658297e9262c07b192f3bfc /lib/Target/TargetData.cpp | |
parent | 3bcf74e298c325f73f35efc9d8916e6ddd9ba137 (diff) |
Extend TargetData::getIndexedOffset to support arrays and pointers!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2535 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetData.cpp')
-rw-r--r-- | lib/Target/TargetData.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 0df95209b5..85c9e683da 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -145,16 +145,12 @@ unsigned char TargetData::getTypeAlignment(const Type *Ty) const { return Align; } -unsigned TargetData::getIndexedOffset(const Type *ptrTy, +unsigned TargetData::getIndexedOffset(const Type *Ty, const std::vector<Value*> &Idx) const { - const PointerType *PtrTy = cast<const PointerType>(ptrTy); unsigned Result = 0; - // Get the type pointed to... - const Type *Ty = PtrTy->getElementType(); - - for (unsigned CurIDX = 0; CurIDX < Idx.size(); ++CurIDX) { - if (const StructType *STy = dyn_cast<const StructType>(Ty)) { + for (unsigned CurIDX = 0, E = Idx.size(); CurIDX != E; ++CurIDX) { + if (const StructType *STy = dyn_cast<StructType>(Ty)) { assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx"); unsigned FieldNo = cast<ConstantUInt>(Idx[CurIDX])->getValue(); @@ -168,10 +164,17 @@ unsigned TargetData::getIndexedOffset(const Type *ptrTy, // Update Ty to refer to current element Ty = STy->getElementTypes()[FieldNo]; - } else if (isa<const ArrayType>(Ty)) { - assert(0 && "Loading from arrays not implemented yet!"); + } else if (const SequentialType *STy = dyn_cast<SequentialType>(Ty)) { + assert(Idx[CurIDX]->getType() == Type::UIntTy &&"Illegal sequential idx"); + assert(isa<ConstantUInt>(Idx[CurIDX]) && + "getIndexedOffset cannot compute offset of non-constant index!"); + + unsigned IndexNo = cast<ConstantUInt>(Idx[CurIDX])->getValue(); + Ty = STy->getElementType(); + + Result += IndexNo*getTypeSize(Ty); } else { - assert(0 && "Indexing type that is not struct or array?"); + assert(0 && "Indexing type that is not struct, array, or pointer?"); return 0; // Load directly through ptr } } |