blob: 84ad4c587ab1a6bf4ed8453861e225d13797f030 [file] [log] [blame]
Chris Lattner05950c32001-10-13 06:47:01 +00001//===- ReadInst.cpp - Code to read an instruction from bytecode -----------===//
Chris Lattner00950542001-06-06 20:29:01 +00002//
3// This file defines the mechanism to read an instruction from a bytecode
4// stream.
5//
6// Note that this library should be as fast as possible, reentrant, and
7// threadsafe!!
8//
Chris Lattner05950c32001-10-13 06:47:01 +00009//===----------------------------------------------------------------------===//
Chris Lattner00950542001-06-06 20:29:01 +000010
Chris Lattner7061dc52001-12-03 18:02:31 +000011#include "ReaderInternals.h"
Chris Lattner00950542001-06-06 20:29:01 +000012#include "llvm/iTerminators.h"
13#include "llvm/iMemory.h"
Chris Lattner7061dc52001-12-03 18:02:31 +000014#include "llvm/iPHINode.h"
15#include "llvm/iOther.h"
Chris Lattnercb7e2e22003-10-18 05:54:18 +000016#include "llvm/Module.h"
Chris Lattner00950542001-06-06 20:29:01 +000017
Chris Lattner6fcf5032003-10-09 20:45:42 +000018namespace {
19 struct RawInst { // The raw fields out of the bytecode stream...
20 unsigned NumOperands;
21 unsigned Opcode;
22 unsigned Type;
23
24 RawInst(const unsigned char *&Buf, const unsigned char *EndBuf,
25 std::vector<unsigned> &Args);
26 };
27}
Chris Lattner927b1852003-10-09 20:22:47 +000028
29
30
31RawInst::RawInst(const unsigned char *&Buf, const unsigned char *EndBuf,
32 std::vector<unsigned> &Args) {
Chris Lattner00950542001-06-06 20:29:01 +000033 unsigned Op, Typ;
Misha Brukmand554ebf2003-09-23 16:17:50 +000034 if (read(Buf, EndBuf, Op))
35 throw std::string("Error reading from buffer.");
Chris Lattner00950542001-06-06 20:29:01 +000036
Chris Lattner2b9f6002001-10-23 03:21:10 +000037 // bits Instruction format: Common to all formats
38 // --------------------------
39 // 01-00: Opcode type, fixed to 1.
40 // 07-02: Opcode
Chris Lattner927b1852003-10-09 20:22:47 +000041 Opcode = (Op >> 2) & 63;
42 Args.resize((Op >> 0) & 03);
Chris Lattner00950542001-06-06 20:29:01 +000043
Chris Lattner927b1852003-10-09 20:22:47 +000044 switch (Args.size()) {
Chris Lattner00950542001-06-06 20:29:01 +000045 case 1:
Chris Lattner2b9f6002001-10-23 03:21:10 +000046 // bits Instruction format:
47 // --------------------------
48 // 19-08: Resulting type plane
49 // 31-20: Operand #1 (if set to (2^12-1), then zero operands)
50 //
Chris Lattner927b1852003-10-09 20:22:47 +000051 Type = (Op >> 8) & 4095;
52 Args[0] = (Op >> 20) & 4095;
53 if (Args[0] == 4095) // Handle special encoding for 0 operands...
54 Args.resize(0);
Chris Lattner00950542001-06-06 20:29:01 +000055 break;
56 case 2:
Chris Lattner2b9f6002001-10-23 03:21:10 +000057 // bits Instruction format:
58 // --------------------------
59 // 15-08: Resulting type plane
60 // 23-16: Operand #1
61 // 31-24: Operand #2
62 //
Chris Lattner927b1852003-10-09 20:22:47 +000063 Type = (Op >> 8) & 255;
64 Args[0] = (Op >> 16) & 255;
65 Args[1] = (Op >> 24) & 255;
Chris Lattner00950542001-06-06 20:29:01 +000066 break;
67 case 3:
Chris Lattner2b9f6002001-10-23 03:21:10 +000068 // bits Instruction format:
69 // --------------------------
70 // 13-08: Resulting type plane
71 // 19-14: Operand #1
72 // 25-20: Operand #2
73 // 31-26: Operand #3
74 //
Chris Lattner927b1852003-10-09 20:22:47 +000075 Type = (Op >> 8) & 63;
76 Args[0] = (Op >> 14) & 63;
77 Args[1] = (Op >> 20) & 63;
78 Args[2] = (Op >> 26) & 63;
Chris Lattner00950542001-06-06 20:29:01 +000079 break;
80 case 0:
81 Buf -= 4; // Hrm, try this again...
Chris Lattner927b1852003-10-09 20:22:47 +000082 if (read_vbr(Buf, EndBuf, Opcode))
Misha Brukmand554ebf2003-09-23 16:17:50 +000083 throw std::string("Error reading from buffer.");
Chris Lattner927b1852003-10-09 20:22:47 +000084 Opcode >>= 2;
85 if (read_vbr(Buf, EndBuf, Type))
Misha Brukmand554ebf2003-09-23 16:17:50 +000086 throw std::string("Error reading from buffer.");
Chris Lattner00950542001-06-06 20:29:01 +000087
Chris Lattner927b1852003-10-09 20:22:47 +000088 unsigned NumOperands;
89 if (read_vbr(Buf, EndBuf, NumOperands))
90 throw std::string("Error reading from buffer.");
91 Args.resize(NumOperands);
92
93 if (NumOperands == 0)
Misha Brukmand554ebf2003-09-23 16:17:50 +000094 throw std::string("Zero-argument instruction found; this is invalid.");
Chris Lattner00950542001-06-06 20:29:01 +000095
Chris Lattner927b1852003-10-09 20:22:47 +000096 for (unsigned i = 0; i != NumOperands; ++i)
97 if (read_vbr(Buf, EndBuf, Args[i]))
98 throw std::string("Error reading from buffer");
99 if (align32(Buf, EndBuf))
Misha Brukmand554ebf2003-09-23 16:17:50 +0000100 throw std::string("Unaligned bytecode buffer.");
Chris Lattner00950542001-06-06 20:29:01 +0000101 break;
102 }
Chris Lattner00950542001-06-06 20:29:01 +0000103}
104
105
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000106void BytecodeParser::ParseInstruction(const unsigned char *&Buf,
107 const unsigned char *EndBuf,
108 std::vector<unsigned> &Args,
109 BasicBlock *BB) {
Chris Lattner6fcf5032003-10-09 20:45:42 +0000110 Args.clear();
Chris Lattner927b1852003-10-09 20:22:47 +0000111 RawInst RI(Buf, EndBuf, Args);
112 const Type *InstTy = getType(RI.Type);
Chris Lattner00950542001-06-06 20:29:01 +0000113
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000114 Instruction *Result = 0;
Chris Lattner927b1852003-10-09 20:22:47 +0000115 if (RI.Opcode >= Instruction::BinaryOpsBegin &&
116 RI.Opcode < Instruction::BinaryOpsEnd && Args.size() == 2)
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000117 Result = BinaryOperator::create((Instruction::BinaryOps)RI.Opcode,
118 getValue(RI.Type, Args[0]),
119 getValue(RI.Type, Args[1]));
Chris Lattner027dcc52001-07-08 21:10:27 +0000120
Chris Lattner927b1852003-10-09 20:22:47 +0000121 switch (RI.Opcode) {
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000122 default:
123 if (Result == 0) throw std::string("Illegal instruction read!");
124 break;
125 case Instruction::VAArg:
126 Result = new VAArgInst(getValue(RI.Type, Args[0]), getType(Args[1]));
127 break;
128 case Instruction::VANext:
129 if (!hasOldStyleVarargs) {
130 Result = new VANextInst(getValue(RI.Type, Args[0]), getType(Args[1]));
131 } else {
132 // In the old-style varargs scheme, this was the "va_arg" instruction.
133 // Emit emulation code now.
134 if (!usesOldStyleVarargs) {
135 usesOldStyleVarargs = true;
136 std::cerr << "WARNING: this bytecode file uses obsolete features. "
137 << "Disassemble and assemble to update it.\n";
138 }
139
140 Value *VAListPtr = getValue(RI.Type, Args[0]);
141 const Type *ArgTy = getType(Args[1]);
142
143 // First, load the valist...
144 Instruction *CurVAList = new LoadInst(VAListPtr, "");
145 BB->getInstList().push_back(CurVAList);
146
147 // Construct the vaarg
148 Result = new VAArgInst(CurVAList, ArgTy);
149
150 // Now we must advance the pointer and update it in memory.
151 Instruction *TheVANext = new VANextInst(CurVAList, ArgTy);
152 BB->getInstList().push_back(TheVANext);
153
154 BB->getInstList().push_back(new StoreInst(TheVANext, VAListPtr));
155 }
156
157 break;
Chris Lattner927b1852003-10-09 20:22:47 +0000158 case Instruction::Cast:
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000159 Result = new CastInst(getValue(RI.Type, Args[0]), getType(Args[1]));
160 break;
Chris Lattner027dcc52001-07-08 21:10:27 +0000161 case Instruction::PHINode: {
Chris Lattner927b1852003-10-09 20:22:47 +0000162 if (Args.size() == 0 || (Args.size() & 1))
Chris Lattner3483f542003-10-09 18:25:19 +0000163 throw std::string("Invalid phi node encountered!\n");
Chris Lattner927b1852003-10-09 20:22:47 +0000164
165 PHINode *PN = new PHINode(InstTy);
Chris Lattner4c523922003-10-09 22:46:58 +0000166 PN->op_reserve(Args.size());
Chris Lattner927b1852003-10-09 20:22:47 +0000167 for (unsigned i = 0, e = Args.size(); i != e; i += 2)
Chris Lattner35d2ca62003-10-09 22:39:30 +0000168 PN->addIncoming(getValue(RI.Type, Args[i]), getBasicBlock(Args[i+1]));
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000169 Result = PN;
170 break;
Chris Lattner027dcc52001-07-08 21:10:27 +0000171 }
172
173 case Instruction::Shl:
174 case Instruction::Shr:
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000175 Result = new ShiftInst((Instruction::OtherOps)RI.Opcode,
176 getValue(RI.Type, Args[0]),
177 getValue(Type::UByteTyID, Args[1]));
178 break;
Chris Lattner027dcc52001-07-08 21:10:27 +0000179 case Instruction::Ret:
Chris Lattner927b1852003-10-09 20:22:47 +0000180 if (Args.size() == 0)
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000181 Result = new ReturnInst();
Chris Lattner927b1852003-10-09 20:22:47 +0000182 else if (Args.size() == 1)
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000183 Result = new ReturnInst(getValue(RI.Type, Args[0]));
184 else
185 throw std::string("Unrecognized instruction!");
Chris Lattner027dcc52001-07-08 21:10:27 +0000186 break;
187
188 case Instruction::Br:
Chris Lattner927b1852003-10-09 20:22:47 +0000189 if (Args.size() == 1)
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000190 Result = new BranchInst(getBasicBlock(Args[0]));
Chris Lattner927b1852003-10-09 20:22:47 +0000191 else if (Args.size() == 3)
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000192 Result = new BranchInst(getBasicBlock(Args[0]), getBasicBlock(Args[1]),
193 getValue(Type::BoolTyID , Args[2]));
194 else
195 throw std::string("Invalid number of operands for a 'br' instruction!");
196 break;
Chris Lattner027dcc52001-07-08 21:10:27 +0000197 case Instruction::Switch: {
Chris Lattner927b1852003-10-09 20:22:47 +0000198 if (Args.size() & 1)
Chris Lattner3483f542003-10-09 18:25:19 +0000199 throw std::string("Switch statement with odd number of arguments!");
Chris Lattner00950542001-06-06 20:29:01 +0000200
Chris Lattner35d2ca62003-10-09 22:39:30 +0000201 SwitchInst *I = new SwitchInst(getValue(RI.Type, Args[0]),
Chris Lattner927b1852003-10-09 20:22:47 +0000202 getBasicBlock(Args[1]));
203 for (unsigned i = 2, e = Args.size(); i != e; i += 2)
Chris Lattner35d2ca62003-10-09 22:39:30 +0000204 I->addCase(cast<Constant>(getValue(RI.Type, Args[i])),
Chris Lattner927b1852003-10-09 20:22:47 +0000205 getBasicBlock(Args[i+1]));
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000206 Result = I;
207 break;
Chris Lattner027dcc52001-07-08 21:10:27 +0000208 }
209
210 case Instruction::Call: {
Chris Lattner927b1852003-10-09 20:22:47 +0000211 if (Args.size() == 0)
212 throw std::string("Invalid call instruction encountered!");
213
Chris Lattner35d2ca62003-10-09 22:39:30 +0000214 Value *F = getValue(RI.Type, Args[0]);
Chris Lattner00950542001-06-06 20:29:01 +0000215
Chris Lattner3483f542003-10-09 18:25:19 +0000216 // Check to make sure we have a pointer to function type
Chris Lattner5bea4112003-09-05 18:25:29 +0000217 const PointerType *PTy = dyn_cast<PointerType>(F->getType());
Chris Lattner3483f542003-10-09 18:25:19 +0000218 if (PTy == 0) throw std::string("Call to non function pointer value!");
Chris Lattner5bea4112003-09-05 18:25:29 +0000219 const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType());
Chris Lattner3483f542003-10-09 18:25:19 +0000220 if (FTy == 0) throw std::string("Call to non function pointer value!");
Chris Lattnere5a57ee2001-07-25 22:47:55 +0000221
Chris Lattner0d75d8d72003-03-06 16:32:25 +0000222 std::vector<Value *> Params;
Chris Lattner5bea4112003-09-05 18:25:29 +0000223 const FunctionType::ParamTypes &PL = FTy->getParamTypes();
Chris Lattner05950c32001-10-13 06:47:01 +0000224
Chris Lattner5bea4112003-09-05 18:25:29 +0000225 if (!FTy->isVarArg()) {
Chris Lattner2aac6bf2002-04-04 22:19:18 +0000226 FunctionType::ParamTypes::const_iterator It = PL.begin();
Chris Lattnere5a57ee2001-07-25 22:47:55 +0000227
Chris Lattner927b1852003-10-09 20:22:47 +0000228 for (unsigned i = 1, e = Args.size(); i != e; ++i) {
229 if (It == PL.end()) throw std::string("Invalid call instruction!");
230 Params.push_back(getValue(*It++, Args[i]));
Chris Lattnere5a57ee2001-07-25 22:47:55 +0000231 }
Chris Lattner3483f542003-10-09 18:25:19 +0000232 if (It != PL.end()) throw std::string("Invalid call instruction!");
Chris Lattnere5a57ee2001-07-25 22:47:55 +0000233 } else {
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000234 Args.erase(Args.begin(), Args.begin()+1+hasVarArgCallPadding);
Chris Lattnere5a57ee2001-07-25 22:47:55 +0000235
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000236 unsigned FirstVariableOperand;
237 if (!hasVarArgCallPadding) {
238 if (Args.size() < FTy->getNumParams())
239 throw std::string("Call instruction missing operands!");
240
241 // Read all of the fixed arguments
242 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
243 Params.push_back(getValue(FTy->getParamType(i), Args[i]));
244
245 FirstVariableOperand = FTy->getNumParams();
246 } else {
247 FirstVariableOperand = 0;
248 }
249
250 if ((Args.size()-FirstVariableOperand) & 1) // Must be pairs of type/value
Chris Lattner927b1852003-10-09 20:22:47 +0000251 throw std::string("Invalid call instruction!");
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000252
253 for (unsigned i = FirstVariableOperand, e = Args.size(); i != e; i += 2)
Chris Lattner35d2ca62003-10-09 22:39:30 +0000254 Params.push_back(getValue(Args[i], Args[i+1]));
Chris Lattner00950542001-06-06 20:29:01 +0000255 }
Chris Lattner00950542001-06-06 20:29:01 +0000256
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000257 Result = new CallInst(F, Params);
258 break;
Chris Lattner027dcc52001-07-08 21:10:27 +0000259 }
Chris Lattner05950c32001-10-13 06:47:01 +0000260 case Instruction::Invoke: {
Chris Lattner927b1852003-10-09 20:22:47 +0000261 if (Args.size() < 3) throw std::string("Invalid invoke instruction!");
Chris Lattner35d2ca62003-10-09 22:39:30 +0000262 Value *F = getValue(RI.Type, Args[0]);
Chris Lattner05950c32001-10-13 06:47:01 +0000263
Chris Lattner3483f542003-10-09 18:25:19 +0000264 // Check to make sure we have a pointer to function type
Chris Lattner5bea4112003-09-05 18:25:29 +0000265 const PointerType *PTy = dyn_cast<PointerType>(F->getType());
Chris Lattner3483f542003-10-09 18:25:19 +0000266 if (PTy == 0) throw std::string("Invoke to non function pointer value!");
Chris Lattner5bea4112003-09-05 18:25:29 +0000267 const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType());
Chris Lattner3483f542003-10-09 18:25:19 +0000268 if (FTy == 0) throw std::string("Invoke to non function pointer value!");
Chris Lattner05950c32001-10-13 06:47:01 +0000269
Chris Lattner0d75d8d72003-03-06 16:32:25 +0000270 std::vector<Value *> Params;
Chris Lattner05950c32001-10-13 06:47:01 +0000271 BasicBlock *Normal, *Except;
272
Chris Lattner927b1852003-10-09 20:22:47 +0000273 const FunctionType::ParamTypes &PL = FTy->getParamTypes();
274
Chris Lattner5bea4112003-09-05 18:25:29 +0000275 if (!FTy->isVarArg()) {
Chris Lattner927b1852003-10-09 20:22:47 +0000276 Normal = getBasicBlock(Args[1]);
277 Except = getBasicBlock(Args[2]);
Chris Lattner05950c32001-10-13 06:47:01 +0000278
Chris Lattner927b1852003-10-09 20:22:47 +0000279 FunctionType::ParamTypes::const_iterator It = PL.begin();
280 for (unsigned i = 3, e = Args.size(); i != e; ++i) {
281 if (It == PL.end()) throw std::string("Invalid invoke instruction!");
282 Params.push_back(getValue(*It++, Args[i]));
Chris Lattner05950c32001-10-13 06:47:01 +0000283 }
Chris Lattner927b1852003-10-09 20:22:47 +0000284 if (It != PL.end()) throw std::string("Invalid invoke instruction!");
Chris Lattner05950c32001-10-13 06:47:01 +0000285 } else {
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000286 Args.erase(Args.begin(), Args.begin()+1+hasVarArgCallPadding);
Chris Lattner927b1852003-10-09 20:22:47 +0000287
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000288 unsigned FirstVariableArgument;
289 if (!hasVarArgCallPadding) {
290 Normal = getBasicBlock(Args[0]);
291 Except = getBasicBlock(Args[1]);
292
293 FirstVariableArgument = FTy->getNumParams()+2;
294 for (unsigned i = 2; i != FirstVariableArgument; ++i)
295 Params.push_back(getValue(FTy->getParamType(i-2), Args[i]));
Chris Lattner4ee8ef22003-10-08 22:52:54 +0000296
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000297 } else {
298 if (Args.size() < 4) throw std::string("Invalid invoke instruction!");
299 if (Args[0] != Type::LabelTyID || Args[2] != Type::LabelTyID)
300 throw std::string("Invalid invoke instruction!");
301 Normal = getBasicBlock(Args[1]);
302 Except = getBasicBlock(Args[3]);
Chris Lattner05950c32001-10-13 06:47:01 +0000303
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000304 FirstVariableArgument = 4;
305 }
306
307 if (Args.size()-FirstVariableArgument & 1) // Must be pairs of type/value
Chris Lattner3483f542003-10-09 18:25:19 +0000308 throw std::string("Invalid invoke instruction!");
309
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000310 for (unsigned i = FirstVariableArgument; i < Args.size(); i += 2)
Chris Lattner927b1852003-10-09 20:22:47 +0000311 Params.push_back(getValue(Args[i], Args[i+1]));
Chris Lattner05950c32001-10-13 06:47:01 +0000312 }
313
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000314 Result = new InvokeInst(F, Normal, Except, Params);
315 break;
Chris Lattner05950c32001-10-13 06:47:01 +0000316 }
Chris Lattner027dcc52001-07-08 21:10:27 +0000317 case Instruction::Malloc:
Chris Lattner927b1852003-10-09 20:22:47 +0000318 if (Args.size() > 2) throw std::string("Invalid malloc instruction!");
319 if (!isa<PointerType>(InstTy))
Chris Lattner3483f542003-10-09 18:25:19 +0000320 throw std::string("Invalid malloc instruction!");
321
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000322 Result = new MallocInst(cast<PointerType>(InstTy)->getElementType(),
323 Args.size() ? getValue(Type::UIntTyID,
324 Args[0]) : 0);
325 break;
Chris Lattner027dcc52001-07-08 21:10:27 +0000326
327 case Instruction::Alloca:
Chris Lattner927b1852003-10-09 20:22:47 +0000328 if (Args.size() > 2) throw std::string("Invalid alloca instruction!");
329 if (!isa<PointerType>(InstTy))
Chris Lattner3483f542003-10-09 18:25:19 +0000330 throw std::string("Invalid alloca instruction!");
Chris Lattner027dcc52001-07-08 21:10:27 +0000331
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000332 Result = new AllocaInst(cast<PointerType>(InstTy)->getElementType(),
333 Args.size() ? getValue(Type::UIntTyID, Args[0]) :0);
334 break;
Chris Lattner027dcc52001-07-08 21:10:27 +0000335 case Instruction::Free:
Chris Lattner927b1852003-10-09 20:22:47 +0000336 if (!isa<PointerType>(InstTy))
Chris Lattner3483f542003-10-09 18:25:19 +0000337 throw std::string("Invalid free instruction!");
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000338 Result = new FreeInst(getValue(RI.Type, Args[0]));
339 break;
Chris Lattnerab5ac6b2001-07-08 23:22:50 +0000340 case Instruction::GetElementPtr: {
Chris Lattner927b1852003-10-09 20:22:47 +0000341 if (Args.size() == 0 || !isa<PointerType>(InstTy))
Chris Lattner3483f542003-10-09 18:25:19 +0000342 throw std::string("Invalid getelementptr instruction!");
Chris Lattnerb2b12b42001-11-26 16:54:55 +0000343
Chris Lattner927b1852003-10-09 20:22:47 +0000344 std::vector<Value*> Idx;
Chris Lattnerb2b12b42001-11-26 16:54:55 +0000345
Chris Lattner927b1852003-10-09 20:22:47 +0000346 const Type *NextTy = InstTy;
347 for (unsigned i = 1, e = Args.size(); i != e; ++i) {
348 const CompositeType *TopTy = dyn_cast_or_null<CompositeType>(NextTy);
349 if (!TopTy) throw std::string("Invalid getelementptr instruction!");
350 Idx.push_back(getValue(TopTy->getIndexType(), Args[i]));
351 NextTy = GetElementPtrInst::getIndexedType(InstTy, Idx, true);
Chris Lattner027dcc52001-07-08 21:10:27 +0000352 }
Chris Lattner77a316a2001-11-12 21:48:38 +0000353
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000354 Result = new GetElementPtrInst(getValue(RI.Type, Args[0]), Idx);
355 break;
Chris Lattnerab5ac6b2001-07-08 23:22:50 +0000356 }
Chris Lattner09bd0252003-09-08 18:04:16 +0000357
Chris Lattnerdba2b222003-09-08 18:20:14 +0000358 case 62: // volatile load
Chris Lattner09bd0252003-09-08 18:04:16 +0000359 case Instruction::Load:
Chris Lattner927b1852003-10-09 20:22:47 +0000360 if (Args.size() != 1 || !isa<PointerType>(InstTy))
Chris Lattner3483f542003-10-09 18:25:19 +0000361 throw std::string("Invalid load instruction!");
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000362 Result = new LoadInst(getValue(RI.Type, Args[0]), "", RI.Opcode == 62);
363 break;
Chris Lattnerb2b12b42001-11-26 16:54:55 +0000364
Chris Lattnerdba2b222003-09-08 18:20:14 +0000365 case 63: // volatile store
Chris Lattner09bd0252003-09-08 18:04:16 +0000366 case Instruction::Store: {
Chris Lattner927b1852003-10-09 20:22:47 +0000367 if (!isa<PointerType>(InstTy) || Args.size() != 2)
Chris Lattner3483f542003-10-09 18:25:19 +0000368 throw std::string("Invalid store instruction!");
Chris Lattnerab5ac6b2001-07-08 23:22:50 +0000369
Chris Lattner35d2ca62003-10-09 22:39:30 +0000370 Value *Ptr = getValue(RI.Type, Args[1]);
Chris Lattner352eef72002-08-21 22:55:27 +0000371 const Type *ValTy = cast<PointerType>(Ptr->getType())->getElementType();
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000372 Result = new StoreInst(getValue(ValTy, Args[0]), Ptr, RI.Opcode == 63);
373 break;
Chris Lattner00950542001-06-06 20:29:01 +0000374 }
Chris Lattner36143fc2003-09-08 18:54:55 +0000375 case Instruction::Unwind:
Chris Lattner927b1852003-10-09 20:22:47 +0000376 if (Args.size() != 0) throw std::string("Invalid unwind instruction!");
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000377 Result = new UnwindInst();
378 break;
Chris Lattner927b1852003-10-09 20:22:47 +0000379 } // end switch(RI.Opcode)
Chris Lattner00950542001-06-06 20:29:01 +0000380
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000381 insertValue(Result, Values);
382 BB->getInstList().push_back(Result);
383 BCR_TRACE(4, *Result);
Chris Lattner00950542001-06-06 20:29:01 +0000384}