diff options
author | Chris Lattner <sabre@nondot.org> | 2004-04-05 01:27:26 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-04-05 01:27:26 +0000 |
commit | 5fa428fda9eb0f333311eca20b9f08fef975a8c0 (patch) | |
tree | ccab09d06a0ebfcecfaa658b31360d9fb63903b0 /lib/Bytecode/Reader/ConstantReader.cpp | |
parent | 68056127bb76a28713f829d92b309c2b1960ffc2 (diff) |
Implement support for a new LLVM 1.3 bytecode format, which uses uint's
to index into structure types and allows arbitrary 32- and 64-bit integer
types to index into sequential types.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12651 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader/ConstantReader.cpp')
-rw-r--r-- | lib/Bytecode/Reader/ConstantReader.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index b4a219df6b..8691b26544 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -15,6 +15,7 @@ #include "ReaderInternals.h" #include "llvm/Module.h" #include "llvm/Constants.h" +#include "llvm/Support/GetElementPtrTypeIterator.h" #include <algorithm> using namespace llvm; @@ -164,6 +165,20 @@ Constant *BytecodeParser::parseConstantValue(const unsigned char *&Buf, return ConstantExpr::getCast(ArgVec[0], getType(TypeID)); } else if (Opcode == Instruction::GetElementPtr) { // GetElementPtr std::vector<Constant*> IdxList(ArgVec.begin()+1, ArgVec.end()); + + if (hasRestrictedGEPTypes) { + const Type *BaseTy = ArgVec[0]->getType(); + generic_gep_type_iterator<std::vector<Constant*>::iterator> + GTI = gep_type_begin(BaseTy, IdxList.begin(), IdxList.end()), + E = gep_type_end(BaseTy, IdxList.begin(), IdxList.end()); + for (unsigned i = 0; GTI != E; ++GTI, ++i) + if (isa<StructType>(*GTI)) { + if (IdxList[i]->getType() != Type::UByteTy) + throw std::string("Invalid index for getelementptr!"); + IdxList[i] = ConstantExpr::getCast(IdxList[i], Type::UIntTy); + } + } + return ConstantExpr::getGetElementPtr(ArgVec[0], IdxList); } else if (Opcode == Instruction::Select) { assert(ArgVec.size() == 3); |