[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Class.h Class.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Thu Mar 24 05:38:43 PST 2005
Changes in directory llvm-java/lib/Compiler:
Compiler.cpp updated: 1.242 -> 1.243
Class.h updated: 1.1 -> 1.2
Class.cpp updated: 1.1 -> 1.2
---
Log message:
Add superclass pointer to each Class object.
---
Diffs of the changes: (+28 -21)
Class.cpp | 19 ++++++++++++++-----
Class.h | 2 ++
Compiler.cpp | 28 ++++++++++++----------------
3 files changed, 28 insertions(+), 21 deletions(-)
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.242 llvm-java/lib/Compiler/Compiler.cpp:1.243
--- llvm-java/lib/Compiler/Compiler.cpp:1.242 Wed Mar 23 22:47:47 2005
+++ llvm-java/lib/Compiler/Compiler.cpp Thu Mar 24 07:38:30 2005
@@ -65,7 +65,7 @@
std::auto_ptr<BasicBlockBuilder> bbBuilder_;
std::list<BasicBlock*> bbWorkList_;
typedef std::map<BasicBlock*, unsigned> OpStackDepthMap;
- OpStackDepthMap opStackDepthMap_;
+ OpStackDepthMap opStackDepthMap_;
typedef std::map<std::string, GlobalVariable*> StringMap;
StringMap stringMap_;
BasicBlock* currentBB_;
@@ -179,7 +179,7 @@
init,
str + ".str",
&module_);
-
+
std::vector<Value*> params;
params.reserve(4);
params.clear();
@@ -196,7 +196,7 @@
// Create a new java/lang/String object.
Value* objRef = allocateObject(ci, vi, ip);
-
+
// Initialize it: call java/lang/String/<init>(byte[],int)
Method* method = getMethod("java/lang/String/<init>([BI)V");
Function* function = getFunction(method);
@@ -210,7 +210,7 @@
new CallInst(function, params, "", ip);
return objRef;
- }
+ }
Value* getConstantString(ConstantString* s) {
const std::string& str = s->getValue()->str();
@@ -362,8 +362,6 @@
const Methods& methods = cf->getMethods();
- const Class& ci = resolver_->getClass("java/lang/Object");
-
// Add member functions to the vtable.
for (unsigned i = 0, e = methods.size(); i != e; ++i) {
Method* method = methods[i];
@@ -1087,29 +1085,27 @@
Value* getField(unsigned index, Value* ptr) {
ConstantFieldRef* fieldRef = cf_->getConstantFieldRef(index);
ConstantNameAndType* nameAndType = fieldRef->getNameAndType();
- return getField(fieldRef->getClass()->getName()->str(),
- nameAndType->getName()->str(),
- ptr);
+ return getField(
+ &resolver_->getClass(fieldRef->getClass()->getName()->str()),
+ nameAndType->getName()->str(),
+ ptr);
}
/// Emits the necessary code to get a field from the passed
/// pointer to an object.
- Value* getField(std::string className,
+ Value* getField(const Class* clazz,
const std::string& fieldName,
Value* ptr) {
// Cast ptr to correct type.
- ptr = new CastInst(ptr, resolver_->getClass(className).getType(),
- TMP, currentBB_);
+ ptr = new CastInst(ptr, clazz->getType(), TMP, currentBB_);
// Deref pointer.
std::vector<Value*> indices(1, ConstantUInt::get(Type::UIntTy, 0));
while (true) {
- const Class& clazz = resolver_->getClass(className);
- int slot = clazz.getFieldIndex(fieldName);
+ int slot = clazz->getFieldIndex(fieldName);
if (slot == -1) {
- className =
- ClassFile::get(className)->getSuperClass()->getName()->str();
indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
+ clazz = clazz->getSuperClass();
}
else {
indices.push_back(ConstantUInt::get(Type::UIntTy, slot));
Index: llvm-java/lib/Compiler/Class.h
diff -u llvm-java/lib/Compiler/Class.h:1.1 llvm-java/lib/Compiler/Class.h:1.2
--- llvm-java/lib/Compiler/Class.h:1.1 Wed Mar 23 22:47:47 2005
+++ llvm-java/lib/Compiler/Class.h Thu Mar 24 07:38:30 2005
@@ -28,6 +28,7 @@
static const unsigned INVALID_INTERFACE_INDEX = 0xFFFFFFFF;
Resolver* resolver_;
+ const Class* superClass_;
const Class* componentClass_;
Type* structType_;
const Type* type_;
@@ -56,6 +57,7 @@
public:
const Type* getStructType() const { return structType_; }
const Type* getType() const { return type_; }
+ const Class* getSuperClass() const { return superClass_; }
const Class* getComponentClass() const { return componentClass_; }
bool isArray() const { return componentClass_; }
unsigned getInterfaceIndex() const { return interfaceIndex_; }
Index: llvm-java/lib/Compiler/Class.cpp
diff -u llvm-java/lib/Compiler/Class.cpp:1.1 llvm-java/lib/Compiler/Class.cpp:1.2
--- llvm-java/lib/Compiler/Class.cpp:1.1 Wed Mar 23 22:47:47 2005
+++ llvm-java/lib/Compiler/Class.cpp Thu Mar 24 07:38:30 2005
@@ -27,6 +27,7 @@
Class::Class(Resolver& resolver)
: resolver_(&resolver),
+ superClass_(NULL),
componentClass_(NULL),
structType_(OpaqueType::get()),
type_(PointerType::get(structType_)),
@@ -37,6 +38,7 @@
Class::Class(Resolver& resolver, const Type* type)
: resolver_(&resolver),
+ superClass_(NULL),
componentClass_(NULL),
structType_(0),
type_(type),
@@ -68,9 +70,6 @@
{
const ClassFile* cf = ClassFile::get(className);
- if (cf->isInterface())
- interfaceIndex_ = resolver_->getNextInterfaceIndex();
-
// This is any class but java/lang/Object.
if (cf->getSuperClass()) {
const Class& superClass =
@@ -78,6 +77,16 @@
// We first add the struct of the super class.
addField("super", superClass.getStructType());
+
+ // Although we can safely assume that all interfaces inherits from
+ // java/lang/Object, java/lang/Class.getSuperclass() returns null
+ // on interface types. So we only set the superClass_ field when
+ // the class is not an interface type, but we model the LLVM type
+ // of the interface to be as if it inherits java/lang/Object.
+ if (cf->isInterface())
+ interfaceIndex_ = resolver_->getNextInterfaceIndex();
+ else
+ superClass_ = &superClass;
}
// This is java/lang/Object.
else
@@ -98,11 +107,11 @@
void Class::buildArrayClass(const Class& componentClass)
{
+ superClass_ = &resolver_->getClass("java/lang/Object");
componentClass_ = &componentClass;
- addField("super", resolver_->getClass("java/lang/Object").getStructType());
+ addField("super", superClass_->getStructType());
addField("<length>", Type::UIntTy);
addField("<data>", ArrayType::get(componentClass_->getType(), 0));
resolveType();
}
-
More information about the llvm-commits
mailing list