diff options
author | Chris Lattner <sabre@nondot.org> | 2003-10-09 20:22:47 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-10-09 20:22:47 +0000 |
commit | 927b185c175a8eb6d64ea97e1735fc6102114766 (patch) | |
tree | 61b9ae5b740d44fe2ec5292181b989e444d83155 /lib/Bytecode/Reader/ConstantReader.cpp | |
parent | 3483f54367e990c61eda61a6a550ba2634a13cb9 (diff) |
Major refactoring of the bytecode reader. This includes the following
changes:
* BytecodeReader::getType(...) used to return a null pointer
on error. This was only checked about half the time. Now we convert
it to throw an exception, and delete the half that checked for error.
This was checked in before, but psmith crashed and lost the change :(
* insertValue no longer returns -1 on error, so callers don't need to
check for it.
* Substantial rewrite of InstructionReader.cpp, to use more efficient,
simpler, data structures. This provides another 5% speedup. This also
makes the code much easier to read and understand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8984 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader/ConstantReader.cpp')
-rw-r--r-- | lib/Bytecode/Reader/ConstantReader.cpp | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index 2f0e0b8e0f..4b6e998fed 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -27,7 +27,6 @@ const Type *BytecodeParser::parseTypeConstant(const unsigned char *&Buf, unsigned Typ; if (read_vbr(Buf, EndBuf, Typ)) return Val; const Type *RetType = getType(Typ); - if (RetType == 0) return Val; unsigned NumParams; if (read_vbr(Buf, EndBuf, NumParams)) return Val; @@ -35,9 +34,7 @@ const Type *BytecodeParser::parseTypeConstant(const unsigned char *&Buf, std::vector<const Type*> Params; while (NumParams--) { if (read_vbr(Buf, EndBuf, Typ)) return Val; - const Type *Ty = getType(Typ); - if (Ty == 0) return Val; - Params.push_back(Ty); + Params.push_back(getType(Typ)); } bool isVarArg = Params.size() && Params.back() == Type::VoidTy; @@ -49,7 +46,6 @@ const Type *BytecodeParser::parseTypeConstant(const unsigned char *&Buf, unsigned ElTyp; if (read_vbr(Buf, EndBuf, ElTyp)) return Val; const Type *ElementType = getType(ElTyp); - if (ElementType == 0) return Val; unsigned NumElements; if (read_vbr(Buf, EndBuf, NumElements)) return Val; @@ -64,10 +60,7 @@ const Type *BytecodeParser::parseTypeConstant(const unsigned char *&Buf, if (read_vbr(Buf, EndBuf, Typ)) return Val; while (Typ) { // List is terminated by void/0 typeid - const Type *Ty = getType(Typ); - if (Ty == 0) return Val; - Elements.push_back(Ty); - + Elements.push_back(getType(Typ)); if (read_vbr(Buf, EndBuf, Typ)) return Val; } @@ -77,9 +70,7 @@ const Type *BytecodeParser::parseTypeConstant(const unsigned char *&Buf, unsigned ElTyp; if (read_vbr(Buf, EndBuf, ElTyp)) return Val; BCR_TRACE(5, "Pointer Type Constant #" << ElTyp << "\n"); - const Type *ElementType = getType(ElTyp); - if (ElementType == 0) return Val; - return PointerType::get(ElementType); + return PointerType::get(getType(ElTyp)); } case Type::OpaqueTyID: { @@ -169,9 +160,8 @@ Constant *BytecodeParser::parseConstantValue(const unsigned char *&Buf, if (read_vbr(Buf, EndBuf, ArgValSlot)) throw Error_readvbr; if (read_vbr(Buf, EndBuf, ArgTypeSlot)) throw Error_readvbr; const Type *ArgTy = getType(ArgTypeSlot); - if (ArgTy == 0) throw std::string("Argument type slot not found."); - BCR_TRACE(4, "CE Arg " << i << ": Type: '" << ArgTy << "' slot: " + BCR_TRACE(4, "CE Arg " << i << ": Type: '" << *ArgTy << "' slot: " << ArgValSlot << "\n"); // Get the arg value from its slot if it exists, otherwise a placeholder @@ -355,27 +345,25 @@ void BytecodeParser::ParseConstantPool(const unsigned char *&Buf, if (read_vbr(Buf, EndBuf, NumEntries) || read_vbr(Buf, EndBuf, Typ)) throw Error_readvbr; - const Type *Ty = getType(Typ); - if (Ty == 0) throw std::string("Invalid type read."); - BCR_TRACE(3, "Type: '" << Ty << "' NumEntries: " << NumEntries << "\n"); - if (Typ == Type::TypeTyID) { + BCR_TRACE(3, "Type: 'type' NumEntries: " << NumEntries << "\n"); parseTypeConstants(Buf, EndBuf, TypeTab, NumEntries); } else { + const Type *Ty = getType(Typ); + BCR_TRACE(3, "Type: '" << *Ty << "' NumEntries: " << NumEntries << "\n"); + for (unsigned i = 0; i < NumEntries; ++i) { 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."); + unsigned Slot = insertValue(C, Tab); // If we are reading a function constant table, make sure that we adjust // the slot number to be the real global constant number. // if (&Tab != &ModuleValues && Typ < ModuleValues.size()) Slot += ModuleValues[Typ]->size(); - ResolveReferencesToValue(C, (unsigned)Slot); + ResolveReferencesToValue(C, Slot); } } } |