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

Alkis Evlogimenos alkis at cs.uiuc.edu
Mon Mar 28 19:10:56 PST 2005



Changes in directory llvm-java/lib/Compiler:

VMField.h added (r1.1)
VMField.cpp added (r1.1)
VMClass.h updated: 1.18 -> 1.19
VMClass.cpp updated: 1.21 -> 1.22
---
Log message:

Add VMField class that represents a member or static field in a
class. This will allow us to resolve and cache field references.


---
Diffs of the changes:  (+113 -10)

 VMClass.cpp |   21 +++++++++++-------
 VMClass.h   |    4 +--
 VMField.cpp |   28 ++++++++++++++++++++++++
 VMField.h   |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 113 insertions(+), 10 deletions(-)


Index: llvm-java/lib/Compiler/VMField.h
diff -c /dev/null llvm-java/lib/Compiler/VMField.h:1.1
*** /dev/null	Mon Mar 28 21:10:56 2005
--- llvm-java/lib/Compiler/VMField.h	Mon Mar 28 21:10:46 2005
***************
*** 0 ****
--- 1,70 ----
+ //===-- VMField.h - Compiler representation of a Java field -----*- C++ -*-===//
+ //
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file contains the declaration of the Field class that represents a
+ // compile time representation of a Java class field (java.lang.Field).
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #ifndef LLVM_JAVA_VMFIELD_H
+ #define LLVM_JAVA_VMFIELD_H
+ 
+ #include <llvm/Java/ClassFile.h>
+ 
+ namespace llvm {
+ 
+   class GlobalVariable;
+ 
+ }
+ 
+ namespace llvm { namespace Java {
+ 
+   class VMClass;
+ 
+   class VMField {
+     const VMClass* clazz_;
+     const Field* field_;
+     union {
+       int index;
+       GlobalVariable* global;
+     } data_;
+ 
+     friend class VMClass;
+     // Interface for VMClass.
+ 
+     // Create static field reference.
+     VMField(const VMClass* clazz, const Field* field);
+ 
+     // Create member field reference.
+     VMField(const VMClass* clazz, const Field* field, int index)
+       : clazz_(clazz),
+         field_(field) {
+       assert(!isStatic() && "This should be a member field!");
+       data_.index = index;
+     }
+ 
+ 
+   public:
+     const std::string& getName() const { return field_->getName()->str(); }
+     bool isStatic() const { return field_->isStatic(); }
+ 
+     const VMClass* getClass() const { return clazz_; }
+     int getMemberIndex() const {
+       assert(!isStatic() && "Field should not be static!");
+       return data_.index;
+     }
+     GlobalVariable* getGlobal() const {
+       assert(isStatic() && "Field should be static!");
+       return data_.global;
+     }
+   };
+ 
+ } } // namespace llvm::Java
+ 
+ #endif//LLVM_JAVA_VMFIELD_H


Index: llvm-java/lib/Compiler/VMField.cpp
diff -c /dev/null llvm-java/lib/Compiler/VMField.cpp:1.1
*** /dev/null	Mon Mar 28 21:10:56 2005
--- llvm-java/lib/Compiler/VMField.cpp	Mon Mar 28 21:10:46 2005
***************
*** 0 ****
--- 1,28 ----
+ //===-- VMField.cpp - Compiler representation of a Java field ---*- C++ -*-===//
+ //
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file contains the implementation of the Field class that represents a
+ // compile time representation of a Java class field (java.lang.Field).
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include "VMField.h"
+ #include "VMClass.h"
+ #include <iostream>
+ 
+ using namespace llvm;
+ using namespace llvm::Java;
+ 
+ VMField::VMField(const VMClass* clazz, const Field* field)
+   : clazz_(clazz),
+     field_(field)
+ {
+   assert(isStatic() && "This should be a static field!");
+   // FIXME: add Global to module.
+ }


Index: llvm-java/lib/Compiler/VMClass.h
diff -u llvm-java/lib/Compiler/VMClass.h:1.18 llvm-java/lib/Compiler/VMClass.h:1.19
--- llvm-java/lib/Compiler/VMClass.h:1.18	Mon Mar 28 20:49:46 2005
+++ llvm-java/lib/Compiler/VMClass.h	Mon Mar 28 21:10:46 2005
@@ -38,8 +38,8 @@
     Type* layoutType_;
     const Type* type_;
     unsigned interfaceIndex_;
-    typedef std::map<std::string, int> Field2IndexMap;
-    Field2IndexMap f2iMap_;
+    typedef std::map<std::string, VMField> FieldMap;
+    FieldMap fieldMap_;
     mutable std::vector<void*> resolvedConstantPool_;
     std::vector<const VMClass*> superClasses_;
     std::vector<const VMClass*> interfaces_;


Index: llvm-java/lib/Compiler/VMClass.cpp
diff -u llvm-java/lib/Compiler/VMClass.cpp:1.21 llvm-java/lib/Compiler/VMClass.cpp:1.22
--- llvm-java/lib/Compiler/VMClass.cpp:1.21	Mon Mar 28 20:49:46 2005
+++ llvm-java/lib/Compiler/VMClass.cpp	Mon Mar 28 21:10:46 2005
@@ -71,8 +71,8 @@
 }
 
 int VMClass::getFieldIndex(const std::string& name) const {
-  Field2IndexMap::const_iterator it = f2iMap_.find(name);
-  return it == f2iMap_.end() ? -1 : it->second;
+  FieldMap::const_iterator it = fieldMap_.find(name);
+  return it == fieldMap_.end() ? -1 : it->second.getMemberIndex();
 }
 
 void VMClass::computeLayout() {
@@ -96,12 +96,17 @@
     const Fields& fields = classFile_->getFields();
     for (unsigned i = 0, e = fields.size(); i != e; ++i) {
       Field* field = fields[i];
-      if (!field->isStatic()) {
-        memberFields_.push_back(NULL);
-        f2iMap_.insert(std::make_pair(field->getName()->str(),
-                                      memberFields_.size()));
-        layout.push_back(
-          getClassForDescriptor(field->getDescriptorIndex())->getType());
+      if (field->isStatic()) {
+        // FIXME: Initialize static VMFields as well.
+      }
+      else {
+        const VMClass* fc = getClassForDescriptor(field->getDescriptorIndex());
+        FieldMap::iterator i =
+          fieldMap_.insert(std::make_pair(
+                             field->getName()->str(),
+                             VMField(fc, field, memberFields_.size()+1))).first;
+        memberFields_.push_back(&i->second);
+        layout.push_back(fc->getType());
       }
     }
   }






More information about the llvm-commits mailing list