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

Alkis Evlogimenos alkis at cs.uiuc.edu
Tue Mar 29 04:51:08 PST 2005



Changes in directory llvm-java/lib/Compiler:

VMClass.h updated: 1.19 -> 1.20
VMClass.cpp updated: 1.22 -> 1.23
Compiler.cpp updated: 1.263 -> 1.264
---
Log message:

Merge VMClass::getClassForClass() and VMClass::getClassForDescriptor()
into one function VMClass::getClass().


---
Diffs of the changes:  (+30 -42)

 Compiler.cpp |   26 +++++++++++++-------------
 VMClass.cpp  |   43 ++++++++++++++++---------------------------
 VMClass.h    |    3 +--
 3 files changed, 30 insertions(+), 42 deletions(-)


Index: llvm-java/lib/Compiler/VMClass.h
diff -u llvm-java/lib/Compiler/VMClass.h:1.19 llvm-java/lib/Compiler/VMClass.h:1.20
--- llvm-java/lib/Compiler/VMClass.h:1.19	Mon Mar 28 21:10:46 2005
+++ llvm-java/lib/Compiler/VMClass.h	Tue Mar 29 06:50:57 2005
@@ -87,8 +87,7 @@
     int getFieldIndex(const std::string& name) const;
 
     llvm::Constant* getConstant(unsigned index) const;
-    const VMClass* getClassForClass(unsigned index) const;
-    const VMClass* getClassForDescriptor(unsigned index) const;
+    const VMClass* getClass(unsigned index) const;
   };
 
 } } // namespace llvm::Java


Index: llvm-java/lib/Compiler/VMClass.cpp
diff -u llvm-java/lib/Compiler/VMClass.cpp:1.22 llvm-java/lib/Compiler/VMClass.cpp:1.23
--- llvm-java/lib/Compiler/VMClass.cpp:1.22	Mon Mar 28 21:10:46 2005
+++ llvm-java/lib/Compiler/VMClass.cpp	Tue Mar 29 06:50:57 2005
@@ -100,7 +100,7 @@
         // FIXME: Initialize static VMFields as well.
       }
       else {
-        const VMClass* fc = getClassForDescriptor(field->getDescriptorIndex());
+        const VMClass* fc = getClass(field->getDescriptorIndex());
         FieldMap::iterator i =
           fieldMap_.insert(std::make_pair(
                              field->getName()->str(),
@@ -136,8 +136,7 @@
     // This is any class but java/lang/Object.
     if (classFile_->getSuperClass()) {
       // Our direct super class.
-      const VMClass* superClass =
-        getClassForClass(classFile_->getSuperClassIndex());
+      const VMClass* superClass = getClass(classFile_->getSuperClassIndex());
 
       // Add the interfaces of our direct superclass.
       for (unsigned i = 0, e = superClass->getNumInterfaces(); i != e; ++i)
@@ -164,8 +163,7 @@
     // For each of the interfaces we implement, load it and add that
     // interface and all the interfaces it inherits from.
     for (unsigned i = 0, e = classFile_->getNumInterfaces(); i != e; ++i) {
-      const VMClass* interface =
-        getClassForClass(classFile_->getInterfaceIndex(i));
+      const VMClass* interface = getClass(classFile_->getInterfaceIndex(i));
       interfaces_.push_back(interface);
       for (unsigned j = 0, f = interface->getNumInterfaces(); j != f; ++j)
         interfaces_.push_back(interface->getInterface(j));
@@ -225,33 +223,24 @@
   return static_cast<llvm::Constant*>(resolvedConstantPool_[index]);
 }
 
-const VMClass* VMClass::getClassForClass(unsigned index) const
+const VMClass* VMClass::getClass(unsigned index) const
 {
   assert(classFile_ && "No constant pool!");
-  assert(dynamic_cast<ConstantClass*>(classFile_->getConstant(index)) &&
-         "Not an index to a class reference!");
+  assert((dynamic_cast<ConstantClass*>(classFile_->getConstant(index)) ||
+          dynamic_cast<ConstantUtf8*>(classFile_->getConstant(index))) &&
+         "Not an index to a class or descriptor reference!");
 
   // If we haven't resolved this constant already, do so now.
   if (!resolvedConstantPool_[index]) {
-    ConstantClass* jc = classFile_->getConstantClass(index);
-    resolvedConstantPool_[index] =
-      const_cast<VMClass*>(resolver_->getClass(jc->getName()->str()));
-  }
-
-  return static_cast<const VMClass*>(resolvedConstantPool_[index]);
-}
-
-const VMClass* VMClass::getClassForDescriptor(unsigned index) const
-{
-  assert(classFile_ && "No constant pool!");
-  assert(dynamic_cast<ConstantUtf8*>(classFile_->getConstant(index)) &&
-         "Not an index to a descriptor reference!");
-
-  // If we haven't resolved this constant already, do so now.
-  if (!resolvedConstantPool_[index]) {
-    ConstantUtf8* jc = classFile_->getConstantUtf8(index);
-    resolvedConstantPool_[index] =
-      const_cast<VMClass*>(resolver_->getClassForDesc(jc->str()));
+    Constant* jc = classFile_->getConstant(index);
+    if (ConstantClass* c = dynamic_cast<ConstantClass*>(jc))
+      resolvedConstantPool_[index] =
+        const_cast<VMClass*>(resolver_->getClass(c->getName()->str()));
+    else if (ConstantUtf8* d = dynamic_cast<ConstantUtf8*>(jc))
+      resolvedConstantPool_[index] =
+        const_cast<VMClass*>(resolver_->getClassForDesc(d->str()));
+    else
+      assert(0 && "Not a class!");
   }
 
   return static_cast<const VMClass*>(resolvedConstantPool_[index]);


Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.263 llvm-java/lib/Compiler/Compiler.cpp:1.264
--- llvm-java/lib/Compiler/Compiler.cpp:1.263	Mon Mar 28 17:56:46 2005
+++ llvm-java/lib/Compiler/Compiler.cpp	Tue Mar 29 06:50:57 2005
@@ -797,9 +797,9 @@
 
       const std::string& className = fieldRef->getClass()->getName()->str();
       GlobalVariable* global = getStaticField(
-        class_->getClassForClass(fieldRef->getClassIndex()),
+        class_->getClass(fieldRef->getClassIndex()),
         nameAndType->getName()->str(),
-        class_->getClassForDescriptor(nameAndType->getDescriptorIndex()));
+        class_->getClass(nameAndType->getDescriptorIndex()));
 
       assert(global && "Cannot find global for static field!");
 
@@ -852,7 +852,7 @@
         class_->getClassFile()->getConstantFieldRef(index);
       ConstantNameAndType* nameAndType = fieldRef->getNameAndType();
       return getField(
-        class_->getClassForClass(fieldRef->getClassIndex()),
+        class_->getClass(fieldRef->getClassIndex()),
         nameAndType->getName()->str(),
         ptr);
     }
@@ -1102,7 +1102,7 @@
           Field* field = fields[i];
           if (field->isStatic()) {
             const VMClass* fieldClass =
-              clazz->getClassForDescriptor(field->getDescriptorIndex());
+              clazz->getClass(field->getDescriptorIndex());
             const Type* globalTy = fieldClass->getType();
             // A java field can be final/constant even if it has a
             // dynamic initializer. Because LLVM does not currently
@@ -1636,7 +1636,7 @@
     void do_putfield(unsigned index) {
       ConstantFieldRef* fieldRef =
         class_->getClassFile()->getConstantFieldRef(index);
-      const VMClass* fieldClass = class_->getClassForDescriptor(
+      const VMClass* fieldClass = class_->getClass(
         fieldRef->getNameAndType()->getDescriptorIndex());
       const Type* type = fieldClass->getType();
       Value* v = pop(type);
@@ -1691,7 +1691,7 @@
       const std::string& className = methodRef->getClass()->getName()->str();
 
       const VMClass* clazz =
-        class_->getClassForClass(methodRef->getClassIndex());
+        class_->getClass(methodRef->getClassIndex());
       const VTableInfo* vi = getVTableInfoGeneric(clazz);
 
       const std::string& methodDescr =
@@ -1734,7 +1734,7 @@
         methodName + nameAndType->getDescriptor()->str();
       std::string funcName = className + '/' + methodDescr;
       const VMClass* clazz =
-        class_->getClassForClass(methodRef->getClassIndex());
+        class_->getClass(methodRef->getClassIndex());
 
       const FunctionType* funcTy = cast<FunctionType>(
         resolver_->getType(nameAndType->getDescriptor()->str(), true));
@@ -1747,7 +1747,7 @@
       ConstantMethodRef* methodRef =
         class_->getClassFile()->getConstantMethodRef(index);
       const VMClass* clazz =
-        class_->getClassForClass(methodRef->getClassIndex());
+        class_->getClass(methodRef->getClassIndex());
       emitStaticInitializers(clazz->getClassFile());
       Method* method = getMethod(methodRef);
       Function* function = getFunction(method);
@@ -1775,7 +1775,7 @@
       const std::string& className = methodRef->getClass()->getName()->str();
 
       const VMClass* clazz =
-        class_->getClassForClass(methodRef->getClassIndex());
+        class_->getClass(methodRef->getClassIndex());
       const VTableInfo* vi = getVTableInfoGeneric(clazz);
 
       const std::string& methodDescr =
@@ -1848,7 +1848,7 @@
     }
 
     void do_new(unsigned index) {
-      const VMClass* clazz = class_->getClassForClass(index);
+      const VMClass* clazz = class_->getClass(index);
       emitStaticInitializers(clazz->getClassFile());
       const VTableInfo& vi = getVTableInfo(clazz);
 
@@ -1937,7 +1937,7 @@
     void do_anewarray(unsigned index) {
       Value* count = pop(Type::UIntTy);
 
-      const VMClass* clazz = class_->getClassForClass(index);
+      const VMClass* clazz = class_->getClass(index);
       const VMClass* arrayClass = resolver_->getArrayClass(clazz);
       const VTableInfo* vi = getVTableInfoGeneric(arrayClass);
 
@@ -1959,7 +1959,7 @@
     }
 
     void do_checkcast(unsigned index) {
-      const VMClass* clazz = class_->getClassForClass(index);
+      const VMClass* clazz = class_->getClass(index);
       const VTableInfo* vi = getVTableInfoGeneric(clazz);
 
       Value* objRef = pop(resolver_->getObjectBaseType());
@@ -1976,7 +1976,7 @@
     }
 
     void do_instanceof(unsigned index) {
-      const VMClass* clazz = class_->getClassForClass(index);
+      const VMClass* clazz = class_->getClass(index);
       const VTableInfo* vi = getVTableInfoGeneric(clazz);
 
       Value* objRef = pop(resolver_->getObjectBaseType());






More information about the llvm-commits mailing list