[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Sun Dec 5 13:53:42 PST 2004



Changes in directory llvm-java/lib/Compiler:

Compiler.cpp updated: 1.165 -> 1.166
---
Log message:

Fix some issues with vtables. Although not completely correct we can
now compile and run some programs.


---
Diffs of the changes:  (+14 -9)

Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.165 llvm-java/lib/Compiler/Compiler.cpp:1.166
--- llvm-java/lib/Compiler/Compiler.cpp:1.165	Sun Dec  5 03:50:54 2004
+++ llvm-java/lib/Compiler/Compiler.cpp	Sun Dec  5 15:53:31 2004
@@ -607,15 +607,11 @@
       for (VTableInfo::Method2IndexMap::const_iterator
              i = interfaceVI.m2iMap.begin(), e = interfaceVI.m2iMap.end();
            i != e; ++i) {
-        std::vector<llvm::Constant*> indices;
-        indices.reserve(2);
-        indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
         assert(classVI.m2iMap.find(i->first) != classVI.m2iMap.end() &&
                "Interface method not found in class definition!");
         unsigned classMethodIdx = classVI.m2iMap.find(i->first)->second;
-        indices.push_back(ConstantUInt::get(Type::UIntTy, classMethodIdx));
         init[i->second] =
-          ConstantExpr::getGetElementPtr(classVI.vtable, indices);
+          cast<ConstantStruct>(classVI.vtable->getInitializer())->getElementAt(classMethodIdx);
       }
 
       llvm::Constant* vtable = ConstantStruct::get(init);
@@ -624,13 +620,15 @@
         interface->getThisClass()->getName()->str() + "<vtable>";
       module_.addTypeName(globalName, vtable->getType());
 
-      return new GlobalVariable(
+      GlobalVariable* gv = new GlobalVariable(
         vtable->getType(),
         true,
         GlobalVariable::ExternalLinkage,
         vtable,
         globalName,
         &module_);
+
+      return gv;
     }
 
     /// Builds the interfaces vtable array for this classfile and its
@@ -772,9 +770,13 @@
 
           const FunctionType* funcTy = cast<FunctionType>(
             getType(method->getDescriptor(), ClassInfo::ObjectBaseTy));
-          Function* vfun = module_.getOrInsertFunction(funcName, funcTy);
-          if (!method->isAbstract())
-            scheduleFunction(vfun);
+          llvm::Constant* vfun =
+            llvm::Constant::getNullValue(PointerType::get(funcTy));
+          if (!cf->isInterface()) {
+            vfun = module_.getOrInsertFunction(funcName, funcTy);
+            if (!method->isAbstract())
+              scheduleFunction(cast<Function>(vfun));
+          }
 
           unsigned& index = vi.m2iMap[methodDescr];
           if (!index) {
@@ -2419,5 +2421,8 @@
         new ReturnInst(UndefValue::get(F->getReturnType()), entry);
     }
 
+//   for (Module::giterator G = m->gbegin(), E = m->gend(); G != E; ++G)
+//     std::cerr << *G << "\n\n";
+
   return m;
 }






More information about the llvm-commits mailing list