return std::string((char*)OldAt, Size);
}
+void BytecodeReader::read_str(SmallVectorImpl<char> &StrData) {
+ StrData.clear();
+ unsigned Size = read_vbr_uint();
+ const unsigned char *OldAt = At;
+ At += Size;
+ if (At > BlockEnd) // Size invalid?
+ error("Ran out of data reading a string!");
+ StrData.append(OldAt, At);
+}
+
+
/// Read an arbitrary block of data
inline void BytecodeReader::read_data(void *Ptr, void *End) {
unsigned char *Start = (unsigned char *)Ptr;
break;
}
case Instruction::InsertElement: {
- const PackedType *PackedTy = dyn_cast<PackedType>(InstTy);
- if (!PackedTy || Oprnds.size() != 3)
+ const VectorType *VectorTy = dyn_cast<VectorType>(InstTy);
+ if (!VectorTy || Oprnds.size() != 3)
error("Invalid insertelement instruction!");
Value *V1 = getValue(iType, Oprnds[0]);
- Value *V2 = getValue(getTypeSlot(PackedTy->getElementType()),Oprnds[1]);
+ Value *V2 = getValue(getTypeSlot(VectorTy->getElementType()),Oprnds[1]);
Value *V3 = getValue(Int32TySlot, Oprnds[2]);
if (!InsertElementInst::isValidOperands(V1, V2, V3))
break;
}
case Instruction::ShuffleVector: {
- const PackedType *PackedTy = dyn_cast<PackedType>(InstTy);
- if (!PackedTy || Oprnds.size() != 3)
+ const VectorType *VectorTy = dyn_cast<VectorType>(InstTy);
+ if (!VectorTy || Oprnds.size() != 3)
error("Invalid shufflevector instruction!");
Value *V1 = getValue(iType, Oprnds[0]);
Value *V2 = getValue(iType, Oprnds[1]);
- const PackedType *EltTy =
- PackedType::get(Type::Int32Ty, PackedTy->getNumElements());
+ const VectorType *EltTy =
+ VectorType::get(Type::Int32Ty, VectorTy->getNumElements());
Value *V3 = getValue(getTypeSlot(EltTy), Oprnds[2]);
if (!ShuffleVectorInst::isValidOperands(V1, V2, V3))
error("Invalid shufflevector instruction!");
const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType());
if (FTy == 0) error("Call to non function pointer value!");
- std::vector<Value *> Params;
+ SmallVector<Value *, 8> Params;
if (!FTy->isVarArg()) {
FunctionType::param_iterator It = FTy->param_begin();
Params.push_back(getValue(Oprnds[i], Oprnds[i+1]));
}
- Result = new CallInst(F, Params);
+ Result = new CallInst(F, &Params[0], Params.size());
if (isTailCall) cast<CallInst>(Result)->setTailCall();
if (CallingConv) cast<CallInst>(Result)->setCallingConv(CallingConv);
break;
if (FTy == 0)
error("Invoke to non function pointer value!");
- std::vector<Value *> Params;
+ SmallVector<Value *, 8> Params;
BasicBlock *Normal, *Except;
unsigned CallingConv = Oprnds.back();
Oprnds.pop_back();
Params.push_back(getValue(Oprnds[i], Oprnds[i+1]));
}
- Result = new InvokeInst(F, Normal, Except, Params);
+ Result = new InvokeInst(F, Normal, Except, &Params[0], Params.size());
if (CallingConv) cast<InvokeInst>(Result)->setCallingConv(CallingConv);
break;
}
E = CurrentFunction->end(); I != E; ++I)
BBMap.push_back(I);
+ SmallVector<char, 32> NameStr;
+
while (moreInBlock()) {
// Symtab block header: [num entries][type id number]
unsigned NumEntries = read_vbr_uint();
for (unsigned i = 0; i != NumEntries; ++i) {
// Symtab entry: [def slot #][name]
unsigned slot = read_vbr_uint();
- std::string Name = read_str();
+ read_str(NameStr);
Value *V = 0;
if (Typ == LabelTySlot) {
- if (slot < BBMap.size())
- V = BBMap[slot];
+ V = (slot < BBMap.size()) ? BBMap[slot] : 0;
} else {
- V = getValue(Typ, slot, false); // Find mapping...
+ V = getValue(Typ, slot, false); // Find mapping.
}
- if (Handler) Handler->handleSymbolTableValue(Typ, slot, Name);
+ if (Handler) Handler->handleSymbolTableValue(Typ, slot,
+ &NameStr[0], NameStr.size());
if (V == 0)
- error("Failed value look-up for name '" + Name + "', type #" +
+ error("Failed value look-up for name '" +
+ std::string(NameStr.begin(), NameStr.end()) + "', type #" +
utostr(Typ) + " slot #" + utostr(slot));
- V->setName(Name);
+ V->setName(&NameStr[0], NameStr.size());
+
+ NameStr.clear();
}
}
checkPastBlockEnd("Symbol Table");
Result = ArrayType::get(ElementType, NumElements);
break;
}
- case Type::PackedTyID: {
+ case Type::VectorTyID: {
const Type *ElementType = readType();
unsigned NumElements = read_vbr_uint();
- Result = PackedType::get(ElementType, NumElements);
+ Result = VectorType::get(ElementType, NumElements);
break;
}
case Type::StructTyID: {
Result = ConstantInt::get(IT, Val);
if (Handler) Handler->handleConstantValue(Result);
} else
- assert("Integer types > 64 bits not supported");
+ assert(0 && "Integer types > 64 bits not supported");
break;
}
case Type::FloatTyID: {
break;
}
- case Type::PackedTyID: {
- const PackedType *PT = cast<PackedType>(Ty);
+ case Type::VectorTyID: {
+ const VectorType *PT = cast<VectorType>(Ty);
unsigned NumElements = PT->getNumElements();
unsigned TypeSlot = getTypeSlot(PT->getElementType());
std::vector<Constant*> Elements;
while (NumElements--) // Read all of the elements of the constant.
Elements.push_back(getConstantValue(TypeSlot,
read_vbr_uint()));
- Result = ConstantPacked::get(PT, Elements);
- if (Handler) Handler->handleConstantPacked(PT, &Elements[0],Elements.size(),
+ Result = ConstantVector::get(PT, Elements);
+ if (Handler) Handler->handleConstantVector(PT, &Elements[0],Elements.size(),
TypeSlot, Result);
break;
}
/// and \p Length parameters.
bool BytecodeReader::ParseBytecode(volatile BufPtr Buf, unsigned Length,
const std::string &ModuleID,
- Decompressor_t *Decompressor,
+ BCDecompressor_t *Decompressor,
std::string* ErrMsg) {
/// We handle errors by
// If this is a compressed file
if (Sig == ('l' | ('l' << 8) | ('v' << 16) | ('c' << 24))) {
+ if (!Decompressor) {
+ error("Compressed bytecode found, but not decompressor available");
+ }
// Invoke the decompression of the bytecode. Note that we have to skip the
// file's magic number which is not part of the compressed block. Hence,