[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Sun Dec 5 23:57:29 PST 2004
Changes in directory llvm-java/lib/Compiler:
Compiler.cpp updated: 1.168 -> 1.169
---
Log message:
Make interface calls work.
---
Diffs of the changes: (+29 -19)
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.168 llvm-java/lib/Compiler/Compiler.cpp:1.169
--- llvm-java/lib/Compiler/Compiler.cpp:1.168 Sun Dec 5 19:00:46 2004
+++ llvm-java/lib/Compiler/Compiler.cpp Mon Dec 6 01:57:18 2004
@@ -628,7 +628,7 @@
globalName,
&module_);
- return gv;
+ return ConstantExpr::getCast(gv, PointerType::get(VTableInfo::VTableTy));
}
/// Builds the interfaces vtable array for this classfile and its
@@ -648,37 +648,46 @@
PointerType::get(PointerType::get(VTableInfo::VTableTy))));
// Otherwise we must fill in the interfaces vtables array. For
- // each implemented vtable we insert a pointer to the
+ // each implemented interface we insert a pointer to the
// <class,interface> vtable for this class. Note that we only
// fill in up to the highest index of the implemented
// interfaces.
std::vector<llvm::Constant*> vtables;
- const Classes& interfaces = cf->getInterfaces();
llvm::Constant* nullVTable =
llvm::Constant::getNullValue(PointerType::get(VTableInfo::VTableTy));
- for (unsigned i = 0, e = interfaces.size(); i != e; ++i) {
- ClassFile* interface = ClassFile::get(interfaces[i]->getName()->str());
- assert(interface->isInterface() &&
- "Class in interfaces list is not an interface!");
- const ClassInfo& interfaceCI = getClassInfo(interface);
- if (interfaceCI.interfaceIdx >= vtables.size())
- vtables.resize(interfaceCI.interfaceIdx+1, nullVTable);
- vtables[interfaceCI.interfaceIdx] = buildInterfaceVTable(cf, interface);
+ ClassFile* curCf = cf;
+ while (true) {
+ const Classes& interfaces = curCf->getInterfaces();
+ for (unsigned i = 0, e = interfaces.size(); i != e; ++i) {
+ ClassFile* interface =
+ ClassFile::get(interfaces[i]->getName()->str());
+ assert(interface->isInterface() &&
+ "Class in interfaces list is not an interface!");
+ const ClassInfo& interfaceCI = getClassInfo(interface);
+ if (interfaceCI.interfaceIdx >= vtables.size())
+ vtables.resize(interfaceCI.interfaceIdx+1, nullVTable);
+ vtables[interfaceCI.interfaceIdx] =
+ buildInterfaceVTable(cf, interface);
+ }
+ if (!curCf->getSuperClass())
+ break;
+ curCf = ClassFile::get(curCf->getSuperClass()->getName()->str());
}
- ArrayType* interfacesArrayTy =
- ArrayType::get(PointerType::get(VTableInfo::VTableTy), vtables.size());
-
const std::string& globalName =
cf->getThisClass()->getName()->str() + "<interfacesvtables>";
- module_.addTypeName(globalName, interfacesArrayTy);
+
+ llvm::Constant* init = ConstantArray::get(
+ ArrayType::get(PointerType::get(VTableInfo::VTableTy), vtables.size()),
+ vtables);
+ module_.addTypeName(globalName, init->getType());
GlobalVariable* interfacesArray = new GlobalVariable(
- interfacesArrayTy,
+ init->getType(),
true,
GlobalVariable::ExternalLinkage,
- ConstantArray::get(interfacesArrayTy, vtables),
+ init,
globalName,
&module_);
@@ -2191,11 +2200,12 @@
interfaceVTable =
new CastInst(interfaceVTable, vi->vtable->getType(), TMP, currentBB_);
// Get the function pointer.
- indices.resize(1);
assert(vi->m2iMap.find(methodDescr) != vi->m2iMap.end() &&
"could not find slot for virtual function!");
unsigned vSlot = vi->m2iMap.find(methodDescr)->second;
- indices.push_back(ConstantUInt::get(Type::UIntTy, vSlot));
+ indices.resize(2);
+ indices[0] = ConstantUInt::get(Type::UIntTy, 0);
+ indices[1] = ConstantUInt::get(Type::UIntTy, vSlot);
Value* vfunPtr =
new GetElementPtrInst(interfaceVTable, indices, TMP, currentBB_);
Value* vfun = new LoadInst(vfunPtr, className + '/' + methodDescr,
More information about the llvm-commits
mailing list