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

Alkis Evlogimenos alkis at cs.uiuc.edu
Thu Jan 27 11:56:22 PST 2005



Changes in directory llvm-java/lib/Compiler:

Compiler.cpp updated: 1.201 -> 1.202
---
Log message:

Teach ClassInfo how to resolve to its real type and keep track of its
elements. This removes a bit of code from initializeClassInfo(),
getClassInfo() and buildArrayClassInfo().


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

 Compiler.cpp |   74 +++++++++++++++++++++++++----------------------------------
 1 files changed, 32 insertions(+), 42 deletions(-)


Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.201 llvm-java/lib/Compiler/Compiler.cpp:1.202
--- llvm-java/lib/Compiler/Compiler.cpp:1.201	Thu Jan 27 13:17:54 2005
+++ llvm-java/lib/Compiler/Compiler.cpp	Thu Jan 27 13:56:11 2005
@@ -88,22 +88,30 @@
       unsigned interfaceIdx_;
       typedef std::map<std::string, int> Field2IndexMap;
       Field2IndexMap f2iMap_;
+      typedef std::vector<const Type*> ElementTypes;
+      ElementTypes elementTypes;
 
     public:
       static unsigned InterfaceCount;
 
     public:
-      ClassInfo() : type_(NULL), interfaceIdx_(0) { }
-      void setType(Type* type) { type_ = type; }
+      ClassInfo() : type_(OpaqueType::get()), interfaceIdx_(0) { }
       Type* getType() { return type_; }
       const Type* getType() const { return type_; }
-      void addField(const std::string& name, int slot) {
-        f2iMap_.insert(std::make_pair(name, slot));
+      void addField(const std::string& name, const Type* type) {
+        f2iMap_.insert(std::make_pair(name, elementTypes.size()));
+        elementTypes.push_back(type);
       }
       int getFieldIndex(const std::string& name) const {
         Field2IndexMap::const_iterator it = f2iMap_.find(name);
         return it == f2iMap_.end() ? -1 : it->second;
       }
+      void resolveType() {
+        PATypeHolder holder = type_;
+        Type* resolvedType = StructType::get(elementTypes);
+        cast<OpaqueType>(type_)->refineAbstractTypeTo(resolvedType);
+        type_ = holder.get();
+      }
       unsigned getInterfaceIndex() const { return interfaceIdx_; }
       void setInterfaceIndex(unsigned index) { interfaceIdx_ = index; }
     };
@@ -312,37 +320,28 @@
 
       module_.addTypeName(LLVM_JAVA_OBJECT_BASE, ObjectBaseTy);
 
-      assert(!ci.getType() &&
+      assert(isa<OpaqueType>(ci.getType()) &&
              "java/lang/Object ClassInfo should not be initialized!");
 
-      ci.setType(OpaqueType::get());
-
-      std::vector<const Type*> elements;
-
       // Because this is java/lang/Object, we add the opaque
       // llvm_java_object_base type first.
-      ci.addField(LLVM_JAVA_OBJECT_BASE, elements.size());
-      elements.push_back(ObjectBaseTy);
+      ci.addField(LLVM_JAVA_OBJECT_BASE, ObjectBaseTy);
 
       const Fields& fields = cf->getFields();
       for (unsigned i = 0, e = fields.size(); i != e; ++i) {
         Field* field = fields[i];
-        if (!field->isStatic()) {
-          ci.addField(field->getName()->str(), elements.size());
-          elements.push_back(getType(field->getDescriptor()));
-        }
+        if (!field->isStatic())
+          ci.addField(field->getName()->str(), getType(field->getDescriptor()));
       }
 
-      PATypeHolder holder = ci.getType();
-      cast<OpaqueType>(ci.getType())->
-        refineAbstractTypeTo(StructType::get(elements));
-      ci.setType(holder.get());
+      ci.resolveType();
 
       DEBUG(std::cerr << "Adding java/lang/Object = "
             << *ci.getType() << " to type map\n");
       module_.addTypeName("java/lang/Object", ci.getType());
 
-      assert(ci.getType() && "ClassInfo not initialized properly!");
+      assert(!isa<OpaqueType>(ci.getType()) &&
+             "ClassInfo not initialized properly!");
       emitStaticInitializers(cf);
       DEBUG(std::cerr << "Built ClassInfo for: java/lang/Object\n");
       return true;
@@ -455,35 +454,30 @@
       DEBUG(std::cerr << "Building ClassInfo for: " << className << '\n');
       ClassInfo& ci = c2ciMap_[cf];
 
-      assert(!ci.getType() && "got already initialized ClassInfo!");
+      assert(isa<OpaqueType>(ci.getType()) &&
+             "got already initialized ClassInfo!");
 
       // Get the interface id.
       if (cf->isInterface())
         ci.setInterfaceIndex(ClassInfo::InterfaceCount++);
 
-      ci.setType(OpaqueType::get());
-
-      std::vector<const Type*> elements;
       ConstantClass* super = cf->getSuperClass();
       assert(super && "Class does not have superclass!");
       const ClassInfo& superCI =
         getClassInfo(ClassFile::get(super->getName()->str()));
-      elements.push_back(superCI.getType());
+      ci.addField("super", superCI.getType());
 
       const Fields& fields = cf->getFields();
       for (unsigned i = 0, e = fields.size(); i != e; ++i) {
         Field* field = fields[i];
-        if (!field->isStatic()) {
-          ci.addField(field->getName()->str(), elements.size());
-          elements.push_back(getType(field->getDescriptor()));
-        }
+        if (!field->isStatic())
+          ci.addField(field->getName()->str(), getType(field->getDescriptor()));
       }
-      PATypeHolder holder = ci.getType();
-      cast<OpaqueType>(ci.getType())->
-        refineAbstractTypeTo(StructType::get(elements));
-      ci.setType(holder.get());
 
-      assert(ci.getType() && "ClassInfo not initialized properly!");
+      ci.resolveType();
+
+      assert(!isa<OpaqueType>(ci.getType()) &&
+             "ClassInfo not initialized properly!");
       DEBUG(std::cerr << "Adding " << className << " = "
             << *ci.getType() << " to type map\n");
       module_.addTypeName(className, ci.getType());
@@ -497,15 +491,11 @@
     ClassInfo buildArrayClassInfo(Type* elementTy) {
       ClassInfo arrayInfo;
 
-      std::vector<const Type*> elements;
-      elements.reserve(3);
-      elements.push_back(ObjectBaseTy);
-      elements.push_back(Type::UIntTy);
-      arrayInfo.addField("<length>", elements.size());
-      elements.push_back(ArrayType::get(elementTy, 0));
-      arrayInfo.addField("<data>", elements.size());
+      arrayInfo.addField("super", ObjectBaseTy);
+      arrayInfo.addField("<length>", Type::UIntTy);
+      arrayInfo.addField("<data>", ArrayType::get(elementTy, 0));
 
-      arrayInfo.setType(StructType::get(elements));
+      arrayInfo.resolveType();
 
       return arrayInfo;
     }






More information about the llvm-commits mailing list