summaryrefslogtreecommitdiff
path: root/lib/Bytecode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-12-14 16:30:09 +0000
committerChris Lattner <sabre@nondot.org>2001-12-14 16:30:09 +0000
commitb024ef5e62a23f8701dc757ea49e7b8080c3725a (patch)
tree7f419e1bef36f4e14b4cd84df175433ae99dc833 /lib/Bytecode
parentf7a551fd929a4a849883cde04cfe54e0590a38b7 (diff)
downloadllvm-b024ef5e62a23f8701dc757ea49e7b8080c3725a.tar.gz
llvm-b024ef5e62a23f8701dc757ea49e7b8080c3725a.tar.bz2
llvm-b024ef5e62a23f8701dc757ea49e7b8080c3725a.tar.xz
Add pointer indexing support
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1460 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/InstructionReader.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index 47d9e820e2..b498ac90c1 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -350,8 +350,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
case Instruction::GetElementPtr: {
vector<Value*> Idx;
if (!isa<PointerType>(Raw.Ty)) return failure(true);
- const CompositeType *TopTy =
- dyn_cast<CompositeType>(cast<PointerType>(Raw.Ty)->getElementType());
+ const CompositeType *TopTy = dyn_cast<CompositeType>(Raw.Ty);
switch (Raw.NumOperands) {
case 0: cerr << "Invalid load encountered!\n"; return failure(true);
@@ -366,7 +365,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
Idx.push_back(V = getValue(TopTy->getIndexType(), Raw.Arg2));
if (!V) return failure(true);
- const Type *ETy = MemAccessInst::getIndexedType(Raw.Ty, Idx, true);
+ const Type *ETy = MemAccessInst::getIndexedType(TopTy, Idx, true);
const CompositeType *ElTy = dyn_cast_or_null<CompositeType>(ETy);
if (!ElTy) return failure(true);
@@ -404,8 +403,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
case Instruction::Store: {
vector<Value*> Idx;
if (!isa<PointerType>(Raw.Ty)) return failure(true);
- const CompositeType *TopTy =
- dyn_cast<CompositeType>(cast<PointerType>(Raw.Ty)->getElementType());
+ const CompositeType *TopTy = dyn_cast<CompositeType>(Raw.Ty);
switch (Raw.NumOperands) {
case 0:
@@ -418,13 +416,18 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
break;
default:
vector<unsigned> &args = *Raw.VarArgs;
- for (unsigned i = 0, E = args.size(); i != E; ++i) {
- const Type *ETy = MemAccessInst::getIndexedType(Raw.Ty, Idx, true);
- const CompositeType *ElTy = dyn_cast_or_null<CompositeType>(ETy);
- if (!ElTy) return failure(true);
+ const CompositeType *ElTy = TopTy;
+ unsigned i, E;
+ for (i = 0, E = args.size(); ElTy && i != E; ++i) {
Idx.push_back(V = getValue(ElTy->getIndexType(), args[i]));
if (!V) return failure(true);
+
+ const Type *ETy = MemAccessInst::getIndexedType(Raw.Ty, Idx, true);
+ ElTy = dyn_cast_or_null<CompositeType>(ETy);
}
+ if (i != E)
+ return failure(true); // didn't use up all of the indices!
+
delete Raw.VarArgs;
break;
}