[llvm-commits] CVS: llvm-java/lib/Compiler/VMField.h VMField.cpp VMClass.h VMClass.cpp Resolver.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Sat Apr 2 17:12:17 PST 2005
Changes in directory llvm-java/lib/Compiler:
VMField.h updated: 1.4 -> 1.5
VMField.cpp updated: 1.5 -> 1.6
VMClass.h updated: 1.30 -> 1.31
VMClass.cpp updated: 1.40 -> 1.41
Resolver.cpp updated: 1.19 -> 1.20
---
Log message:
Implement GetFieldId, Get<Type>Field, Set<Type>Field JNI functions.
---
Diffs of the changes: (+95 -0)
Resolver.cpp | 4 ++++
VMClass.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
VMClass.h | 2 ++
VMField.cpp | 32 ++++++++++++++++++++++++++++++++
VMField.h | 7 +++++++
5 files changed, 95 insertions(+)
Index: llvm-java/lib/Compiler/VMField.h
diff -u llvm-java/lib/Compiler/VMField.h:1.4 llvm-java/lib/Compiler/VMField.h:1.5
--- llvm-java/lib/Compiler/VMField.h:1.4 Wed Mar 30 21:15:08 2005
+++ llvm-java/lib/Compiler/VMField.h Sat Apr 2 19:12:05 2005
@@ -19,6 +19,7 @@
namespace llvm {
+ class Constant;
class GlobalVariable;
}
@@ -47,6 +48,9 @@
public:
const std::string& getName() const { return field_->getName()->str(); }
+ const std::string& getDescriptor() const {
+ return field_->getDescriptor()->str();
+ }
bool isStatic() const { return field_->isStatic(); }
const VMClass* getParent() const { return parent_; }
@@ -59,6 +63,9 @@
assert(isStatic() && "Field should be static!");
return data_.global;
}
+
+ llvm::Constant* buildFieldDescriptor() const;
+ llvm::Constant* buildFieldOffset() const;
};
} } // namespace llvm::Java
Index: llvm-java/lib/Compiler/VMField.cpp
diff -u llvm-java/lib/Compiler/VMField.cpp:1.5 llvm-java/lib/Compiler/VMField.cpp:1.6
--- llvm-java/lib/Compiler/VMField.cpp:1.5 Wed Mar 30 21:15:08 2005
+++ llvm-java/lib/Compiler/VMField.cpp Sat Apr 2 19:12:05 2005
@@ -16,6 +16,7 @@
#include "Resolver.h"
#include "VMClass.h"
#include <llvm/Constants.h>
+#include <llvm/DerivedTypes.h>
using namespace llvm;
using namespace llvm::Java;
@@ -56,3 +57,34 @@
assert(!isStatic() && "This should be a member field!");
data_.index = index;
}
+
+llvm::Constant* VMField::buildFieldDescriptor() const
+{
+ llvm::Constant* fd = ConstantArray::get(getName() + getDescriptor());
+
+ return ConstantExpr::getPtrPtrFromArrayPtr(
+ new GlobalVariable(
+ fd->getType(),
+ true,
+ GlobalVariable::ExternalLinkage,
+ fd,
+ getName() + getDescriptor(),
+ parent_->getResolver()->getModule()));
+}
+
+llvm::Constant* VMField::buildFieldOffset() const
+{
+ assert(!isStatic() && "This should be a member field!");
+
+ assert(!isa<OpaqueType>(getParent()->getType()) &&
+ "Should not be called before its owning class layout is computed!");
+ llvm::Constant* nullRef =
+ llvm::Constant::getNullValue(getParent()->getType());
+ std::vector<llvm::Constant*> indices;
+ indices.reserve(2);
+ indices.push_back(ConstantInt::get(Type::UIntTy, 0));
+ indices.push_back(ConstantInt::get(Type::UIntTy, getMemberIndex()));
+
+ return ConstantExpr::getCast(
+ ConstantExpr::getGetElementPtr(nullRef, indices), Type::UIntTy);
+}
Index: llvm-java/lib/Compiler/VMClass.h
diff -u llvm-java/lib/Compiler/VMClass.h:1.30 llvm-java/lib/Compiler/VMClass.h:1.31
--- llvm-java/lib/Compiler/VMClass.h:1.30 Sat Apr 2 02:18:20 2005
+++ llvm-java/lib/Compiler/VMClass.h Sat Apr 2 19:12:05 2005
@@ -60,6 +60,8 @@
llvm::Constant* buildSuperClassRecords() const;
llvm::Constant* buildInterfaceClassRecord(const VMClass* interface) const;
llvm::Constant* buildInterfaceClassRecords() const;
+ llvm::Constant* buildFieldDescriptors() const;
+ llvm::Constant* buildFieldOffsets() const;
llvm::Constant* buildClassTypeInfo() const;
const VMField* lookupField(const std::string& name) const;
Index: llvm-java/lib/Compiler/VMClass.cpp
diff -u llvm-java/lib/Compiler/VMClass.cpp:1.40 llvm-java/lib/Compiler/VMClass.cpp:1.41
--- llvm-java/lib/Compiler/VMClass.cpp:1.40 Sat Apr 2 02:18:20 2005
+++ llvm-java/lib/Compiler/VMClass.cpp Sat Apr 2 19:12:05 2005
@@ -297,6 +297,53 @@
resolver_->getModule()));
}
+llvm::Constant* VMClass::buildFieldDescriptors() const
+{
+ std::vector<llvm::Constant*> init;
+ init.reserve(memberFields_.size()+1);
+
+ for (unsigned i = 0, e = memberFields_.size(); i != e; ++i) {
+ const VMField* field = memberFields_[i];
+ init.push_back(field->buildFieldDescriptor());
+ }
+ // Null terminate.
+ init.push_back(llvm::Constant::getNullValue(PointerType::get(Type::SByteTy)));
+
+ const ArrayType* arrayType =
+ ArrayType::get(init.back()->getType(), init.size());
+
+ return ConstantExpr::getPtrPtrFromArrayPtr(
+ new GlobalVariable(
+ arrayType,
+ true,
+ GlobalVariable::ExternalLinkage,
+ ConstantArray::get(arrayType, init),
+ getName() + "<fielddescriptors>",
+ resolver_->getModule()));
+}
+
+llvm::Constant* VMClass::buildFieldOffsets() const
+{
+ std::vector<llvm::Constant*> init;
+ init.reserve(memberFields_.size());
+
+ for (unsigned i = 0, e = memberFields_.size(); i != e; ++i) {
+ const VMField* field = memberFields_[i];
+ init.push_back(field->buildFieldOffset());
+ }
+
+ const ArrayType* arrayType = ArrayType::get(Type::UIntTy, init.size());
+
+ return ConstantExpr::getPtrPtrFromArrayPtr(
+ new GlobalVariable(
+ arrayType,
+ true,
+ GlobalVariable::ExternalLinkage,
+ ConstantArray::get(arrayType, init),
+ getName() + "<fieldoffsets>",
+ resolver_->getModule()));
+}
+
llvm::Constant* VMClass::buildClassTypeInfo() const
{
std::vector<llvm::Constant*> init;
@@ -324,6 +371,9 @@
else // A class.
init.push_back(ConstantSInt::get(Type::IntTy, 0));
+ init.push_back(buildFieldDescriptors());
+ init.push_back(buildFieldOffsets());
+
return ConstantStruct::get(init);
}
Index: llvm-java/lib/Compiler/Resolver.cpp
diff -u llvm-java/lib/Compiler/Resolver.cpp:1.19 llvm-java/lib/Compiler/Resolver.cpp:1.20
--- llvm-java/lib/Compiler/Resolver.cpp:1.19 Sat Apr 2 18:22:44 2005
+++ llvm-java/lib/Compiler/Resolver.cpp Sat Apr 2 19:12:05 2005
@@ -47,6 +47,8 @@
// struct class_record** interfaces;
// struct class_record* component;
// int elementSize;
+ // char** fieldDescriptors;
+ // unsigned* fieldOffsets;
// };
// Compute the type_info type.
@@ -58,6 +60,8 @@
elements.push_back(PointerType::get(PointerType::get(classRecordType_)));
elements.push_back(PointerType::get(classRecordType_));
elements.push_back(Type::IntTy);
+ elements.push_back(PointerType::get(PointerType::get(Type::SByteTy)));
+ elements.push_back(PointerType::get(Type::UIntTy));
typeInfoType_ = StructType::get(elements);
module_->addTypeName("struct.llvm_java_typeinfo", getTypeInfoType());
More information about the llvm-commits
mailing list