diff options
Diffstat (limited to 'lib/Bytecode')
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 24 | ||||
-rw-r--r-- | lib/Bytecode/Writer/Writer.cpp | 12 |
2 files changed, 17 insertions, 19 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index ac6418d7a7..c7e99d0c94 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -1010,8 +1010,9 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, // 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); + if (ConstantInt *C = dyn_cast<ConstantInt>(Idx.back())) + if (C->getType() == Type::UByteTy) + Idx[Idx.size()-1] = ConstantExpr::getCast(C, Type::UIntTy); NextTy = GetElementPtrInst::getIndexedType(InstTy, Idx, true); } @@ -1549,15 +1550,15 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) { case Type::UShortTyID: case Type::UIntTyID: { unsigned Val = read_vbr_uint(); - if (!ConstantUInt::isValueValidForType(Ty, Val)) + if (!ConstantInt::isValueValidForType(Ty, uint64_t(Val))) error("Invalid unsigned byte/short/int read."); - Result = ConstantUInt::get(Ty, Val); + Result = ConstantInt::get(Ty, Val); if (Handler) Handler->handleConstantValue(Result); break; } case Type::ULongTyID: - Result = ConstantUInt::get(Ty, read_vbr_uint64()); + Result = ConstantInt::get(Ty, read_vbr_uint64()); if (Handler) Handler->handleConstantValue(Result); break; @@ -1566,9 +1567,9 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) { case Type::IntTyID: case Type::LongTyID: { int64_t Val = read_vbr_int64(); - if (!ConstantSInt::isValueValidForType(Ty, Val)) + if (!ConstantInt::isValueValidForType(Ty, Val)) error("Invalid signed byte/short/int/long read."); - Result = ConstantSInt::get(Ty, Val); + Result = ConstantInt::get(Ty, Val); if (Handler) Handler->handleConstantValue(Result); break; } @@ -1699,12 +1700,9 @@ void BytecodeReader::ParseStringConstants(unsigned NumEntries, ValueTable &Tab){ read_data(Data, Data+ATy->getNumElements()); std::vector<Constant*> Elements(ATy->getNumElements()); - if (ATy->getElementType() == Type::SByteTy) - for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) - Elements[i] = ConstantSInt::get(Type::SByteTy, (signed char)Data[i]); - else - for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) - Elements[i] = ConstantUInt::get(Type::UByteTy, (unsigned char)Data[i]); + const Type* ElemType = ATy->getElementType(); + for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) + Elements[i] = ConstantInt::get(ElemType, (unsigned char)Data[i]); // Create the constant, inserting it as needed. Constant *C = ConstantArray::get(ATy, Elements); diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index 48cccda8f4..d5c4840c00 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -293,7 +293,7 @@ void BytecodeWriter::outputConstant(const Constant *CPV) { assert(CE->getNumOperands() > 0 && "ConstantExpr with 0 operands"); assert(CE->getNumOperands() != 1 || CE->getOpcode() == Instruction::Cast); output_vbr(1+CE->getNumOperands()); // flags as an expr - output_vbr(CE->getOpcode()); // flags as an expr + output_vbr(CE->getOpcode()); // Put out the CE op code for (User::const_op_iterator OI = CE->op_begin(); OI != CE->op_end(); ++OI){ int Slot = Table.getSlot(*OI); @@ -307,7 +307,7 @@ void BytecodeWriter::outputConstant(const Constant *CPV) { output_vbr(1U); // 1 -> UndefValue constant. return; } else { - output_vbr(0U); // flag as not a ConstantExpr + output_vbr(0U); // flag as not a ConstantExpr (i.e. 0 operands) } switch (CPV->getType()->getTypeID()) { @@ -322,14 +322,14 @@ void BytecodeWriter::outputConstant(const Constant *CPV) { case Type::UShortTyID: case Type::UIntTyID: case Type::ULongTyID: - output_vbr(cast<ConstantUInt>(CPV)->getValue()); + output_vbr(cast<ConstantInt>(CPV)->getZExtValue()); break; case Type::SByteTyID: // Signed integer types... case Type::ShortTyID: case Type::IntTyID: case Type::LongTyID: - output_vbr(cast<ConstantSInt>(CPV)->getValue()); + output_vbr(cast<ConstantInt>(CPV)->getSExtValue()); break; case Type::ArrayTyID: { @@ -881,11 +881,11 @@ void BytecodeWriter::outputConstantsInPlane(const std::vector<const Value*> // FIXME: Most slabs only have 1 or 2 entries! We should encode this much // more compactly. - // Output type header: [num entries][type id number] + // Put out type header: [num entries][type id number] // output_vbr(NC); - // Output the Type ID Number... + // Put out the Type ID Number... int Slot = Table.getSlot(Plane.front()->getType()); assert (Slot != -1 && "Type in constant pool but not in function!!"); output_typeid((unsigned)Slot); |