Transform two methods to return pointers directly instead of returning them

as 'by reference' arguments.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8849 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2003-10-04 20:00:03 +00:00
parent 51ca860bda
commit 9e460f23bb
3 changed files with 42 additions and 66 deletions

View File

@ -147,9 +147,9 @@ void BytecodeParser::parseTypeConstants(const unsigned char *&Buf,
}
void BytecodeParser::parseConstantValue(const unsigned char *&Buf,
const unsigned char *EndBuf,
const Type *Ty, Constant *&V) {
Constant *BytecodeParser::parseConstantValue(const unsigned char *&Buf,
const unsigned char *EndBuf,
const Type *Ty) {
// We must check for a ConstantExpr before switching by type because
// a ConstantExpr can be of any type, and has no explicit value.
@ -183,14 +183,13 @@ void BytecodeParser::parseConstantValue(const unsigned char *&Buf,
// Construct a ConstantExpr of the appropriate kind
if (isExprNumArgs == 1) { // All one-operand expressions
assert(Opcode == Instruction::Cast);
V = ConstantExpr::getCast(ArgVec[0], Ty);
return ConstantExpr::getCast(ArgVec[0], Ty);
} else if (Opcode == Instruction::GetElementPtr) { // GetElementPtr
std::vector<Constant*> IdxList(ArgVec.begin()+1, ArgVec.end());
V = ConstantExpr::getGetElementPtr(ArgVec[0], IdxList);
return ConstantExpr::getGetElementPtr(ArgVec[0], IdxList);
} else { // All other 2-operand expressions
V = ConstantExpr::get(Opcode, ArgVec[0], ArgVec[1]);
return ConstantExpr::get(Opcode, ArgVec[0], ArgVec[1]);
}
return;
}
// Ok, not an ConstantExpr. We now know how to read the given type...
@ -199,8 +198,7 @@ void BytecodeParser::parseConstantValue(const unsigned char *&Buf,
unsigned Val;
if (read_vbr(Buf, EndBuf, Val)) throw Error_readvbr;
if (Val != 0 && Val != 1) throw std::string("Invalid boolean value read.");
V = ConstantBool::get(Val == 1);
break;
return ConstantBool::get(Val == 1);
}
case Type::UByteTyID: // Unsigned integer types...
@ -210,15 +208,13 @@ void BytecodeParser::parseConstantValue(const unsigned char *&Buf,
if (read_vbr(Buf, EndBuf, Val)) throw Error_readvbr;
if (!ConstantUInt::isValueValidForType(Ty, Val))
throw std::string("Invalid unsigned byte/short/int read.");
V = ConstantUInt::get(Ty, Val);
break;
return ConstantUInt::get(Ty, Val);
}
case Type::ULongTyID: {
uint64_t Val;
if (read_vbr(Buf, EndBuf, Val)) throw Error_readvbr;
V = ConstantUInt::get(Ty, Val);
break;
return ConstantUInt::get(Ty, Val);
}
case Type::SByteTyID: // Signed integer types...
@ -229,27 +225,23 @@ void BytecodeParser::parseConstantValue(const unsigned char *&Buf,
if (read_vbr(Buf, EndBuf, Val)) throw Error_readvbr;
if (!ConstantSInt::isValueValidForType(Ty, Val))
throw std::string("Invalid signed byte/short/int/long read.");
V = ConstantSInt::get(Ty, Val);
break;
return ConstantSInt::get(Ty, Val);
}
case Type::FloatTyID: {
float F;
if (input_data(Buf, EndBuf, &F, &F+1)) throw Error_inputdata;
V = ConstantFP::get(Ty, F);
break;
return ConstantFP::get(Ty, F);
}
case Type::DoubleTyID: {
double Val;
if (input_data(Buf, EndBuf, &Val, &Val+1)) throw Error_inputdata;
V = ConstantFP::get(Ty, Val);
break;
return ConstantFP::get(Ty, Val);
}
case Type::TypeTyID:
assert(0 && "Type constants should be handled separately!!!");
abort();
throw std::string("Type constants shouldn't live in constant table!");
case Type::ArrayTyID: {
const ArrayType *AT = cast<ArrayType>(Ty);
@ -263,8 +255,7 @@ void BytecodeParser::parseConstantValue(const unsigned char *&Buf,
if (!C) throw std::string("Unable to get const value of array slot.");
Elements.push_back(C);
}
V = ConstantArray::get(AT, Elements);
break;
return ConstantArray::get(AT, Elements);
}
case Type::StructTyID: {
@ -280,8 +271,7 @@ void BytecodeParser::parseConstantValue(const unsigned char *&Buf,
Elements.push_back(C);
}
V = ConstantStruct::get(ST, Elements);
break;
return ConstantStruct::get(ST, Elements);
}
case Type::PointerTyID: {
@ -294,8 +284,7 @@ void BytecodeParser::parseConstantValue(const unsigned char *&Buf,
switch (SubClass) {
case 0: // ConstantPointerNull value...
V = ConstantPointerNull::get(PT);
break;
return ConstantPointerNull::get(PT);
case 1: { // ConstantPointerRef value...
unsigned Slot;
@ -336,23 +325,18 @@ void BytecodeParser::parseConstantValue(const unsigned char *&Buf,
}
}
V = ConstantPointerRef::get(GV);
break;
return ConstantPointerRef::get(GV);
}
default:
BCR_TRACE(5, "UNKNOWN Pointer Constant Type!\n");
throw std::string("Unknown pointer constant type.");
}
break;
}
default:
std::cerr << __FILE__ << ":" << __LINE__
<< ": Don't know how to deserialize constant value of type '"
<< Ty->getName() << "'\n";
throw std::string("Don't know how to deserialize constant value of type '"+
Ty->getName());
Ty->getDescription());
}
}
@ -379,11 +363,10 @@ void BytecodeParser::ParseConstantPool(const unsigned char *&Buf,
parseTypeConstants(Buf, EndBuf, TypeTab, NumEntries);
} else {
for (unsigned i = 0; i < NumEntries; ++i) {
Constant *C;
int Slot;
parseConstantValue(Buf, EndBuf, Ty, C);
Constant *C = parseConstantValue(Buf, EndBuf, Ty);
assert(C && "parseConstantValue returned NULL!");
BCR_TRACE(4, "Read Constant: '" << *C << "'\n");
int Slot;
if ((Slot = insertValue(C, Tab)) == -1)
throw std::string("Could not insert value into ValueTable.");

View File

@ -31,25 +31,21 @@ static inline void ALIGN32(const unsigned char *&begin,
throw std::string("Alignment error in buffer: read past end of block.");
}
void
BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) {
if (Ty->isPrimitiveType()) {
Slot = Ty->getPrimitiveID();
} else {
// Check the function level types first...
TypeValuesListTy::iterator I = find(FunctionTypeValues.begin(),
FunctionTypeValues.end(), Ty);
if (I != FunctionTypeValues.end()) {
Slot = FirstDerivedTyID + ModuleTypeValues.size() +
(&*I - &FunctionTypeValues[0]);
} else {
I = find(ModuleTypeValues.begin(), ModuleTypeValues.end(), Ty);
if (I == ModuleTypeValues.end())
throw std::string("Didn't find type in ModuleTypeValues.");
Slot = FirstDerivedTyID + (&*I - &ModuleTypeValues[0]);
}
}
//cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << "\n";
unsigned BytecodeParser::getTypeSlot(const Type *Ty) {
if (Ty->isPrimitiveType())
return Ty->getPrimitiveID();
// Check the function level types first...
TypeValuesListTy::iterator I = find(FunctionTypeValues.begin(),
FunctionTypeValues.end(), Ty);
if (I != FunctionTypeValues.end())
return FirstDerivedTyID + ModuleTypeValues.size() +
(&*I - &FunctionTypeValues[0]);
I = find(ModuleTypeValues.begin(), ModuleTypeValues.end(), Ty);
if (I == ModuleTypeValues.end())
throw std::string("Didn't find type in ModuleTypeValues.");
return FirstDerivedTyID + (&*I - &ModuleTypeValues[0]);
}
const Type *BytecodeParser::getType(unsigned ID) {
@ -68,8 +64,7 @@ int BytecodeParser::insertValue(Value *Val, ValueTable &ValueTab) {
Val->getType()->isPrimitiveType() ||
!cast<Constant>(Val)->isNullValue()) &&
"Cannot read null values from bytecode!");
unsigned type;
getTypeSlot(Val->getType(), type);
unsigned type = getTypeSlot(Val->getType());
assert(type != Type::TypeTyID && "Types should never be insertValue'd!");
if (ValueTab.size() <= type) {
@ -93,19 +88,16 @@ int BytecodeParser::insertValue(Value *Val, ValueTable &ValueTab) {
void BytecodeParser::setValueTo(ValueTable &ValueTab, unsigned Slot,
Value *Val) {
assert(&ValueTab == &ModuleValues && "Can only setValueTo on Module values!");
unsigned type;
getTypeSlot(Val->getType(), type);
assert((!HasImplicitZeroInitializer || Slot != 0) &&
"Cannot change zero init");
unsigned type = getTypeSlot(Val->getType());
assert(type < ValueTab.size() && Slot <= ValueTab[type]->size());
ValueTab[type]->setOperand(Slot-HasImplicitZeroInitializer, Val);
}
Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) {
unsigned Num = oNum;
unsigned type; // The type plane it lives in...
getTypeSlot(Ty, type);
unsigned type = getTypeSlot(Ty); // The type plane it lives in...
if (type == Type::TypeTyID) { // The 'type' plane has implicit values
assert(Create == false);

View File

@ -169,8 +169,9 @@ private:
void ParseConstantPool(const unsigned char *&Buf, const unsigned char *EndBuf,
ValueTable &Tab, TypeValuesListTy &TypeTab);
void parseConstantValue(const unsigned char *&Buf, const unsigned char *End,
const Type *Ty, Constant *&V);
Constant *parseConstantValue(const unsigned char *&Buf,
const unsigned char *End,
const Type *Ty);
void parseTypeConstants(const unsigned char *&Buf,
const unsigned char *EndBuf,
TypeValuesListTy &Tab, unsigned NumEntries);
@ -185,7 +186,7 @@ private:
void setValueTo(ValueTable &D, unsigned Slot, Value *V);
void postResolveValues(ValueTable &ValTab);
void getTypeSlot(const Type *Ty, unsigned &Slot);
unsigned getTypeSlot(const Type *Ty);
// resolve all references to the placeholder (if any) for the given value
void ResolveReferencesToValue(Value *Val, unsigned Slot);