diff options
Diffstat (limited to 'llvm/lib/Bytecode')
-rw-r--r-- | llvm/lib/Bytecode/Reader/Reader.cpp | 22 | ||||
-rw-r--r-- | llvm/lib/Bytecode/Writer/Writer.cpp | 13 |
2 files changed, 32 insertions, 3 deletions
diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp index 540768383ac..eab576e541b 100644 --- a/llvm/lib/Bytecode/Reader/Reader.cpp +++ b/llvm/lib/Bytecode/Reader/Reader.cpp @@ -12,6 +12,7 @@ #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" @@ -312,10 +313,28 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, Module *C) { - if (!MethodSignatureList.empty()) return failure(true); // Two ModuleGlobal blocks? + // Read global variables... + unsigned VarType; + if (read_vbr(Buf, End, VarType)) return failure(true); + while (VarType != Type::VoidTyID) { // List is terminated by Void + const Type *Ty = getType(VarType); + if (!Ty || !Ty->isPointerType()) { + cerr << "Global not pointer type! Ty = " << Ty << endl; + return failure(true); + } + + // Create the global variable... + GlobalVariable *GV = new GlobalVariable(Ty); + insertValue(GV, ModuleValues); + C->getGlobalList().push_back(GV); + + if (read_vbr(Buf, End, VarType)) return failure(true); + BCR_TRACE(2, "Global Variable of type: " << Ty->getDescription() << endl); + } + // Read the method signatures for all of the methods that are coming, and // create fillers in the Value tables. unsigned MethSignature; @@ -324,7 +343,6 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, const Type *Ty = getType(MethSignature); if (!Ty || !Ty->isMethodType()) { cerr << "Method not meth type! Ty = " << Ty << endl; - if (Ty) cerr << Ty->getName(); else cerr << MethSignature; cerr << endl; return failure(true); } diff --git a/llvm/lib/Bytecode/Writer/Writer.cpp b/llvm/lib/Bytecode/Writer/Writer.cpp index 42351458229..e6562f5fb94 100644 --- a/llvm/lib/Bytecode/Writer/Writer.cpp +++ b/llvm/lib/Bytecode/Writer/Writer.cpp @@ -24,6 +24,7 @@ #include "WriterInternals.h" #include "llvm/Module.h" +#include "llvm/GlobalVariable.h" #include "llvm/Method.h" #include "llvm/BasicBlock.h" #include "llvm/ConstPoolVals.h" @@ -117,7 +118,15 @@ void BytecodeWriter::outputConstants(bool isMethod) { void BytecodeWriter::outputModuleInfoBlock(const Module *M) { BytecodeBlock ModuleInfoBlock(BytecodeFormat::ModuleGlobalInfo, Out); - // Output the types of the methods in this class + // Output the types for the global variables in the module... + for (Module::const_giterator I = M->gbegin(), End = M->gend(); I != End;++I) { + int Slot = Table.getValSlot((*I)->getType()); + assert(Slot != -1 && "Module global vars is broken!"); + output_vbr((unsigned)Slot, Out); + } + output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out); + + // Output the types of the methods in this module... 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!"); @@ -125,6 +134,8 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) { output_vbr((unsigned)Slot, Out); } output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out); + + align32(Out); } |