diff options
author | Chris Lattner <sabre@nondot.org> | 2001-06-27 23:41:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-06-27 23:41:11 +0000 |
commit | 7fc9fe34390c66ca58646d09a87f7dbaacb6c1f8 (patch) | |
tree | fd083cad8506b9f54d19b8429dfae825f264c35b /lib/Bytecode | |
parent | 138a124f09de272b2ab93cfd6e2a8a283d18029b (diff) |
Miscellaneous cleanups:
* Convert post to pre-increment for for loops
* Use generic programming more
* Use new Value::cast* instructions
* Use new Module, Method, & BasicBlock forwarding methods
* Use new facilities in STLExtras.h
* Use new Instruction::isPHINode() method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r-- | lib/Bytecode/Reader/ConstantReader.cpp | 4 | ||||
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 17 | ||||
-rw-r--r-- | lib/Bytecode/Writer/SlotCalculator.cpp | 11 | ||||
-rw-r--r-- | lib/Bytecode/Writer/Writer.cpp | 20 |
4 files changed, 22 insertions, 30 deletions
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index b85bd887ef..dd47d1c2cf 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -156,7 +156,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf, unsigned Slot; if (read_vbr(Buf, EndBuf, Slot)) return true; Value *V = getValue(AT->getElementType(), Slot, false); - if (!V || V->getValueType() != Value::ConstantVal) + if (!V || !V->isConstant()) return true; Elements.push_back((ConstPoolVal*)V); } @@ -173,7 +173,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf, unsigned Slot; if (read_vbr(Buf, EndBuf, Slot)) return true; Value *V = getValue(ET[i], Slot, false); - if (!V || V->getValueType() != Value::ConstantVal) + if (!V || !V->isConstant()) return true; Elements.push_back((ConstPoolVal*)V); } diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index c3f4c907fe..e8bf17e604 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -46,11 +46,8 @@ const Type *BytecodeParser::getType(unsigned ID) { const Value *D = getValue(Type::TypeTy, ID, false); if (D == 0) return 0; - assert(D->getType() == Type::TypeTy && - D->getValueType() == Value::ConstantVal); - - - return ((const ConstPoolType*)D)->getValue();; + assert(D->getType() == Type::TypeTy); + return ((const ConstPoolType*)D->castConstantAsserting())->getValue(); } bool BytecodeParser::insertValue(Value *Def, vector<ValueList> &ValueTab) { @@ -63,7 +60,7 @@ bool BytecodeParser::insertValue(Value *Def, vector<ValueList> &ValueTab) { //cerr << "insertValue Values[" << type << "][" << ValueTab[type].size() // << "] = " << Def << endl; - if (type == Type::TypeTyID && Def->getValueType() == Value::ConstantVal) { + if (type == Type::TypeTyID && Def->isConstant()) { const Type *Ty = ((const ConstPoolType*)Def)->getValue(); unsigned ValueOffset = FirstDerivedTyID; @@ -123,7 +120,7 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) { bool BytecodeParser::postResolveValues(ValueTable &ValTab) { bool Error = false; - for (unsigned ty = 0; ty < ValTab.size(); ty++) { + for (unsigned ty = 0; ty < ValTab.size(); ++ty) { ValueList &DL = ValTab[ty]; unsigned Size; while ((Size = DL.size())) { @@ -180,7 +177,7 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf) { const Type *Ty = getType(Typ); if (Ty == 0) return true; - for (unsigned i = 0; i < NumEntries; i++) { + for (unsigned i = 0; i < NumEntries; ++i) { // Symtab entry: [def slot #][name] unsigned slot; if (read_vbr(Buf, EndBuf, slot)) return true; @@ -211,7 +208,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, const MethodType::ParamTypes &Params = MTy->getParamTypes(); for (MethodType::ParamTypes::const_iterator It = Params.begin(); - It != Params.end(); It++) { + It != Params.end(); ++It) { MethodArgument *MA = new MethodArgument(*It); if (insertValue(MA, Values)) { delete M; return true; } M->getArgumentList().push_back(MA); @@ -267,7 +264,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, Value *MethPHolder = getValue(MTy, MethSlot, false); assert(MethPHolder && "Something is broken no placeholder found!"); - assert(MethPHolder->getValueType() == Value::MethodVal && "Not a method?"); + assert(MethPHolder->isMethod() && "Not a method?"); unsigned type; // Type slot assert(!getTypeSlot(MTy, type) && "How can meth type not exist?"); diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index 01fae37e53..f7eada1418 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -176,12 +176,11 @@ void SlotCalculator::insertVal(const Value *D) { // Insert node into table and NodeMap... NodeMap[D] = Table[Ty].size(); - if (Typ == Type::TypeTy && // If it's a type constant, add the Type also - D->getValueType() != Value::TypeVal) { - assert(D->getValueType() == Value::ConstantVal && - "All Type instances should be constant types!"); - - const ConstPoolType *CPT = (const ConstPoolType*)D; + if (Typ == Type::TypeTy && !D->isType()) { + // If it's a type constant, add the Type also + + // All Type instances should be constant types! + const ConstPoolType *CPT = (const ConstPoolType*)D->castConstantAsserting(); int Slot = getValSlot(CPT->getValue()); if (Slot == -1) { // Only add if it's not already here! diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index d03c945471..2be490dbed 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -67,7 +67,7 @@ bool BytecodeWriter::processConstPool(const ConstantPool &CP, bool isMethod) { unsigned NumConstants = 0; for (unsigned vn = ValNo; vn < Plane.size(); vn++) - if (Plane[vn]->getValueType() == Value::ConstantVal) + if (Plane[vn]->isConstant()) NumConstants++; if (NumConstants == 0) continue; // Skip empty type planes... @@ -85,21 +85,19 @@ bool BytecodeWriter::processConstPool(const ConstantPool &CP, bool isMethod) { for (; ValNo < Plane.size(); ValNo++) { const Value *V = Plane[ValNo]; - if (V->getValueType() == Value::ConstantVal) { + if (const ConstPoolVal *CPV = V->castConstant()) { //cerr << "Serializing value: <" << V->getType() << ">: " // << ((const ConstPoolVal*)V)->getStrValue() << ":" // << Out.size() << "\n"; - outputConstant((const ConstPoolVal*)V); + outputConstant(CPV); } } } delete CPool; // End bytecode block section! - if (!isMethod) { // The ModuleInfoBlock follows directly after the c-pool - assert(CP.getParent()->getValueType() == Value::ModuleVal); - outputModuleInfoBlock((const Module*)CP.getParent()); - } + if (!isMethod) // The ModuleInfoBlock follows directly after the c-pool + outputModuleInfoBlock(CP.getParent()->castModuleAsserting()); return false; } @@ -108,13 +106,11 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) { BytecodeBlock ModuleInfoBlock(BytecodeFormat::ModuleGlobalInfo, Out); // Output the types of the methods in this class - Module::MethodListType::const_iterator I = M->getMethodList().begin(); - while (I != M->getMethodList().end()) { + for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) { int Slot = Table.getValSlot((*I)->getType()); assert(Slot != -1 && "Module const pool is broken!"); assert(Slot >= Type::FirstDerivedTyID && "Derived type not in range!"); output_vbr((unsigned)Slot, Out); - I++; } output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out); align32(Out); @@ -144,7 +140,7 @@ bool BytecodeWriter::processBasicBlock(const BasicBlock *BB) { void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { BytecodeBlock MethodBlock(BytecodeFormat::SymbolTable, Out); - for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); TI++) { + for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); ++TI) { SymbolTable::type_const_iterator I = MST.type_begin(TI->first); SymbolTable::type_const_iterator End = MST.type_end(TI->first); int Slot; @@ -158,7 +154,7 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { assert(Slot != -1 && "Type in symtab, but not in table!"); output_vbr((unsigned)Slot, Out); - for (; I != End; I++) { + for (; I != End; ++I) { // Symtab entry: [def slot #][name] Slot = Table.getValSlot(I->second); assert (Slot != -1 && "Value in symtab but not in method!!"); |