[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Mon Jan 24 05:33:37 PST 2005
Changes in directory llvm-java/lib/Compiler:
Compiler.cpp updated: 1.189 -> 1.190
---
Log message:
For each interface recursively add all methods from the interfaces it
inherits from.
---
Diffs of the changes: (+40 -10)
Compiler.cpp | 50 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 40 insertions(+), 10 deletions(-)
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.189 llvm-java/lib/Compiler/Compiler.cpp:1.190
--- llvm-java/lib/Compiler/Compiler.cpp:1.189 Sun Jan 23 08:40:25 2005
+++ llvm-java/lib/Compiler/Compiler.cpp Mon Jan 24 07:33:26 2005
@@ -107,6 +107,8 @@
GlobalVariable* vtable;
std::vector<llvm::Constant*> superVtables;
typedef std::map<std::string, unsigned> Method2IndexMap;
+ typedef Method2IndexMap::iterator iterator;
+ typedef Method2IndexMap::const_iterator const_iterator;
Method2IndexMap m2iMap;
static Type* VTableBaseTy;
@@ -746,18 +748,46 @@
std::copy(superVI.superVtables.begin(), superVI.superVtables.end(),
std::back_inserter(vi.superVtables));
- // Copy all the constants from the super class' vtable.
- assert(superVI.vtable && "No vtable found for super class!");
- ConstantStruct* superInit =
- cast<ConstantStruct>(superVI.vtable->getInitializer());
- std::vector<llvm::Constant*> init(superInit->getNumOperands());
+ std::vector<llvm::Constant*> init(1);
// Use a null typeinfo struct for now.
init[0] = llvm::Constant::getNullValue(VTableInfo::TypeInfoTy);
- // Fill in the function pointers as they are in the super
- // class. Overriden methods will be replaced later.
- for (unsigned i = 1, e = superInit->getNumOperands(); i != e; ++i)
- init[i] = superInit->getOperand(i);
- vi.m2iMap = superVI.m2iMap;
+
+ // If this is an interface, add all methods from each interface
+ // this inherits from.
+ if (cf->isInterface()) {
+ const Classes& ifaces = cf->getInterfaces();
+ for (unsigned i = 0, e = ifaces.size(); i != e; ++i) {
+ ClassFile* ifaceCF = ClassFile::get(ifaces[i]->getName()->str());
+ const VTableInfo& ifaceVI = getVTableInfo(ifaceCF);
+ ConstantStruct* ifaceInit =
+ cast<ConstantStruct>(ifaceVI.vtable->getInitializer());
+ for (VTableInfo::const_iterator MI = ifaceVI.m2iMap.begin(),
+ ME = ifaceVI.m2iMap.end(); MI != ME; ++MI) {
+ const std::string& methodDescr = MI->first;
+ unsigned slot = MI->second;
+
+ unsigned& index = vi.m2iMap[methodDescr];
+ if (!index) {
+ index = init.size();
+ init.resize(index + 1);
+ }
+ init[index] = ifaceInit->getOperand(slot);
+ }
+ }
+ }
+ // Otherwise this is a class, so add all methods from its super
+ // class.
+ else {
+ assert(superVI.vtable && "No vtable found for super class!");
+ ConstantStruct* superInit =
+ cast<ConstantStruct>(superVI.vtable->getInitializer());
+ // Fill in the function pointers as they are in the super
+ // class. Overriden methods will be replaced later.
+ init.resize(superInit->getNumOperands());
+ for (unsigned i = 1, e = superInit->getNumOperands(); i != e; ++i)
+ init[i] = superInit->getOperand(i);
+ vi.m2iMap = superVI.m2iMap;
+ }
// Add member functions to the vtable.
const Methods& methods = cf->getMethods();
More information about the llvm-commits
mailing list