* 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
llvm-svn: 703
diff --git a/llvm/lib/AsmParser/ParserInternals.h b/llvm/lib/AsmParser/ParserInternals.h
index bedb65f..b00a352 100644
--- a/llvm/lib/AsmParser/ParserInternals.h
+++ b/llvm/lib/AsmParser/ParserInternals.h
@@ -176,7 +176,12 @@
typedef PlaceholderValue<MethPlaceHolderHelper> MethPlaceHolder;
static inline ValID &getValIDFromPlaceHolder(const Value *Val) {
- switch (Val->getType()->getPrimitiveID()) {
+ const Type *Ty = Val->getType();
+ if (isa<PointerType>(Ty) &&
+ isa<MethodType>(cast<PointerType>(Ty)->getValueType()))
+ Ty = cast<PointerType>(Ty)->getValueType();
+
+ switch (Ty->getPrimitiveID()) {
case Type::TypeTyID: return ((TypePlaceHolder*)Val)->getDef();
case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getDef();
case Type::MethodTyID: return ((MethPlaceHolder*)Val)->getDef();
@@ -185,7 +190,12 @@
}
static inline int getLineNumFromPlaceHolder(const Value *Val) {
- switch (Val->getType()->getPrimitiveID()) {
+ const Type *Ty = Val->getType();
+ if (isa<PointerType>(Ty) &&
+ isa<MethodType>(cast<PointerType>(Ty)->getValueType()))
+ Ty = cast<PointerType>(Ty)->getValueType();
+
+ switch (Ty->getPrimitiveID()) {
case Type::TypeTyID: return ((TypePlaceHolder*)Val)->getLineNum();
case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getLineNum();
case Type::MethodTyID: return ((MethPlaceHolder*)Val)->getLineNum();
diff --git a/llvm/lib/AsmParser/llvmAsmParser.y b/llvm/lib/AsmParser/llvmAsmParser.y
index 6852df7..43c69f3 100644
--- a/llvm/lib/AsmParser/llvmAsmParser.y
+++ b/llvm/lib/AsmParser/llvmAsmParser.y
@@ -295,6 +295,10 @@
vector<ValueList> *LateResolver = (CurMeth.CurrentMethod) ?
&CurMeth.LateResolveValues : &CurModule.LateResolveValues;
+ if (const PointerType *PTy = dyn_cast<PointerType>(Ty))
+ if (const MethodType *MTy = dyn_cast<MethodType>(PTy->getValueType()))
+ Ty = MTy; // Convert pointer to method to method type
+
switch (Ty->getPrimitiveID()) {
case Type::LabelTyID: d = new BBPlaceHolder(Ty, D); break;
case Type::MethodTyID: d = new MethPlaceHolder(Ty, D);
@@ -938,8 +942,7 @@
if (Initializer == 0)
ThrowException("Global value initializer is not a constant!");
- GlobalVariable *GV = new GlobalVariable(PointerType::get(Ty), $3,
- Initializer);
+ GlobalVariable *GV = new GlobalVariable(Ty, $3, Initializer);
setValueName(GV, $2);
CurModule.CurrentModule->getGlobalList().push_back(GV);
@@ -953,7 +956,7 @@
"' is not a sized type!");
}
- GlobalVariable *GV = new GlobalVariable(PointerType::get(Ty), $4);
+ GlobalVariable *GV = new GlobalVariable(Ty, $4);
setValueName(GV, $2);
CurModule.CurrentModule->getGlobalList().push_back(GV);
@@ -1031,13 +1034,14 @@
for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); ++I)
ParamTypeList.push_back((*I)->getType());
- const MethodType *MT = MethodType::get(*$1, ParamTypeList);
+ const MethodType *MT = MethodType::get(*$1, ParamTypeList);
+ const PointerType *PMT = PointerType::get(MT);
delete $1;
Method *M = 0;
if (SymbolTable *ST = CurModule.CurrentModule->getSymbolTable()) {
- if (Value *V = ST->lookup(MT, $2)) { // Method already in symtab?
- M = cast<Method>(V);
+ if (Value *V = ST->lookup(PMT, $2)) { // Method already in symtab?
+ M = cast<Method>(V);
// Yes it is. If this is the case, either we need to be a forward decl,
// or it needs to be.
@@ -1274,18 +1278,23 @@
delete $2; // Free the list...
}
| CALL TypesV ValueRef '(' ValueRefListE ')' {
+ const PointerType *PMTy;
const MethodType *Ty;
- if (!(Ty = dyn_cast<MethodType>($2->get()))) {
+ if (!(PMTy = dyn_cast<PointerType>($2->get())) ||
+ !(Ty = dyn_cast<MethodType>(PMTy->getValueType()))) {
// Pull out the types of all of the arguments...
vector<const Type*> ParamTypes;
- for (list<Value*>::iterator I = $5->begin(), E = $5->end(); I != E; ++I)
- ParamTypes.push_back((*I)->getType());
- Ty = MethodType::get(*$2, ParamTypes);
+ if ($5) {
+ for (list<Value*>::iterator I = $5->begin(), E = $5->end(); I != E; ++I)
+ ParamTypes.push_back((*I)->getType());
+ }
+ Ty = MethodType::get($2->get(), ParamTypes);
+ PMTy = PointerType::get(Ty);
}
delete $2;
- Value *V = getVal(Ty, $3); // Get the method we're calling...
+ Value *V = getVal(PMTy, $3); // Get the method we're calling...
// Create the call node...
if (!$5) { // Has no arguments?