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

Alkis Evlogimenos alkis at cs.uiuc.edu
Mon Jan 24 05:42:12 PST 2005



Changes in directory llvm-java/lib/Compiler:

Compiler.cpp updated: 1.190 -> 1.191
---
Log message:

For each interface a class implements, add an interface vtable for
that interface and all the interfaces that interface inherits from
(recursively).

This fixes MultipleInterfaces.java.


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

 Compiler.cpp |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)


Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.190 llvm-java/lib/Compiler/Compiler.cpp:1.191
--- llvm-java/lib/Compiler/Compiler.cpp:1.190	Mon Jan 24 07:33:26 2005
+++ llvm-java/lib/Compiler/Compiler.cpp	Mon Jan 24 07:42:01 2005
@@ -628,6 +628,24 @@
       return ConstantExpr::getCast(gv, PointerType::get(VTableInfo::VTableTy));
     }
 
+    void insertVtablesForInterface(std::vector<llvm::Constant*>& vtables,
+                                   ClassFile* cf,
+                                   ClassFile* ifaceCf) {
+      static llvm::Constant* nullVTable =
+        llvm::Constant::getNullValue(PointerType::get(VTableInfo::VTableTy));
+
+      assert(ifaceCf->isInterface() && "Classfile must be an interface!");
+      const ClassInfo& ifaceCi = getClassInfo(ifaceCf);
+      if (ifaceCi.interfaceIdx >= vtables.size())
+        vtables.resize(ifaceCi.interfaceIdx+1, nullVTable);
+      vtables[ifaceCi.interfaceIdx] = buildInterfaceVTable(cf, ifaceCf);
+      const Classes& interfaces = ifaceCf->getInterfaces();
+      for (unsigned i = 0, e = interfaces.size(); i != e; ++i) {
+        ClassFile* otherCf = ClassFile::get(interfaces[i]->getName()->str());
+        insertVtablesForInterface(vtables, cf, otherCf);
+      }
+    }
+
     /// Builds the interfaces vtable array for this classfile and its
     /// corresponding VTableInfo. If this classfile is an interface we
     /// return a pointer to 0xFFFFFFFF.
@@ -657,15 +675,8 @@
       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);
+          ClassFile* ifaceCf = ClassFile::get(interfaces[i]->getName()->str());
+          insertVtablesForInterface(vtables, cf, ifaceCf);
         }
         if (!curCf->getSuperClass())
           break;






More information about the llvm-commits mailing list