* Both Method & GlobalVariable now subclass GlobalValue
* ConstPoolPointerReference now represents a pointer to a GlobalValue
* Methods name references are now explicit pointers to methods
* Rename Value::GlobalVal to Value::GlobalVariableVal to avoid confusion
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@703 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp
index 4c7f7c9..8ccaf30 100644
--- a/lib/Bytecode/Reader/ConstantReader.cpp
+++ b/lib/Bytecode/Reader/ConstantReader.cpp
@@ -158,7 +158,7 @@
BCR_TRACE(5, "Resulting types:\n");
for (unsigned i = 0; i < NumEntries; i++) {
- BCR_TRACE(5, cast<Type>(Tab[i+BaseLevel]) << "\n");
+ BCR_TRACE(5, cast<const Type>(Tab[i+BaseLevel]) << "\n");
}
return false;
}
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index b6eec66..5697b26 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -197,9 +197,9 @@
if (M == 0) return failure(true);
vector<Value *> Params;
- const MethodType::ParamTypes &PL = M->getType()->getParamTypes();
+ const MethodType::ParamTypes &PL = M->getMethodType()->getParamTypes();
- if (!M->getType()->isVarArg()) {
+ if (!M->getMethodType()->isVarArg()) {
MethodType::ParamTypes::const_iterator It = PL.begin();
switch (Raw.NumOperands) {
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index 14e89e2..97428ea 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -223,7 +223,10 @@
Values.clear();
if (MethodSignatureList.empty()) return failure(true); // Unexpected method!
- const MethodType *MTy = MethodSignatureList.front().first;
+ const PointerType *PMTy = MethodSignatureList.front().first; // PtrMeth
+ const MethodType *MTy = dyn_cast<const MethodType>(PMTy->getValueType());
+ if (MTy == 0) return failure(true); // Not ptr to method!
+
unsigned MethSlot = MethodSignatureList.front().second;
MethodSignatureList.pop_front();
Method *M = new Method(MTy);
@@ -289,13 +292,13 @@
delete M; return failure(true); // Unresolvable references!
}
- Value *MethPHolder = getValue(MTy, MethSlot, false);
+ Value *MethPHolder = getValue(PMTy, MethSlot, false);
assert(MethPHolder && "Something is broken no placeholder found!");
assert(isa<Method>(MethPHolder) && "Not a method?");
unsigned type; // Type slot
assert(!getTypeSlot(MTy, type) && "How can meth type not exist?");
- getTypeSlot(MTy, type);
+ getTypeSlot(PMTy, type);
C->getMethodList().push_back(M);
@@ -330,6 +333,9 @@
return failure(true);
}
+ const PointerType *PTy = cast<const PointerType>(Ty);
+ Ty = PTy->getValueType();
+
ConstPoolVal *Initializer = 0;
if (VarType & 2) { // Does it have an initalizer?
// Do not improvise... values must have been stored in the constant pool,
@@ -338,8 +344,7 @@
unsigned InitSlot;
if (read_vbr(Buf, End, InitSlot)) return failure(true);
- Value *V = getValue(cast<const PointerType>(Ty)->getValueType(),
- InitSlot, false);
+ Value *V = getValue(Ty, InitSlot, false);
if (V == 0) return failure(true);
Initializer = cast<ConstPoolVal>(V);
}
@@ -350,7 +355,7 @@
C->getGlobalList().push_back(GV);
if (read_vbr(Buf, End, VarType)) return failure(true);
- BCR_TRACE(2, "Global Variable of type: " << Ty->getDescription() << endl);
+ BCR_TRACE(2, "Global Variable of type: " << PTy->getDescription() << endl);
}
// Read the method signatures for all of the methods that are coming, and
@@ -359,10 +364,14 @@
if (read_vbr(Buf, End, MethSignature)) return failure(true);
while (MethSignature != Type::VoidTyID) { // List is terminated by Void
const Type *Ty = getType(MethSignature);
- if (!Ty || !isa<MethodType>(Ty)) {
- cerr << "Method not meth type! Ty = " << Ty << endl;
+ if (!Ty || !isa<PointerType>(Ty) ||
+ !isa<MethodType>(cast<PointerType>(Ty)->getValueType())) {
+ cerr << "Method not ptr to meth type! Ty = " << Ty << endl;
return failure(true);
}
+
+ // We create methods by passing the underlying MethodType to create...
+ Ty = cast<PointerType>(Ty)->getValueType();
// 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
@@ -370,19 +379,20 @@
// placeholder is replaced.
// Insert the placeholder...
- Value *Def = new MethPHolder(Ty, 0);
- insertValue(Def, ModuleValues);
+ Value *Val = new MethPHolder(Ty, 0);
+ insertValue(Val, ModuleValues);
// Figure out which entry of its typeslot it went into...
unsigned TypeSlot;
- if (getTypeSlot(Def->getType(), TypeSlot)) return failure(true);
+ if (getTypeSlot(Val->getType(), TypeSlot)) return failure(true);
unsigned SlotNo = ModuleValues[TypeSlot].size()-1;
// Keep track of this information in a linked list that is emptied as
// methods are loaded...
//
- MethodSignatureList.push_back(make_pair(cast<const MethodType>(Ty),SlotNo));
+ 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);
}
diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h
index cf5a43e..ec486d8 100644
--- a/lib/Bytecode/Reader/ReaderInternals.h
+++ b/lib/Bytecode/Reader/ReaderInternals.h
@@ -72,7 +72,7 @@
// into its slot to reserve it. When the method is loaded, this placeholder
// is replaced.
//
- list<pair<const MethodType *, unsigned> > MethodSignatureList;
+ list<pair<const PointerType *, unsigned> > MethodSignatureList;
private:
bool ParseModule (const uchar * Buf, const uchar *End, Module *&);
diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp
index 256f7c8..d8e17e2 100644
--- a/lib/Bytecode/Writer/InstructionWriter.cpp
+++ b/lib/Bytecode/Writer/InstructionWriter.cpp
@@ -15,6 +15,7 @@
#include "llvm/BasicBlock.h"
#include "llvm/Instruction.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/iOther.h"
#include <algorithm>
typedef unsigned char uchar;
@@ -214,10 +215,11 @@
assert(Slots[1] != -1 && "Cast return type unknown?");
if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1];
NumOperands++;
- } else if (I->getOpcode() == Instruction::Call && // Handle VarArg calls
- cast<MethodType>(I->getOperand(0)->getType())->isVarArg()) {
- outputInstrVarArgsCall(I, Table, Type, Out);
- return;
+ } else if (const CallInst *CI = dyn_cast<CallInst>(I)) {// Handle VarArg calls
+ if (CI->getCalledMethod()->getMethodType()->isVarArg()) {
+ outputInstrVarArgsCall(I, Table, Type, Out);
+ return;
+ }
}
// Decide which instruction encoding to use. This is determined primarily by