summaryrefslogtreecommitdiff
path: root/lib/Bytecode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-11-26 16:54:55 +0000
committerChris Lattner <sabre@nondot.org>2001-11-26 16:54:55 +0000
commitb2b12b4a627761a409dd312076a0310777a96eb8 (patch)
tree6e752f616cd24b837178b2075f47cc5532e7b066 /lib/Bytecode
parent6cdb0118e82196a8ff91b7bec71fb525fe947f8b (diff)
downloadllvm-b2b12b4a627761a409dd312076a0310777a96eb8.tar.gz
llvm-b2b12b4a627761a409dd312076a0310777a96eb8.tar.bz2
llvm-b2b12b4a627761a409dd312076a0310777a96eb8.tar.xz
Implement array indexing
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1337 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/InstructionReader.cpp73
1 files changed, 47 insertions, 26 deletions
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index d3b2bb0d09..c59d147c24 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -348,30 +348,44 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
case Instruction::Load:
case Instruction::GetElementPtr: {
- vector<ConstPoolVal*> Idx;
+ vector<Value*> Idx;
+ if (!isa<PointerType>(Raw.Ty)) return failure(true);
+ const CompositeType *TopTy =
+ dyn_cast<CompositeType>(cast<PointerType>(Raw.Ty)->getValueType());
+
switch (Raw.NumOperands) {
case 0: cerr << "Invalid load encountered!\n"; return failure(true);
case 1: break;
- case 2: V = getValue(Type::UByteTy, Raw.Arg2);
- if (!isa<ConstPoolVal>(V)) return failure(true);
- Idx.push_back(cast<ConstPoolVal>(V));
- break;
- case 3: V = getValue(Type::UByteTy, Raw.Arg2);
- if (!isa<ConstPoolVal>(V)) return failure(true);
- Idx.push_back(cast<ConstPoolVal>(V));
- V = getValue(Type::UByteTy, Raw.Arg3);
- if (!isa<ConstPoolVal>(V)) return failure(true);
- Idx.push_back(cast<ConstPoolVal>(V));
- break;
+ case 2:
+ if (!TopTy) return failure(true);
+ Idx.push_back(V = getValue(TopTy->getIndexType(), Raw.Arg2));
+ if (!V) return failure(true);
+ break;
+ case 3: {
+ if (!TopTy) return failure(true);
+ Idx.push_back(V = getValue(TopTy->getIndexType(), Raw.Arg2));
+ if (!V) return failure(true);
+
+ const Type *ETy = MemAccessInst::getIndexedType(Raw.Ty, Idx, true);
+ const CompositeType *ElTy = dyn_cast_or_null<CompositeType>(ETy);
+ if (!ElTy) return failure(true);
+
+ Idx.push_back(V = getValue(ElTy->getIndexType(), Raw.Arg3));
+ if (!V) return failure(true);
+ break;
+ }
default:
- V = getValue(Type::UByteTy, Raw.Arg2);
- if (!isa<ConstPoolVal>(V)) return failure(true);
- Idx.push_back(cast<ConstPoolVal>(V));
+ if (!TopTy) return failure(true);
+ Idx.push_back(V = getValue(TopTy->getIndexType(), Raw.Arg2));
+ if (!V) return failure(true);
+
vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0, E = args.size(); i != E; ++i) {
- V = getValue(Type::UByteTy, args[i]);
- if (!isa<ConstPoolVal>(V)) return failure(true);
- Idx.push_back(cast<ConstPoolVal>(V));
+ const Type *ETy = MemAccessInst::getIndexedType(Raw.Ty, Idx, true);
+ const CompositeType *ElTy = dyn_cast_or_null<CompositeType>(ETy);
+ if (!ElTy) return failure(true);
+ Idx.push_back(V = getValue(ElTy->getIndexType(), args[i]));
+ if (!V) return failure(true);
}
delete Raw.VarArgs;
break;
@@ -388,21 +402,28 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
return false;
}
case Instruction::Store: {
- vector<ConstPoolVal*> Idx;
+ vector<Value*> Idx;
+ if (!isa<PointerType>(Raw.Ty)) return failure(true);
+ const CompositeType *TopTy =
+ dyn_cast<CompositeType>(cast<PointerType>(Raw.Ty)->getValueType());
+
switch (Raw.NumOperands) {
case 0:
case 1: cerr << "Invalid store encountered!\n"; return failure(true);
case 2: break;
- case 3: V = getValue(Type::UByteTy, Raw.Arg3);
- if (!isa<ConstPoolVal>(V)) return failure(true);
- Idx.push_back(cast<ConstPoolVal>(V));
- break;
+ case 3:
+ if (!TopTy) return failure(true);
+ Idx.push_back(V = getValue(TopTy->getIndexType(), Raw.Arg3));
+ if (!V) return failure(true);
+ break;
default:
vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0, E = args.size(); i != E; ++i) {
- V = getValue(Type::UByteTy, args[i]);
- if (!isa<ConstPoolVal>(V)) return failure(true);
- Idx.push_back(cast<ConstPoolVal>(V));
+ const Type *ETy = MemAccessInst::getIndexedType(Raw.Ty, Idx, true);
+ const CompositeType *ElTy = dyn_cast_or_null<CompositeType>(ETy);
+ if (!ElTy) return failure(true);
+ Idx.push_back(V = getValue(ElTy->getIndexType(), args[i]));
+ if (!V) return failure(true);
}
delete Raw.VarArgs;
break;