//
//===----------------------------------------------------------------------===//
+#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 <sys/types.h>
-#include <sys/mman.h>
#include <sys/stat.h>
+#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <algorithm>
+#include <iostream>
+using std::cerr;
+using std::make_pair;
bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) {
if (Ty->isPrimitiveType()) {
Slot = FirstDerivedTyID + (&*I - &ModuleTypeValues[0]);
}
}
- //cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << endl;
+ //cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << "\n";
return false;
}
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<const Type*>(0);
return cast<Type>(D);
}
-int BytecodeParser::insertValue(Value *Val, vector<ValueList> &ValueTab) {
+int BytecodeParser::insertValue(Value *Val, std::vector<ValueList> &ValueTab) {
unsigned type;
if (getTypeSlot(Val->getType(), type)) return failure<int>(-1);
assert(type != Type::TypeTyID && "Types should never be insertValue'd!");
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;
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<Value*>(0);
return d;
// 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<Instruction>(D)) cerr << endl);
+ if (!isa<Instruction>(D)) cerr << "\n");
D->setName(Name, ST);
}
}
// 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...
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<ConstPoolPointerRef>(U);
+ User *U = OldGV->use_back(); // Must be a ConstantPointerRef...
+ ConstantPointerRef *CPPR = cast<ConstantPointerRef>(U);
assert(CPPR->getValue() == OldGV && "Something isn't happy");
BCR_TRACE(4, "Mutating Forward Ref!\n");
}
const PointerType *PMTy = MethodSignatureList.front().first; // PtrMeth
- const MethodType *MTy = dyn_cast<const MethodType>(PMTy->getValueType());
+ const MethodType *MTy = dyn_cast<const MethodType>(PMTy->getElementType());
if (MTy == 0) return failure(true); // Not ptr to method!
unsigned isInternal;
MethodSignatureList.pop_front();
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) {
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;
}
const PointerType *PTy = cast<const PointerType>(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.
Value *V = getValue(ElTy, InitSlot, false);
if (V == 0) return failure(true);
- Initializer = cast<ConstPoolVal>(V);
+ Initializer = cast<Constant>(V);
}
// Create the global variable...
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);
}
while (MethSignature != Type::VoidTyID) { // List is terminated by Void
const Type *Ty = getType(MethSignature);
if (!Ty || !isa<PointerType>(Ty) ||
- !isa<MethodType>(cast<PointerType>(Ty)->getValueType())) {
+ !isa<MethodType>(cast<PointerType>(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<PointerType>(Ty)->getValueType();
+ Ty = cast<PointerType>(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
MethodSignatureList.push_back(
make_pair(cast<const PointerType>(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);
// 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!";