X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FBytecode%2FReader%2FReader.cpp;h=0b2e935ed4e56bf7f741fda6253e95f1d5688c74;hb=79df7c0aaa18129e55968c8783ef8346807bd4af;hp=a076bffb3a2c72830272734606d0ab7580afcf9d;hpb=b7325433aa2e24b31c3356e20acbb22f21dfe3f7;p=oota-llvm.git diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index a076bffb3a2..0b2e935ed4e 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -10,21 +10,24 @@ // //===----------------------------------------------------------------------===// +#include "ReaderInternals.h" #include "llvm/Bytecode/Reader.h" #include "llvm/Bytecode/Format.h" #include "llvm/GlobalVariable.h" #include "llvm/Module.h" #include "llvm/BasicBlock.h" -#include "llvm/DerivedTypes.h" -#include "llvm/ConstPoolVals.h" +#include "llvm/ConstantVals.h" +#include "llvm/iPHINode.h" #include "llvm/iOther.h" -#include "ReaderInternals.h" #include -#include #include +#include #include #include #include +#include +using std::cerr; +using std::make_pair; bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) { if (Ty->isPrimitiveType()) { @@ -42,7 +45,7 @@ bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) { Slot = FirstDerivedTyID + (&*I - &ModuleTypeValues[0]); } } - //cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << endl; + //cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << "\n"; return false; } @@ -50,7 +53,7 @@ const Type *BytecodeParser::getType(unsigned ID) { const Type *T = Type::getPrimitiveType((Type::PrimitiveID)ID); if (T) return T; - //cerr << "Looking up Type ID: " << ID << endl; + //cerr << "Looking up Type ID: " << ID << "\n"; const Value *D = getValue(Type::TypeTy, ID, false); if (D == 0) return failure(0); @@ -58,7 +61,7 @@ const Type *BytecodeParser::getType(unsigned ID) { return cast(D); } -int BytecodeParser::insertValue(Value *Val, vector &ValueTab) { +int BytecodeParser::insertValue(Value *Val, std::vector &ValueTab) { unsigned type; if (getTypeSlot(Val->getType(), type)) return failure(-1); assert(type != Type::TypeTyID && "Types should never be insertValue'd!"); @@ -67,7 +70,7 @@ int BytecodeParser::insertValue(Value *Val, vector &ValueTab) { ValueTab.resize(type+1, ValueList()); //cerr << "insertValue Values[" << type << "][" << ValueTab[type].size() - // << "] = " << Val << endl; + // << "] = " << Val << "\n"; ValueTab[type].push_back(Val); return ValueTab[type].size()-1; @@ -115,7 +118,7 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) { case Type::LabelTyID: d = new BBPHolder(Ty, oNum); break; case Type::MethodTyID: cerr << "Creating method pholder! : " << type << ":" << oNum << " " - << Ty->getName() << endl; + << Ty->getName() << "\n"; d = new MethPHolder(Ty, oNum); if (insertValue(d, LateResolveModuleValues) ==-1) return failure(0); return d; @@ -196,17 +199,17 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf, // Symtab entry: [def slot #][name] unsigned slot; if (read_vbr(Buf, EndBuf, slot)) return failure(true); - string Name; + std::string Name; if (read(Buf, EndBuf, Name, false)) // Not aligned... return failure(true); Value *D = getValue(Ty, slot, false); // Find mapping... if (D == 0) { - BCR_TRACE(3, "FAILED LOOKUP: Slot #" << slot << endl); + BCR_TRACE(3, "FAILED LOOKUP: Slot #" << slot << "\n"); return failure(true); } BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D; - if (!isa(D)) cerr << endl); + if (!isa(D)) cerr << "\n"); D->setName(Name, ST); } @@ -217,7 +220,7 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf, } // DeclareNewGlobalValue - Patch up forward references to global values in the -// form of ConstPoolPointerRef. +// form of ConstantPointerRef. // void BytecodeParser::DeclareNewGlobalValue(GlobalValue *GV, unsigned Slot) { // Check to see if there is a forward reference to this global variable... @@ -229,11 +232,11 @@ void BytecodeParser::DeclareNewGlobalValue(GlobalValue *GV, unsigned Slot) { BCR_TRACE(3, "Mutating CPPR Forward Ref!\n"); // Loop over all of the uses of the GlobalValue. The only thing they are - // allowed to be at this point is ConstPoolPointerRef's. + // allowed to be at this point is ConstantPointerRef's. assert(OldGV->use_size() == 1 && "Only one reference should exist!"); while (!OldGV->use_empty()) { - User *U = OldGV->use_back(); // Must be a ConstPoolPointerRef... - ConstPoolPointerRef *CPPR = cast(U); + User *U = OldGV->use_back(); // Must be a ConstantPointerRef... + ConstantPointerRef *CPPR = cast(U); assert(CPPR->getValue() == OldGV && "Something isn't happy"); BCR_TRACE(4, "Mutating Forward Ref!\n"); @@ -262,24 +265,27 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, } const PointerType *PMTy = MethodSignatureList.front().first; // PtrMeth - const MethodType *MTy = dyn_cast(PMTy->getValueType()); + const MethodType *MTy = dyn_cast(PMTy->getElementType()); if (MTy == 0) return failure(true); // Not ptr to method! + unsigned isInternal; + if (read_vbr(Buf, EndBuf, isInternal)) return failure(true); + unsigned MethSlot = MethodSignatureList.front().second; MethodSignatureList.pop_front(); - Method *M = new Method(MTy); + Method *M = new Method(MTy, isInternal != 0); - BCR_TRACE(2, "METHOD TYPE: " << MTy << endl); + BCR_TRACE(2, "METHOD TYPE: " << MTy << "\n"); const MethodType::ParamTypes &Params = MTy->getParamTypes(); for (MethodType::ParamTypes::const_iterator It = Params.begin(); It != Params.end(); ++It) { - MethodArgument *MA = new MethodArgument(*It); - if (insertValue(MA, Values) == -1) { + FunctionArgument *FA = new FunctionArgument(*It); + if (insertValue(FA, Values) == -1) { Error = "Error reading method arguments!\n"; delete M; return failure(true); } - M->getArgumentList().push_back(MA); + M->getArgumentList().push_back(FA); } while (Buf < EndBuf) { @@ -346,7 +352,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, assert(!getTypeSlot(MTy, type) && "How can meth type not exist?"); getTypeSlot(PMTy, type); - C->getMethodList().push_back(M); + C->getFunctionList().push_back(M); // Replace placeholder with the real method pointer... ModuleValues[type][MethSlot] = M; @@ -380,17 +386,18 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, unsigned VarType; if (read_vbr(Buf, End, VarType)) return failure(true); while (VarType != Type::VoidTyID) { // List is terminated by Void - // VarType Fields: bit0 = isConstant, bit1 = hasInitializer, bit2+ = slot# - const Type *Ty = getType(VarType >> 2); + // VarType Fields: bit0 = isConstant, bit1 = hasInitializer, + // bit2 = isInternal, bit3+ = slot# + const Type *Ty = getType(VarType >> 3); if (!Ty || !Ty->isPointerType()) { Error = "Global not pointer type! Ty = " + Ty->getDescription(); return failure(true); } const PointerType *PTy = cast(Ty); - const Type *ElTy = PTy->getValueType(); + const Type *ElTy = PTy->getElementType(); - ConstPoolVal *Initializer = 0; + Constant *Initializer = 0; if (VarType & 2) { // Does it have an initalizer? // Do not improvise... values must have been stored in the constant pool, // which should have been read before now. @@ -400,11 +407,12 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, Value *V = getValue(ElTy, InitSlot, false); if (V == 0) return failure(true); - Initializer = cast(V); + Initializer = cast(V); } // Create the global variable... - GlobalVariable *GV = new GlobalVariable(ElTy, VarType & 1, Initializer); + GlobalVariable *GV = new GlobalVariable(ElTy, VarType & 1, VarType & 4, + Initializer); int DestSlot = insertValue(GV, ModuleValues); if (DestSlot == -1) return failure(true); @@ -413,7 +421,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, DeclareNewGlobalValue(GV, unsigned(DestSlot)); BCR_TRACE(2, "Global Variable of type: " << PTy->getDescription() - << " into slot #" << DestSlot << endl); + << " into slot #" << DestSlot << "\n"); if (read_vbr(Buf, End, VarType)) return failure(true); } @@ -425,13 +433,13 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, while (MethSignature != Type::VoidTyID) { // List is terminated by Void const Type *Ty = getType(MethSignature); if (!Ty || !isa(Ty) || - !isa(cast(Ty)->getValueType())) { + !isa(cast(Ty)->getElementType())) { Error = "Method not ptr to meth type! Ty = " + Ty->getDescription(); return failure(true); } // We create methods by passing the underlying MethodType to create... - Ty = cast(Ty)->getValueType(); + Ty = cast(Ty)->getElementType(); // When the ModuleGlobalInfo section is read, we load the type of each // method and the 'ModuleValues' slot that it lands in. We then load a @@ -454,7 +462,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, MethodSignatureList.push_back( make_pair(cast(Val->getType()), SlotNo)); if (read_vbr(Buf, End, MethSignature)) return failure(true); - BCR_TRACE(2, "Method of type: " << Ty << endl); + BCR_TRACE(2, "Method of type: " << Ty << "\n"); } if (align32(Buf, End)) return failure(true); @@ -561,11 +569,11 @@ Module *ParseBytecodeBuffer(const uchar *Buffer, unsigned Length) { // Parse and return a class file... // -Module *ParseBytecodeFile(const string &Filename, string *ErrorStr) { +Module *ParseBytecodeFile(const std::string &Filename, std::string *ErrorStr) { struct stat StatBuf; Module *Result = 0; - if (Filename != string("-")) { // Read from a file... + if (Filename != std::string("-")) { // Read from a file... int FD = open(Filename.c_str(), O_RDONLY); if (FD == -1) { if (ErrorStr) *ErrorStr = "Error opening file!";