1 //===-- iMemory.cpp - Implement Memory instructions --------------*- C++ -*--=//
3 // This file implements the various memory related classes defined in iMemory.h
5 //===----------------------------------------------------------------------===//
7 #include "llvm/iMemory.h"
8 #include "llvm/ConstPoolVals.h"
10 const Type *LoadInst::getIndexedType(const Type *Ptr,
11 const vector<ConstPoolVal*> &Idx) {
12 if (!Ptr->isPointerType()) return 0; // Type isn't a pointer type!
14 // Get the type pointed to...
15 Ptr = ((const PointerType*)Ptr)->getValueType();
17 if (Ptr->isStructType()) {
19 while (Ptr->isStructType()) {
20 if (Idx.size() == CurIDX) return 0; // Can't load a whole structure!
21 if (Idx[CurIDX]->getType() != Type::UByteTy) return 0; // Illegal idx
22 unsigned NextIdx = ((ConstPoolUInt*)Idx[CurIDX++])->getValue();
24 const StructType *ST = (const StructType *)Ptr;
25 Ptr = ST->getElementTypes()[NextIdx];
28 } else if (Ptr->isArrayType()) {
29 assert(0 && "Loading from arrays not implemented yet!");
31 return (Idx.size() == 0) ? Ptr : 0; // Load directly through ptr
36 LoadInst::LoadInst(Value *Ptr, const vector<ConstPoolVal*> &Idx,
37 const string &Name = "")
38 : Instruction(getIndexedType(Ptr->getType(), Idx), Load, Name) {
39 assert(getIndexedType(Ptr->getType(), Idx) && "Load operands invalid!");
40 assert(Ptr->getType()->isPointerType() && "Can't free nonpointer!");
41 Operands.reserve(1+Idx.size());
42 Operands.push_back(Use(Ptr, this));
44 for (unsigned i = 0, E = Idx.size(); i != E; ++i)
45 Operands.push_back(Use(Idx[i], this));