2001-10-13 06:47:01 +00:00
|
|
|
//===- ReadInst.cpp - Code to read an instruction from bytecode -----------===//
|
2003-10-20 19:43:21 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
// This file defines the mechanism to read an instruction from a bytecode
|
|
|
|
// stream.
|
|
|
|
//
|
|
|
|
// Note that this library should be as fast as possible, reentrant, and
|
|
|
|
// threadsafe!!
|
|
|
|
//
|
2001-10-13 06:47:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-12-03 18:02:31 +00:00
|
|
|
#include "ReaderInternals.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/iTerminators.h"
|
|
|
|
#include "llvm/iMemory.h"
|
2001-12-03 18:02:31 +00:00
|
|
|
#include "llvm/iPHINode.h"
|
|
|
|
#include "llvm/iOther.h"
|
2003-10-18 05:54:18 +00:00
|
|
|
#include "llvm/Module.h"
|
2003-11-19 17:21:11 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2003-10-09 20:45:42 +00:00
|
|
|
namespace {
|
|
|
|
struct RawInst { // The raw fields out of the bytecode stream...
|
|
|
|
unsigned NumOperands;
|
|
|
|
unsigned Opcode;
|
|
|
|
unsigned Type;
|
|
|
|
|
|
|
|
RawInst(const unsigned char *&Buf, const unsigned char *EndBuf,
|
|
|
|
std::vector<unsigned> &Args);
|
|
|
|
};
|
|
|
|
}
|
2003-10-09 20:22:47 +00:00
|
|
|
|
|
|
|
RawInst::RawInst(const unsigned char *&Buf, const unsigned char *EndBuf,
|
|
|
|
std::vector<unsigned> &Args) {
|
2004-01-15 06:13:09 +00:00
|
|
|
unsigned Op = read(Buf, EndBuf);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-10-23 03:21:10 +00:00
|
|
|
// bits Instruction format: Common to all formats
|
|
|
|
// --------------------------
|
|
|
|
// 01-00: Opcode type, fixed to 1.
|
|
|
|
// 07-02: Opcode
|
2003-10-09 20:22:47 +00:00
|
|
|
Opcode = (Op >> 2) & 63;
|
|
|
|
Args.resize((Op >> 0) & 03);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-10-09 20:22:47 +00:00
|
|
|
switch (Args.size()) {
|
2001-06-06 20:29:01 +00:00
|
|
|
case 1:
|
2001-10-23 03:21:10 +00:00
|
|
|
// bits Instruction format:
|
|
|
|
// --------------------------
|
|
|
|
// 19-08: Resulting type plane
|
|
|
|
// 31-20: Operand #1 (if set to (2^12-1), then zero operands)
|
|
|
|
//
|
2003-10-09 20:22:47 +00:00
|
|
|
Type = (Op >> 8) & 4095;
|
|
|
|
Args[0] = (Op >> 20) & 4095;
|
|
|
|
if (Args[0] == 4095) // Handle special encoding for 0 operands...
|
|
|
|
Args.resize(0);
|
2001-06-06 20:29:01 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2001-10-23 03:21:10 +00:00
|
|
|
// bits Instruction format:
|
|
|
|
// --------------------------
|
|
|
|
// 15-08: Resulting type plane
|
|
|
|
// 23-16: Operand #1
|
|
|
|
// 31-24: Operand #2
|
|
|
|
//
|
2003-10-09 20:22:47 +00:00
|
|
|
Type = (Op >> 8) & 255;
|
|
|
|
Args[0] = (Op >> 16) & 255;
|
|
|
|
Args[1] = (Op >> 24) & 255;
|
2001-06-06 20:29:01 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2001-10-23 03:21:10 +00:00
|
|
|
// bits Instruction format:
|
|
|
|
// --------------------------
|
|
|
|
// 13-08: Resulting type plane
|
|
|
|
// 19-14: Operand #1
|
|
|
|
// 25-20: Operand #2
|
|
|
|
// 31-26: Operand #3
|
|
|
|
//
|
2003-10-09 20:22:47 +00:00
|
|
|
Type = (Op >> 8) & 63;
|
|
|
|
Args[0] = (Op >> 14) & 63;
|
|
|
|
Args[1] = (Op >> 20) & 63;
|
|
|
|
Args[2] = (Op >> 26) & 63;
|
2001-06-06 20:29:01 +00:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
Buf -= 4; // Hrm, try this again...
|
2004-01-15 06:13:09 +00:00
|
|
|
Opcode = read_vbr_uint(Buf, EndBuf);
|
2003-10-09 20:22:47 +00:00
|
|
|
Opcode >>= 2;
|
2004-01-15 06:13:09 +00:00
|
|
|
Type = read_vbr_uint(Buf, EndBuf);
|
2003-10-09 20:22:47 +00:00
|
|
|
|
2004-01-15 06:13:09 +00:00
|
|
|
unsigned NumOperands = read_vbr_uint(Buf, EndBuf);
|
2003-10-09 20:22:47 +00:00
|
|
|
Args.resize(NumOperands);
|
2003-09-23 16:17:50 +00:00
|
|
|
|
2003-10-09 20:22:47 +00:00
|
|
|
if (NumOperands == 0)
|
2003-09-23 16:17:50 +00:00
|
|
|
throw std::string("Zero-argument instruction found; this is invalid.");
|
|
|
|
|
2003-10-09 20:22:47 +00:00
|
|
|
for (unsigned i = 0; i != NumOperands; ++i)
|
2004-01-15 06:13:09 +00:00
|
|
|
Args[i] = read_vbr_uint(Buf, EndBuf);
|
|
|
|
align32(Buf, EndBuf);
|
2001-06-06 20:29:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
void BytecodeParser::ParseInstruction(const unsigned char *&Buf,
|
|
|
|
const unsigned char *EndBuf,
|
|
|
|
std::vector<unsigned> &Args,
|
|
|
|
BasicBlock *BB) {
|
2003-10-09 20:45:42 +00:00
|
|
|
Args.clear();
|
2003-10-09 20:22:47 +00:00
|
|
|
RawInst RI(Buf, EndBuf, Args);
|
|
|
|
const Type *InstTy = getType(RI.Type);
|
2003-09-23 16:17:50 +00:00
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
Instruction *Result = 0;
|
2003-10-09 20:22:47 +00:00
|
|
|
if (RI.Opcode >= Instruction::BinaryOpsBegin &&
|
|
|
|
RI.Opcode < Instruction::BinaryOpsEnd && Args.size() == 2)
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = BinaryOperator::create((Instruction::BinaryOps)RI.Opcode,
|
|
|
|
getValue(RI.Type, Args[0]),
|
|
|
|
getValue(RI.Type, Args[1]));
|
2001-07-08 21:10:27 +00:00
|
|
|
|
2003-10-09 20:22:47 +00:00
|
|
|
switch (RI.Opcode) {
|
2003-10-18 05:54:18 +00:00
|
|
|
default:
|
|
|
|
if (Result == 0) throw std::string("Illegal instruction read!");
|
|
|
|
break;
|
|
|
|
case Instruction::VAArg:
|
|
|
|
Result = new VAArgInst(getValue(RI.Type, Args[0]), getType(Args[1]));
|
|
|
|
break;
|
|
|
|
case Instruction::VANext:
|
2004-04-03 23:43:42 +00:00
|
|
|
Result = new VANextInst(getValue(RI.Type, Args[0]), getType(Args[1]));
|
2003-10-18 05:54:18 +00:00
|
|
|
break;
|
2003-10-09 20:22:47 +00:00
|
|
|
case Instruction::Cast:
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new CastInst(getValue(RI.Type, Args[0]), getType(Args[1]));
|
|
|
|
break;
|
2004-03-12 05:51:49 +00:00
|
|
|
case Instruction::Select:
|
|
|
|
Result = new SelectInst(getValue(Type::BoolTyID, Args[0]),
|
|
|
|
getValue(RI.Type, Args[1]),
|
|
|
|
getValue(RI.Type, Args[2]));
|
|
|
|
break;
|
2003-10-19 21:34:28 +00:00
|
|
|
case Instruction::PHI: {
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() == 0 || (Args.size() & 1))
|
2003-10-09 18:25:19 +00:00
|
|
|
throw std::string("Invalid phi node encountered!\n");
|
2003-10-09 20:22:47 +00:00
|
|
|
|
|
|
|
PHINode *PN = new PHINode(InstTy);
|
2003-10-09 22:46:58 +00:00
|
|
|
PN->op_reserve(Args.size());
|
2003-10-09 20:22:47 +00:00
|
|
|
for (unsigned i = 0, e = Args.size(); i != e; i += 2)
|
2003-10-09 22:39:30 +00:00
|
|
|
PN->addIncoming(getValue(RI.Type, Args[i]), getBasicBlock(Args[i+1]));
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = PN;
|
|
|
|
break;
|
2001-07-08 21:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case Instruction::Shl:
|
|
|
|
case Instruction::Shr:
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new ShiftInst((Instruction::OtherOps)RI.Opcode,
|
|
|
|
getValue(RI.Type, Args[0]),
|
|
|
|
getValue(Type::UByteTyID, Args[1]));
|
|
|
|
break;
|
2001-07-08 21:10:27 +00:00
|
|
|
case Instruction::Ret:
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() == 0)
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new ReturnInst();
|
2003-10-09 20:22:47 +00:00
|
|
|
else if (Args.size() == 1)
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new ReturnInst(getValue(RI.Type, Args[0]));
|
|
|
|
else
|
|
|
|
throw std::string("Unrecognized instruction!");
|
2001-07-08 21:10:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Instruction::Br:
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() == 1)
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new BranchInst(getBasicBlock(Args[0]));
|
2003-10-09 20:22:47 +00:00
|
|
|
else if (Args.size() == 3)
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new BranchInst(getBasicBlock(Args[0]), getBasicBlock(Args[1]),
|
|
|
|
getValue(Type::BoolTyID , Args[2]));
|
|
|
|
else
|
|
|
|
throw std::string("Invalid number of operands for a 'br' instruction!");
|
|
|
|
break;
|
2001-07-08 21:10:27 +00:00
|
|
|
case Instruction::Switch: {
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() & 1)
|
2003-10-09 18:25:19 +00:00
|
|
|
throw std::string("Switch statement with odd number of arguments!");
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-10-09 22:39:30 +00:00
|
|
|
SwitchInst *I = new SwitchInst(getValue(RI.Type, Args[0]),
|
2003-10-09 20:22:47 +00:00
|
|
|
getBasicBlock(Args[1]));
|
|
|
|
for (unsigned i = 2, e = Args.size(); i != e; i += 2)
|
2003-10-09 22:39:30 +00:00
|
|
|
I->addCase(cast<Constant>(getValue(RI.Type, Args[i])),
|
2003-10-09 20:22:47 +00:00
|
|
|
getBasicBlock(Args[i+1]));
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = I;
|
|
|
|
break;
|
2001-07-08 21:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case Instruction::Call: {
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() == 0)
|
|
|
|
throw std::string("Invalid call instruction encountered!");
|
|
|
|
|
2003-10-09 22:39:30 +00:00
|
|
|
Value *F = getValue(RI.Type, Args[0]);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-10-09 18:25:19 +00:00
|
|
|
// Check to make sure we have a pointer to function type
|
2003-09-05 18:25:29 +00:00
|
|
|
const PointerType *PTy = dyn_cast<PointerType>(F->getType());
|
2003-10-09 18:25:19 +00:00
|
|
|
if (PTy == 0) throw std::string("Call to non function pointer value!");
|
2003-09-05 18:25:29 +00:00
|
|
|
const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType());
|
2003-10-09 18:25:19 +00:00
|
|
|
if (FTy == 0) throw std::string("Call to non function pointer value!");
|
2001-10-13 06:47:01 +00:00
|
|
|
|
2003-03-06 16:32:25 +00:00
|
|
|
std::vector<Value *> Params;
|
2003-09-05 18:25:29 +00:00
|
|
|
if (!FTy->isVarArg()) {
|
2004-02-09 04:14:01 +00:00
|
|
|
FunctionType::param_iterator It = FTy->param_begin();
|
2001-07-25 22:47:55 +00:00
|
|
|
|
2003-10-09 20:22:47 +00:00
|
|
|
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
|
2004-02-09 04:14:01 +00:00
|
|
|
if (It == FTy->param_end())
|
|
|
|
throw std::string("Invalid call instruction!");
|
2003-11-19 17:21:11 +00:00
|
|
|
Params.push_back(getValue(getTypeSlot(*It++), Args[i]));
|
2001-07-25 22:47:55 +00:00
|
|
|
}
|
2004-02-09 04:14:01 +00:00
|
|
|
if (It != FTy->param_end())
|
|
|
|
throw std::string("Invalid call instruction!");
|
2001-07-25 22:47:55 +00:00
|
|
|
} else {
|
2004-04-03 23:43:42 +00:00
|
|
|
Args.erase(Args.begin(), Args.begin()+1);
|
2003-10-09 20:22:47 +00:00
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
unsigned FirstVariableOperand;
|
2004-04-03 23:43:42 +00:00
|
|
|
if (Args.size() < FTy->getNumParams())
|
|
|
|
throw std::string("Call instruction missing operands!");
|
2003-10-09 20:22:47 +00:00
|
|
|
|
2004-04-03 23:43:42 +00:00
|
|
|
// Read all of the fixed arguments
|
|
|
|
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
|
|
|
|
Params.push_back(getValue(getTypeSlot(FTy->getParamType(i)),Args[i]));
|
|
|
|
|
|
|
|
FirstVariableOperand = FTy->getNumParams();
|
2003-10-18 05:54:18 +00:00
|
|
|
|
|
|
|
if ((Args.size()-FirstVariableOperand) & 1) // Must be pairs of type/value
|
|
|
|
throw std::string("Invalid call instruction!");
|
|
|
|
|
|
|
|
for (unsigned i = FirstVariableOperand, e = Args.size(); i != e; i += 2)
|
2003-10-09 22:39:30 +00:00
|
|
|
Params.push_back(getValue(Args[i], Args[i+1]));
|
2001-10-13 06:47:01 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new CallInst(F, Params);
|
|
|
|
break;
|
2001-10-13 06:47:01 +00:00
|
|
|
}
|
|
|
|
case Instruction::Invoke: {
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() < 3) throw std::string("Invalid invoke instruction!");
|
2003-10-09 22:39:30 +00:00
|
|
|
Value *F = getValue(RI.Type, Args[0]);
|
2001-10-13 06:47:01 +00:00
|
|
|
|
2003-10-09 18:25:19 +00:00
|
|
|
// Check to make sure we have a pointer to function type
|
2003-09-05 18:25:29 +00:00
|
|
|
const PointerType *PTy = dyn_cast<PointerType>(F->getType());
|
2003-10-09 18:25:19 +00:00
|
|
|
if (PTy == 0) throw std::string("Invoke to non function pointer value!");
|
2003-09-05 18:25:29 +00:00
|
|
|
const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType());
|
2003-10-09 18:25:19 +00:00
|
|
|
if (FTy == 0) throw std::string("Invoke to non function pointer value!");
|
2001-10-13 06:47:01 +00:00
|
|
|
|
2003-03-06 16:32:25 +00:00
|
|
|
std::vector<Value *> Params;
|
2001-10-13 06:47:01 +00:00
|
|
|
BasicBlock *Normal, *Except;
|
|
|
|
|
2003-09-05 18:25:29 +00:00
|
|
|
if (!FTy->isVarArg()) {
|
2003-10-09 20:22:47 +00:00
|
|
|
Normal = getBasicBlock(Args[1]);
|
|
|
|
Except = getBasicBlock(Args[2]);
|
|
|
|
|
2004-02-09 04:14:01 +00:00
|
|
|
FunctionType::param_iterator It = FTy->param_begin();
|
2003-10-09 20:22:47 +00:00
|
|
|
for (unsigned i = 3, e = Args.size(); i != e; ++i) {
|
2004-02-09 04:14:01 +00:00
|
|
|
if (It == FTy->param_end())
|
|
|
|
throw std::string("Invalid invoke instruction!");
|
2003-11-19 17:21:11 +00:00
|
|
|
Params.push_back(getValue(getTypeSlot(*It++), Args[i]));
|
2001-10-13 06:47:01 +00:00
|
|
|
}
|
2004-02-09 04:14:01 +00:00
|
|
|
if (It != FTy->param_end())
|
|
|
|
throw std::string("Invalid invoke instruction!");
|
2001-10-13 06:47:01 +00:00
|
|
|
} else {
|
2004-04-03 23:43:42 +00:00
|
|
|
Args.erase(Args.begin(), Args.begin()+1);
|
2001-07-25 22:47:55 +00:00
|
|
|
|
2004-04-03 23:43:42 +00:00
|
|
|
Normal = getBasicBlock(Args[0]);
|
|
|
|
Except = getBasicBlock(Args[1]);
|
|
|
|
|
|
|
|
unsigned FirstVariableArgument = FTy->getNumParams()+2;
|
|
|
|
for (unsigned i = 2; i != FirstVariableArgument; ++i)
|
|
|
|
Params.push_back(getValue(getTypeSlot(FTy->getParamType(i-2)),
|
|
|
|
Args[i]));
|
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
if (Args.size()-FirstVariableArgument & 1) // Must be pairs of type/value
|
2003-10-09 18:25:19 +00:00
|
|
|
throw std::string("Invalid invoke instruction!");
|
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
for (unsigned i = FirstVariableArgument; i < Args.size(); i += 2)
|
2003-10-09 20:22:47 +00:00
|
|
|
Params.push_back(getValue(Args[i], Args[i+1]));
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new InvokeInst(F, Normal, Except, Params);
|
|
|
|
break;
|
2001-07-08 21:10:27 +00:00
|
|
|
}
|
|
|
|
case Instruction::Malloc:
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() > 2) throw std::string("Invalid malloc instruction!");
|
|
|
|
if (!isa<PointerType>(InstTy))
|
2003-10-09 18:25:19 +00:00
|
|
|
throw std::string("Invalid malloc instruction!");
|
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new MallocInst(cast<PointerType>(InstTy)->getElementType(),
|
|
|
|
Args.size() ? getValue(Type::UIntTyID,
|
|
|
|
Args[0]) : 0);
|
|
|
|
break;
|
2001-07-08 21:10:27 +00:00
|
|
|
|
|
|
|
case Instruction::Alloca:
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() > 2) throw std::string("Invalid alloca instruction!");
|
|
|
|
if (!isa<PointerType>(InstTy))
|
2003-10-09 18:25:19 +00:00
|
|
|
throw std::string("Invalid alloca instruction!");
|
2001-07-08 21:10:27 +00:00
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new AllocaInst(cast<PointerType>(InstTy)->getElementType(),
|
|
|
|
Args.size() ? getValue(Type::UIntTyID, Args[0]) :0);
|
|
|
|
break;
|
2001-07-08 21:10:27 +00:00
|
|
|
case Instruction::Free:
|
2003-10-09 20:22:47 +00:00
|
|
|
if (!isa<PointerType>(InstTy))
|
2003-10-09 18:25:19 +00:00
|
|
|
throw std::string("Invalid free instruction!");
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new FreeInst(getValue(RI.Type, Args[0]));
|
|
|
|
break;
|
2001-07-08 23:22:50 +00:00
|
|
|
case Instruction::GetElementPtr: {
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() == 0 || !isa<PointerType>(InstTy))
|
2003-10-09 18:25:19 +00:00
|
|
|
throw std::string("Invalid getelementptr instruction!");
|
2003-10-09 20:22:47 +00:00
|
|
|
|
|
|
|
std::vector<Value*> Idx;
|
|
|
|
|
|
|
|
const Type *NextTy = InstTy;
|
|
|
|
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
|
|
|
|
const CompositeType *TopTy = dyn_cast_or_null<CompositeType>(NextTy);
|
|
|
|
if (!TopTy) throw std::string("Invalid getelementptr instruction!");
|
2004-04-05 01:27:26 +00:00
|
|
|
|
|
|
|
unsigned ValIdx = Args[i];
|
|
|
|
unsigned IdxTy;
|
|
|
|
if (!hasRestrictedGEPTypes) {
|
|
|
|
// Struct indices are always uints, sequential type indices can be any
|
|
|
|
// of the 32 or 64-bit integer types. The actual choice of type is
|
|
|
|
// encoded in the low two bits of the slot number.
|
|
|
|
if (isa<StructType>(TopTy))
|
|
|
|
IdxTy = Type::UIntTyID;
|
|
|
|
else {
|
|
|
|
switch (ValIdx & 3) {
|
|
|
|
case 0: IdxTy = Type::UIntTyID; break;
|
|
|
|
case 1: IdxTy = Type::IntTyID; break;
|
|
|
|
case 2: IdxTy = Type::ULongTyID; break;
|
|
|
|
case 3: IdxTy = Type::LongTyID; break;
|
|
|
|
}
|
|
|
|
ValIdx >>= 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
IdxTy = isa<StructType>(TopTy) ? Type::UByteTyID : Type::LongTyID;
|
|
|
|
}
|
|
|
|
|
|
|
|
Idx.push_back(getValue(IdxTy, ValIdx));
|
|
|
|
|
|
|
|
// Convert ubyte struct indices into uint struct indices.
|
|
|
|
if (isa<StructType>(TopTy) && hasRestrictedGEPTypes)
|
|
|
|
if (ConstantUInt *C = dyn_cast<ConstantUInt>(Idx.back()))
|
|
|
|
Idx[Idx.size()-1] = ConstantExpr::getCast(C, Type::UIntTy);
|
|
|
|
|
2003-10-09 20:22:47 +00:00
|
|
|
NextTy = GetElementPtrInst::getIndexedType(InstTy, Idx, true);
|
2001-07-08 21:10:27 +00:00
|
|
|
}
|
2001-11-12 21:48:38 +00:00
|
|
|
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new GetElementPtrInst(getValue(RI.Type, Args[0]), Idx);
|
|
|
|
break;
|
2001-07-08 23:22:50 +00:00
|
|
|
}
|
2001-11-26 16:54:55 +00:00
|
|
|
|
2003-09-08 18:20:14 +00:00
|
|
|
case 62: // volatile load
|
2003-09-08 18:04:16 +00:00
|
|
|
case Instruction::Load:
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() != 1 || !isa<PointerType>(InstTy))
|
2003-10-09 18:25:19 +00:00
|
|
|
throw std::string("Invalid load instruction!");
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new LoadInst(getValue(RI.Type, Args[0]), "", RI.Opcode == 62);
|
|
|
|
break;
|
2001-12-14 16:30:09 +00:00
|
|
|
|
2003-09-08 18:20:14 +00:00
|
|
|
case 63: // volatile store
|
2003-09-08 18:04:16 +00:00
|
|
|
case Instruction::Store: {
|
2003-10-09 20:22:47 +00:00
|
|
|
if (!isa<PointerType>(InstTy) || Args.size() != 2)
|
2003-10-09 18:25:19 +00:00
|
|
|
throw std::string("Invalid store instruction!");
|
2001-07-08 23:22:50 +00:00
|
|
|
|
2003-10-09 22:39:30 +00:00
|
|
|
Value *Ptr = getValue(RI.Type, Args[1]);
|
2002-08-21 22:55:27 +00:00
|
|
|
const Type *ValTy = cast<PointerType>(Ptr->getType())->getElementType();
|
2003-11-19 17:21:11 +00:00
|
|
|
Result = new StoreInst(getValue(getTypeSlot(ValTy), Args[0]), Ptr,
|
|
|
|
RI.Opcode == 63);
|
2003-10-18 05:54:18 +00:00
|
|
|
break;
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
2003-09-08 18:54:55 +00:00
|
|
|
case Instruction::Unwind:
|
2003-10-09 20:22:47 +00:00
|
|
|
if (Args.size() != 0) throw std::string("Invalid unwind instruction!");
|
2003-10-18 05:54:18 +00:00
|
|
|
Result = new UnwindInst();
|
|
|
|
break;
|
2003-10-09 20:22:47 +00:00
|
|
|
} // end switch(RI.Opcode)
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-11-19 17:21:11 +00:00
|
|
|
unsigned TypeSlot;
|
|
|
|
if (Result->getType() == InstTy)
|
|
|
|
TypeSlot = RI.Type;
|
|
|
|
else
|
|
|
|
TypeSlot = getTypeSlot(Result->getType());
|
|
|
|
|
|
|
|
insertValue(Result, TypeSlot, Values);
|
2003-10-18 05:54:18 +00:00
|
|
|
BB->getInstList().push_back(Result);
|
|
|
|
BCR_TRACE(4, *Result);
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|