aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode/Reader/Reader.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-04 20:00:03 +0000
committerChris Lattner <sabre@nondot.org>2003-10-04 20:00:03 +0000
commit9e460f23bb00c8b107ea6ef3a932a33e115d3dce (patch)
tree9e0d7e34f4cceb0902b9e94f28e03e310bf3fa84 /lib/Bytecode/Reader/Reader.cpp
parent51ca860bda05bc647140e721c2c2c23c81c4904b (diff)
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
Diffstat (limited to 'lib/Bytecode/Reader/Reader.cpp')
-rw-r--r--lib/Bytecode/Reader/Reader.cpp44
1 files changed, 18 insertions, 26 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index 321a26f4c4..727e2a9110 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -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);