[llvm-commits] CVS: llvm-java/lib/Compiler/Resolver.h Resolver.cpp OperandStack.h Locals.h Locals.cpp Compiler.cpp Class.h Class.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Sat Mar 26 09:15:58 PST 2005
Changes in directory llvm-java/lib/Compiler:
Resolver.h updated: 1.3 -> 1.4
Resolver.cpp updated: 1.3 -> 1.4
OperandStack.h updated: 1.4 -> 1.5
Locals.h updated: 1.6 -> 1.7
Locals.cpp updated: 1.11 -> 1.12
Compiler.cpp updated: 1.252 -> 1.253
Class.h updated: 1.8 -> 1.9
Class.cpp updated: 1.8 -> 1.9
---
Log message:
I am starting to hate reference members. Make them into pointers.
---
Diffs of the changes: (+159 -158)
Class.cpp | 32 ++++----
Class.h | 6 -
Compiler.cpp | 217 ++++++++++++++++++++++++++++-----------------------------
Locals.cpp | 4 -
Locals.h | 2
OperandStack.h | 4 -
Resolver.cpp | 36 ++++-----
Resolver.h | 16 ++--
8 files changed, 159 insertions(+), 158 deletions(-)
Index: llvm-java/lib/Compiler/Resolver.h
diff -u llvm-java/lib/Compiler/Resolver.h:1.3 llvm-java/lib/Compiler/Resolver.h:1.4
--- llvm-java/lib/Compiler/Resolver.h:1.3 Sat Mar 26 10:14:29 2005
+++ llvm-java/lib/Compiler/Resolver.h Sat Mar 26 11:15:47 2005
@@ -26,14 +26,14 @@
namespace llvm { namespace Java {
class Resolver {
- Module& module_;
+ Module* module_;
typedef std::map<std::string, Class> ClassMap;
ClassMap classMap_;
unsigned nextInterfaceIndex_;
const Type* objectBaseType_;
const Type* objectBaseRefType_;
- const Class& getClassForDesc(const std::string& descriptor);
+ const Class* getClassForDesc(const std::string& descriptor);
const Type* getTypeHelper(const std::string&,
unsigned& i,
@@ -47,7 +47,7 @@
}
public:
- Resolver(Module& module);
+ Resolver(Module* module);
const Type* getObjectBaseType() const { return objectBaseType_; }
const Type* getObjectBaseRefType() const { return objectBaseRefType_; }
@@ -64,17 +64,17 @@
return !isTwoSlotType(type);
}
- const Class& getClass(const std::string& className) {
+ const Class* getClass(const std::string& className) {
return getClassForDesc(canonicalizeClassName(className));
}
- const Class& getClass(const Field& field) {
+ const Class* getClass(const Field& field) {
return getClassForDesc(field.getDescriptor()->str());
}
- const Class& getClass(JType type);
- const Class& getArrayClass(JType type);
+ const Class* getClass(JType type);
+ const Class* getArrayClass(JType type);
unsigned getNextInterfaceIndex() { return nextInterfaceIndex_++; }
- Module& getModule() { return module_; }
+ Module* getModule() { return module_; }
};
Index: llvm-java/lib/Compiler/Resolver.cpp
diff -u llvm-java/lib/Compiler/Resolver.cpp:1.3 llvm-java/lib/Compiler/Resolver.cpp:1.4
--- llvm-java/lib/Compiler/Resolver.cpp:1.3 Fri Mar 25 22:32:07 2005
+++ llvm-java/lib/Compiler/Resolver.cpp Sat Mar 26 11:15:47 2005
@@ -21,23 +21,23 @@
using namespace llvm;
using namespace llvm::Java;
-Resolver::Resolver(Module& module)
+Resolver::Resolver(Module* module)
: module_(module),
nextInterfaceIndex_(0),
objectBaseType_(OpaqueType::get()),
objectBaseRefType_(PointerType::get(objectBaseType_))
{
- classMap_.insert(std::make_pair("B", Class(*this, Type::SByteTy)));
- classMap_.insert(std::make_pair("C", Class(*this, Type::UShortTy)));
- classMap_.insert(std::make_pair("D", Class(*this, Type::DoubleTy)));
- classMap_.insert(std::make_pair("F", Class(*this, Type::FloatTy)));
- classMap_.insert(std::make_pair("I", Class(*this, Type::IntTy)));
- classMap_.insert(std::make_pair("J", Class(*this, Type::LongTy)));
- classMap_.insert(std::make_pair("S", Class(*this, Type::ShortTy)));
- classMap_.insert(std::make_pair("Z", Class(*this, Type::BoolTy)));
- classMap_.insert(std::make_pair("V", Class(*this, Type::VoidTy)));
+ classMap_.insert(std::make_pair("B", Class(this, Type::SByteTy)));
+ classMap_.insert(std::make_pair("C", Class(this, Type::UShortTy)));
+ classMap_.insert(std::make_pair("D", Class(this, Type::DoubleTy)));
+ classMap_.insert(std::make_pair("F", Class(this, Type::FloatTy)));
+ classMap_.insert(std::make_pair("I", Class(this, Type::IntTy)));
+ classMap_.insert(std::make_pair("J", Class(this, Type::LongTy)));
+ classMap_.insert(std::make_pair("S", Class(this, Type::ShortTy)));
+ classMap_.insert(std::make_pair("Z", Class(this, Type::BoolTy)));
+ classMap_.insert(std::make_pair("V", Class(this, Type::VoidTy)));
- module_.addTypeName("struct.llvm_java_object_base", objectBaseType_);
+ module_->addTypeName("struct.llvm_java_object_base", objectBaseType_);
}
const Type* Resolver::getType(const std::string& descriptor,
@@ -88,7 +88,7 @@
return 0; // not reached
}
-const Class& Resolver::getClassForDesc(const std::string& descriptor)
+const Class* Resolver::getClassForDesc(const std::string& descriptor)
{
ClassMap::iterator it = classMap_.lower_bound(descriptor);
if (it == classMap_.end() || it->first != descriptor) {
@@ -110,14 +110,14 @@
const std::string& className = descriptor.substr(1, pos - 1);
it = classMap_.insert(
it, std::make_pair(descriptor,
- Class(*this, className)));
+ Class(this, className)));
break;
}
case '[': {
const std::string& componentDescriptor = descriptor.substr(1);
it = classMap_.insert(
it, std::make_pair(descriptor,
- Class(*this, getClassForDesc(componentDescriptor))));
+ Class(this, getClassForDesc(componentDescriptor))));
break;
}
default:
@@ -125,14 +125,14 @@
abort();
}
it->second.link();
- module_.addTypeName(descriptor, it->second.getStructType());
+ module_->addTypeName(descriptor, it->second.getStructType());
DEBUG(std::cerr << "Loaded class: " << descriptor << '\n');
}
- return it->second;
+ return &it->second;
}
-const Class& Resolver::getClass(JType type)
+const Class* Resolver::getClass(JType type)
{
switch (type) {
case BOOLEAN: return getClassForDesc("Z");
@@ -147,7 +147,7 @@
}
}
-const Class& Resolver::getArrayClass(JType type)
+const Class* Resolver::getArrayClass(JType type)
{
switch (type) {
case BOOLEAN: return getClassForDesc("[Z");
Index: llvm-java/lib/Compiler/OperandStack.h
diff -u llvm-java/lib/Compiler/OperandStack.h:1.4 llvm-java/lib/Compiler/OperandStack.h:1.5
--- llvm-java/lib/Compiler/OperandStack.h:1.4 Wed Mar 23 22:47:47 2005
+++ llvm-java/lib/Compiler/OperandStack.h Sat Mar 26 11:15:47 2005
@@ -38,8 +38,8 @@
std::vector<SlotMap> stack_;
public:
- explicit OperandStack(const Resolver& resolver, unsigned maxDepth)
- : resolver_(&resolver),
+ explicit OperandStack(const Resolver* resolver, unsigned maxDepth)
+ : resolver_(resolver),
currentDepth_(0),
stack_(maxDepth) { }
Index: llvm-java/lib/Compiler/Locals.h
diff -u llvm-java/lib/Compiler/Locals.h:1.6 llvm-java/lib/Compiler/Locals.h:1.7
--- llvm-java/lib/Compiler/Locals.h:1.6 Wed Mar 23 22:47:47 2005
+++ llvm-java/lib/Compiler/Locals.h Sat Mar 26 11:15:47 2005
@@ -37,7 +37,7 @@
std::vector<SlotMap> locals_;
public:
- Locals(const Resolver& resolver, unsigned maxLocals);
+ Locals(const Resolver* resolver, unsigned maxLocals);
/// @brief - Stores the value \c value on the \c i'th local
/// variable and appends any instructions to implement this to \c
Index: llvm-java/lib/Compiler/Locals.cpp
diff -u llvm-java/lib/Compiler/Locals.cpp:1.11 llvm-java/lib/Compiler/Locals.cpp:1.12
--- llvm-java/lib/Compiler/Locals.cpp:1.11 Wed Mar 23 22:47:47 2005
+++ llvm-java/lib/Compiler/Locals.cpp Sat Mar 26 11:15:47 2005
@@ -23,8 +23,8 @@
using namespace llvm;
using namespace llvm::Java;
-Locals::Locals(const Resolver& resolver, unsigned maxLocals)
- : resolver_(&resolver),
+Locals::Locals(const Resolver* resolver, unsigned maxLocals)
+ : resolver_(resolver),
locals_(maxLocals)
{
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.252 llvm-java/lib/Compiler/Compiler.cpp:1.253
--- llvm-java/lib/Compiler/Compiler.cpp:1.252 Sat Mar 26 10:44:40 2005
+++ llvm-java/lib/Compiler/Compiler.cpp Sat Mar 26 11:15:47 2005
@@ -58,7 +58,7 @@
llvm::Constant* LONG_SHIFT_MASK = ConstantUInt::get(Type::UByteTy, 0x3f);
class Compiler : public BytecodeParser<Compiler> {
- Module& module_;
+ Module* module_;
std::auto_ptr<Resolver> resolver_;
GlobalVariable* JNIEnvPtr_;
const Class* class_;
@@ -98,38 +98,38 @@
Class2VTableInfoMap ac2viMap_;
public:
- Compiler(Module& m)
+ Compiler(Module* m)
: module_(m),
resolver_(new Resolver(module_)),
- locals_(*resolver_, 0),
- opStack_(*resolver_, 0) {
+ locals_(resolver_.get(), 0),
+ opStack_(resolver_.get(), 0) {
Type* JNIEnvTy = OpaqueType::get();
- module_.addTypeName("JNIEnv", JNIEnvTy);
+ module_->addTypeName("JNIEnv", JNIEnvTy);
JNIEnvPtr_ = new GlobalVariable(JNIEnvTy,
true,
GlobalVariable::ExternalLinkage,
NULL,
"llvm_java_JNIEnv",
- &module_);
- module_.addTypeName("llvm_java_object_vtable", VTableBaseTy);
- getVtable_ = module_.getOrInsertFunction(
+ module_);
+ module_->addTypeName("llvm_java_object_vtable", VTableBaseTy);
+ getVtable_ = module_->getOrInsertFunction(
"llvm_java_get_vtable", VTableBaseRefTy,
resolver_->getObjectBaseRefType(), NULL);
- setVtable_ = module_.getOrInsertFunction(
+ setVtable_ = module_->getOrInsertFunction(
"llvm_java_set_vtable", Type::VoidTy,
resolver_->getObjectBaseRefType(), VTableBaseRefTy, NULL);
- throw_ = module_.getOrInsertFunction(
+ throw_ = module_->getOrInsertFunction(
"llvm_java_throw", Type::IntTy,
resolver_->getObjectBaseRefType(), NULL);
- isInstanceOf_ = module_.getOrInsertFunction(
+ isInstanceOf_ = module_->getOrInsertFunction(
"llvm_java_is_instance_of", Type::IntTy,
resolver_->getObjectBaseRefType(), VTableBaseRefTy, NULL);
- memcpy_ = module_.getOrInsertFunction(
+ memcpy_ = module_->getOrInsertFunction(
"llvm.memcpy", Type::VoidTy,
PointerType::get(Type::SByteTy),
PointerType::get(Type::SByteTy),
Type::ULongTy, Type::UIntTy, NULL);
- memset_ = module_.getOrInsertFunction(
+ memset_ = module_->getOrInsertFunction(
"llvm.memset", Type::VoidTy,
PointerType::get(Type::SByteTy),
Type::UByteTy, Type::ULongTy, Type::UIntTy, NULL);
@@ -163,7 +163,7 @@
// contents of this string constant.
Value* count = ConstantUInt::get(Type::UIntTy, str.size());
Value* arrayRef = allocateArray(resolver_->getClass("[B"),
- getPrimitiveArrayVTableInfo(BYTE),
+ &getPrimitiveArrayVTableInfo(BYTE),
count,
ip);
// Copy string data.
@@ -180,7 +180,7 @@
GlobalVariable::InternalLinkage,
init,
str + ".str",
- &module_);
+ module_);
std::vector<Value*> params;
params.reserve(4);
@@ -192,13 +192,13 @@
new CallInst(memcpy_, params, "", ip);
// Get class information for java/lang/String.
- const Class& ci = resolver_->getClass("java/lang/String");
- const VTableInfo& vi = getVTableInfo(ci.getClassFile());
+ const Class* clazz = resolver_->getClass("java/lang/String");
+ const VTableInfo* vi = getVTableInfoGeneric(clazz);
// Install the vtable pointer.
Value* objBase =
new CastInst(globalString, resolver_->getObjectBaseRefType(), TMP, ip);
- Value* vtable = new CastInst(vi.vtable, VTableBaseRefTy, TMP, ip);
+ Value* vtable = new CastInst(vi->vtable, VTableBaseRefTy, TMP, ip);
new CallInst(setVtable_, objBase, vtable, "", ip);
// Initialize it: call java/lang/String/<init>(byte[],int)
@@ -296,7 +296,7 @@
// This is a static variable.
VTableInfo::TypeInfoTy = StructType::get(elements);
- module_.addTypeName(LLVM_JAVA_OBJECT_TYPEINFO, VTableInfo::TypeInfoTy);
+ module_->addTypeName(LLVM_JAVA_OBJECT_TYPEINFO, VTableInfo::TypeInfoTy);
llvm::Constant* typeInfoInit =
ConstantStruct::get(VTableInfo::TypeInfoTy, init);
@@ -329,7 +329,7 @@
const FunctionType* funcTy = cast<FunctionType>(
resolver_->getType(method->getDescriptor()->str(), true));
- Function* vfun = module_.getOrInsertFunction(funcName, funcTy);
+ Function* vfun = module_->getOrInsertFunction(funcName, funcTy);
scheduleFunction(vfun);
unsigned& index = vi.m2iMap[methodDescr];
@@ -347,13 +347,13 @@
cast<OpaqueType>(VTtype)->refineAbstractTypeTo(StructType::get(elements));
VTableInfo::VTableTy = cast<StructType>(holder.get());
- module_.addTypeName("java/lang/Object<vtable>", VTableInfo::VTableTy);
+ module_->addTypeName("java/lang/Object<vtable>", VTableInfo::VTableTy);
vi.vtable = new GlobalVariable(VTableInfo::VTableTy,
true, GlobalVariable::ExternalLinkage,
ConstantStruct::get(init),
"java/lang/Object<vtable>",
- &module_);
+ module_);
DEBUG(std::cerr << "Built VTableInfo for: java/lang/Object\n");
return true;
}
@@ -363,34 +363,34 @@
/// the array.
std::pair<unsigned,llvm::Constant*>
buildSuperClassesVTables(const ClassFile* cf, const VTableInfo& vi) const {
- std::vector<llvm::Constant*> superVtables(vi.superVtables.size());
- for (unsigned i = 0, e = vi.superVtables.size(); i != e; ++i)
- superVtables[i] = ConstantExpr::getCast(
- vi.superVtables[i],
- PointerType::get(VTableInfo::VTableTy));
-
- llvm::Constant* init = ConstantArray::get(
- ArrayType::get(PointerType::get(VTableInfo::VTableTy),
- superVtables.size()),
- superVtables);
-
- GlobalVariable* vtablesArray = new GlobalVariable(
- init->getType(),
- true,
- GlobalVariable::ExternalLinkage,
- init,
- cf->getThisClass()->getName()->str() + "<superclassesvtables>",
- &module_);
-
- return std::make_pair(
- vi.superVtables.size(),
- ConstantExpr::getPtrPtrFromArrayPtr(vtablesArray));
- }
-
- /// Builds an interface VTable for the specified <class,interface>
- /// pair.
- llvm::Constant* buildInterfaceVTable(const ClassFile* cf,
- const ClassFile* interface) {
+ std::vector<llvm::Constant*> superVtables(vi.superVtables.size());
+ for (unsigned i = 0, e = vi.superVtables.size(); i != e; ++i)
+ superVtables[i] = ConstantExpr::getCast(
+ vi.superVtables[i],
+ PointerType::get(VTableInfo::VTableTy));
+
+ llvm::Constant* init = ConstantArray::get(
+ ArrayType::get(PointerType::get(VTableInfo::VTableTy),
+ superVtables.size()),
+ superVtables);
+
+ GlobalVariable* vtablesArray = new GlobalVariable(
+ init->getType(),
+ true,
+ GlobalVariable::ExternalLinkage,
+ init,
+ cf->getThisClass()->getName()->str() + "<superclassesvtables>",
+ module_);
+
+ return std::make_pair(
+ vi.superVtables.size(),
+ ConstantExpr::getPtrPtrFromArrayPtr(vtablesArray));
+ }
+
+ /// Builds an interface VTable for the specified <class,interface>
+ /// pair.
+ llvm::Constant* buildInterfaceVTable(const ClassFile* cf,
+ const ClassFile* interface) {
DEBUG(std::cerr << "Building interface vtable: "
<< interface->getThisClass()->getName()->str() << " for: "
<< cf->getThisClass()->getName()->str() << '\n');
@@ -428,7 +428,7 @@
const std::string& globalName =
cf->getThisClass()->getName()->str() + '+' +
interface->getThisClass()->getName()->str() + "<vtable>";
- module_.addTypeName(globalName, vtable->getType());
+ module_->addTypeName(globalName, vtable->getType());
GlobalVariable* gv = new GlobalVariable(
vtable->getType(),
@@ -436,7 +436,7 @@
GlobalVariable::ExternalLinkage,
vtable,
globalName,
- &module_);
+ module_);
return ConstantExpr::getCast(gv, PointerType::get(VTableInfo::VTableTy));
}
@@ -448,8 +448,9 @@
llvm::Constant::getNullValue(PointerType::get(VTableInfo::VTableTy));
assert(interfaceCf->isInterface() && "Classfile must be an interface!");
- const Class& interface = resolver_->getClass(interfaceCf->getThisClass()->getName()->str());
- unsigned index = interface.getInterfaceIndex();
+ const Class* interface =
+ resolver_->getClass(interfaceCf->getThisClass()->getName()->str());
+ unsigned index = interface->getInterfaceIndex();
if (index >= vtables.size())
vtables.resize(index+1, nullVTable);
// Add this interface's vtable if it was not added before.
@@ -475,7 +476,7 @@
// value.
if (cf->isInterface())
return std::make_pair(
- resolver_->getClass(cf->getThisClass()->getName()->str()).getInterfaceIndex(),
+ resolver_->getClass(cf->getThisClass()->getName()->str())->getInterfaceIndex(),
ConstantExpr::getCast(
ConstantIntegral::getAllOnesValue(Type::LongTy),
PointerType::get(PointerType::get(VTableInfo::VTableTy))));
@@ -508,7 +509,7 @@
llvm::Constant* init = ConstantArray::get(
ArrayType::get(PointerType::get(VTableInfo::VTableTy), vtables.size()),
vtables);
- module_.addTypeName(globalName, init->getType());
+ module_->addTypeName(globalName, init->getType());
GlobalVariable* interfacesArray = new GlobalVariable(
init->getType(),
@@ -516,7 +517,7 @@
GlobalVariable::ExternalLinkage,
init,
globalName,
- &module_);
+ module_);
return std::make_pair(
int(vtables.size())-1,
@@ -642,7 +643,7 @@
if (cf->isInterface() || method->isAbstract())
vfun = llvm::Constant::getNullValue(PointerType::get(funcTy));
else {
- vfun = module_.getOrInsertFunction(funcName, funcTy);
+ vfun = module_->getOrInsertFunction(funcName, funcTy);
scheduleFunction(cast<Function>(vfun));
}
@@ -663,13 +664,13 @@
const std::string& globalName = className + "<vtable>";
llvm::Constant* vtable = ConstantStruct::get(init);
- module_.addTypeName(globalName, vtable->getType());
+ module_->addTypeName(globalName, vtable->getType());
vi.vtable = new GlobalVariable(vtable->getType(),
true,
GlobalVariable::ExternalLinkage,
vtable,
globalName,
- &module_);
+ module_);
// Now the vtable is complete, install the new typeinfo block
// for this class: we install it last because we need the vtable
@@ -715,13 +716,13 @@
elementTy->getDescription() + "[]<vtable>";
llvm::Constant* vtable = ConstantStruct::get(init);
- module_.addTypeName(globalName, vtable->getType());
+ module_->addTypeName(globalName, vtable->getType());
vi.vtable = new GlobalVariable(vtable->getType(),
true,
GlobalVariable::ExternalLinkage,
vtable,
globalName,
- &module_);
+ module_);
// Construct the typeinfo now.
std::vector<llvm::Constant*> typeInfoInit;
@@ -737,7 +738,7 @@
GlobalVariable::ExternalLinkage,
ConstantArray::get(vtablesArrayTy, vi.superVtables),
elementTy->getDescription() + "[]<superclassesvtables>",
- &module_);
+ module_);
typeInfoInit.push_back(ConstantExpr::getPtrPtrFromArrayPtr(vtablesArray));
typeInfoInit.push_back(ConstantSInt::get(Type::IntTy, 0));
@@ -841,7 +842,7 @@
GlobalVariable::ExternalLinkage,
ConstantArray::get(vtablesArrayTy, vi.superVtables),
"java/lang/Object[]<superclassesvtables>",
- &module_);
+ module_);
init.push_back(ConstantExpr::getPtrPtrFromArrayPtr(vtablesArray));
// last interface index
@@ -875,13 +876,13 @@
vi.m2iMap = javaLangObjectVI.m2iMap;
llvm::Constant* vtable = ConstantStruct::get(init);
- module_.addTypeName("java/lang/Object[]<vtable>", vtable->getType());
+ module_->addTypeName("java/lang/Object[]<vtable>", vtable->getType());
vi.vtable = new GlobalVariable(VTableInfo::VTableTy,
true, GlobalVariable::ExternalLinkage,
vtable,
"java/lang/Object[]<vtable>",
- &module_);
+ module_);
DEBUG(std::cerr << "Built VTableInfo for: java/lang/Object[]\n");
return true;
}
@@ -932,13 +933,13 @@
const std::string& globalName = className + "[]<vtable>";
llvm::Constant* vtable = ConstantStruct::get(init);
- module_.addTypeName(globalName, vtable->getType());
+ module_->addTypeName(globalName, vtable->getType());
vi.vtable = new GlobalVariable(vtable->getType(),
true,
GlobalVariable::ExternalLinkage,
vtable,
globalName,
- &module_);
+ module_);
// Now the vtable is complete, install the new typeinfo block
// for this class: we install it last because we need the vtable
@@ -959,7 +960,7 @@
GlobalVariable::ExternalLinkage,
ConstantArray::get(vtablesArrayTy, vi.superVtables),
className + "[]<superclassesvtables>",
- &module_);
+ module_);
typeInfoInit.push_back(ConstantExpr::getPtrPtrFromArrayPtr(vtablesArray));
// last interface index
@@ -1011,7 +1012,7 @@
const std::string& globalName = className + '/' + name;
DEBUG(std::cerr << "Looking up global: " << globalName << '\n');
- GlobalVariable* global = module_.getGlobalVariable(globalName, type);
+ GlobalVariable* global = module_->getGlobalVariable(globalName, type);
if (global)
return global;
@@ -1093,7 +1094,7 @@
Method* method = getMethod(classMethodDesc);
const std::string& className =
method->getParent()->getThisClass()->getName()->str();
- class_ = &resolver_->getClass(className);
+ class_ = resolver_->getClass(className);
Function* function = getFunction(method);
if (!function->empty()) {
@@ -1120,7 +1121,7 @@
descr.begin() + descr.find(')')));
}
- Function* jniFunction = module_.getOrInsertFunction(funcName,jniFuncTy);
+ Function* jniFunction = module_->getOrInsertFunction(funcName,jniFuncTy);
BasicBlock* bb = new BasicBlock("entry", function);
std::vector<Value*> params;
@@ -1182,7 +1183,7 @@
bbBuilder_.reset(new BasicBlockBuilder(function, codeAttr));
// Put arguments into locals.
- locals_ = Locals(*resolver_, codeAttr->getMaxLocals());
+ locals_ = Locals(resolver_.get(), codeAttr->getMaxLocals());
unsigned index = 0;
for (Function::arg_iterator a = function->arg_begin(),
@@ -1199,7 +1200,7 @@
// NOTE: We create an operand stack one size too big because we
// push extra values on the stack to simplify code generation
// (see implementation of ifne).
- opStack_ = OperandStack(*resolver_, codeAttr->getMaxStack()+2);
+ opStack_ = OperandStack(resolver_.get(), codeAttr->getMaxStack()+2);
opStackDepthMap_.insert(std::make_pair(bb0, 0));
// Insert bb0 in the work list.
@@ -1281,7 +1282,7 @@
const std::string& className =
classfile->getThisClass()->getName()->str();
- const Class& clazz = resolver_->getClass(className);
+ const Class* clazz = resolver_->getClass(className);
// Create the global variables of this class.
const Fields& fields = classfile->getFields();
@@ -1297,7 +1298,7 @@
llvm::Constant* init = llvm::Constant::getNullValue(globalTy);
if (field->getConstantValueAttribute()) {
unsigned i = field->getConstantValueAttribute()->getValueIndex();
- init = ConstantExpr::getCast(clazz.getConstant(i), globalTy);
+ init = ConstantExpr::getCast(clazz->getConstant(i), globalTy);
isConstant = field->isFinal();
}
@@ -1310,26 +1311,26 @@
GlobalVariable::ExternalLinkage,
init,
globalName,
- &module_);
+ module_);
}
}
- Function* hook = module_.getOrInsertFunction(LLVM_JAVA_STATIC_INIT,
- Type::VoidTy, 0);
+ Function* hook = module_->getOrInsertFunction(LLVM_JAVA_STATIC_INIT,
+ Type::VoidTy, 0);
Instruction* I = hook->front().getTerminator();
assert(I && LLVM_JAVA_STATIC_INIT " should have a terminator!");
// Create constant strings for this class.
for (unsigned i = 0, e = classfile->getNumConstants(); i != e; ++i)
if (ConstantString* s = dynamic_cast<ConstantString*>(classfile->getConstant(i)))
- initializeString(clazz.getConstant(i), s->getValue()->str(), I);
+ initializeString(clazz->getConstant(i), s->getValue()->str(), I);
// Call its class initialization method if it exists.
if (const Method* method = classfile->getMethod("<clinit>()V")) {
const std::string& functionName = className + '/' +
method->getName()->str() + method->getDescriptor()->str();
Function* init =
- module_.getOrInsertFunction(functionName, Type::VoidTy, 0);
+ module_->getOrInsertFunction(functionName, Type::VoidTy, 0);
// Insert a call to it right before the terminator of the only
// basic block in llvm_java_static_init.
@@ -1352,7 +1353,7 @@
clazz->getThisClass()->getName()->str() + '/' +
method->getName()->str() + method->getDescriptor()->str();
- Function* function = module_.getOrInsertFunction(funcName, funcTy);
+ Function* function = module_->getOrInsertFunction(funcName, funcTy);
return function;
}
@@ -1397,7 +1398,7 @@
Function* compileMethod(const std::string& classMethodDesc) {
// Initialize the static initializer function.
Function* staticInit =
- module_.getOrInsertFunction(LLVM_JAVA_STATIC_INIT, Type::VoidTy, 0);
+ module_->getOrInsertFunction(LLVM_JAVA_STATIC_INIT, Type::VoidTy, 0);
BasicBlock* staticInitBB = new BasicBlock("entry", staticInit);
new ReturnInst(NULL, staticInitBB);
@@ -1466,10 +1467,10 @@
void do_saload() { do_aload_common("[S"); }
void do_aload_common(const std::string& className) {
- const Class& arrayClass = resolver_->getClass(className);
- assert(arrayClass.isArray() && "Not an array class!");
+ const Class* arrayClass = resolver_->getClass(className);
+ assert(arrayClass->isArray() && "Not an array class!");
Value* index = pop(Type::IntTy);
- Value* arrayRef = pop(arrayClass.getType());
+ Value* arrayRef = pop(arrayClass->getType());
std::vector<Value*> indices;
indices.reserve(3);
@@ -1503,12 +1504,12 @@
void do_sastore() { do_astore_common("[S"); }
void do_astore_common(const std::string& className) {
- const Class& arrayClass = resolver_->getClass(className);
- assert(arrayClass.isArray() && "Not an array class!");
- const Class& componentClass = *arrayClass.getComponentClass();
- Value* value = pop(componentClass.getType());
+ const Class* arrayClass = resolver_->getClass(className);
+ assert(arrayClass->isArray() && "Not an array class!");
+ const Class* componentClass = arrayClass->getComponentClass();
+ Value* value = pop(componentClass->getType());
Value* index = pop(Type::IntTy);
- Value* arrayRef = pop(arrayClass.getType());
+ Value* arrayRef = pop(arrayClass->getType());
std::vector<Value*> indices;
indices.reserve(3);
@@ -1675,7 +1676,7 @@
Value* r = new SelectInst(c, ONE, ZERO, TMP, currentBB_);
c = BinaryOperator::createSetLT(v1, v2, TMP, currentBB_);
r = new SelectInst(c, MINUS_ONE, r, TMP, currentBB_);
- c = new CallInst(module_.getOrInsertFunction
+ c = new CallInst(module_->getOrInsertFunction
("llvm.isunordered",
Type::BoolTy, v1->getType(), v2->getType(), 0),
v1, v2, TMP, currentBB_);
@@ -1920,7 +1921,7 @@
const FunctionType* funcTy = cast<FunctionType>(
resolver_->getType(nameAndType->getDescriptor()->str(), true));
- Function* function = module_.getOrInsertFunction(funcName, funcTy);
+ Function* function = module_->getOrInsertFunction(funcName, funcTy);
scheduleFunction(function);
makeCall(function, getParams(funcTy));
}
@@ -2056,15 +2057,15 @@
}
template<typename InsertionPointTy>
- Value* allocateArray(const Class& clazz,
- const VTableInfo& vi,
+ Value* allocateArray(const Class* clazz,
+ const VTableInfo* vi,
Value* count,
InsertionPointTy* ip) {
static std::vector<Value*> params(4);
- assert(clazz.isArray() && "Not an array class!");
- const Class& componentClass = *clazz.getComponentClass();
- const Type* elementTy = componentClass.getType();
+ assert(clazz->isArray() && "Not an array class!");
+ const Class* componentClass = clazz->getComponentClass();
+ const Type* elementTy = componentClass->getType();
// The size of the element.
llvm::Constant* elementSize =
@@ -2075,7 +2076,7 @@
Instruction::Mul, count, elementSize, TMP, ip);
// The size of the rest of the array object.
llvm::Constant* arrayObjectSize =
- ConstantExpr::getCast(ConstantExpr::getSizeOf(clazz.getStructType()),
+ ConstantExpr::getCast(ConstantExpr::getSizeOf(clazz->getStructType()),
Type::UIntTy);
// Add the array part plus the object part together.
@@ -2090,7 +2091,7 @@
new CallInst(memset_, params, "", ip);
// Cast back to array type.
- objRef = new CastInst(objRef, clazz.getType(), TMP, ip);
+ objRef = new CastInst(objRef, clazz->getType(), TMP, ip);
// Store the size.
Value* lengthPtr = getArrayLengthPtr(objRef, ip);
@@ -2098,7 +2099,7 @@
// Install the vtable pointer.
Value* objBase = new CastInst(objRef, resolver_->getObjectBaseRefType(), TMP, ip);
- Value* vtable = new CastInst(vi.vtable, VTableBaseRefTy, TMP, ip);
+ Value* vtable = new CastInst(vi->vtable, VTableBaseRefTy, TMP, ip);
new CallInst(setVtable_, objBase, vtable, "", ip);
return objRef;
@@ -2107,8 +2108,8 @@
void do_newarray(JType type) {
Value* count = pop(Type::UIntTy);
- const Class& clazz = resolver_->getArrayClass(type);
- const VTableInfo& vi = getPrimitiveArrayVTableInfo(type);
+ const Class* clazz = resolver_->getArrayClass(type);
+ const VTableInfo* vi = getVTableInfoGeneric(clazz);
push(allocateArray(clazz, vi, count, currentBB_));
}
@@ -2119,15 +2120,15 @@
// FIXME: Need to handle different element types. This now
// assumes that all arrays of reference type are arrays of
// java/lang/Object's.
- const Class* clazz = &resolver_->getClass("[Ljava/lang/Object;");
+ const Class* clazz = resolver_->getClass("[Ljava/lang/Object;");
const VTableInfo* vi = getVTableInfoGeneric(clazz);
- push(allocateArray(*clazz, *vi, count, currentBB_));
+ push(allocateArray(clazz, vi, count, currentBB_));
}
void do_arraylength() {
- const Class& clazz = resolver_->getClass("[Ljava/lang/Object;");
- Value* arrayRef = pop(clazz.getType());
+ const Class* clazz = resolver_->getClass("[Ljava/lang/Object;");
+ Value* arrayRef = pop(clazz->getType());
Value* lengthPtr = getArrayLengthPtr(arrayRef, currentBB_);
Value* length = new LoadInst(lengthPtr, TMP, currentBB_);
push(length);
@@ -2195,7 +2196,7 @@
// Require the Java runtime.
m->addLibrary("jrt");
- Compiler c(*m);
+ Compiler c(m.get());
Function* main = c.compileMethod(className + "/main([Ljava/lang/String;)V");
Function* javaMain = m->getOrInsertFunction
("llvm_java_main", Type::VoidTy,
Index: llvm-java/lib/Compiler/Class.h
diff -u llvm-java/lib/Compiler/Class.h:1.8 llvm-java/lib/Compiler/Class.h:1.9
--- llvm-java/lib/Compiler/Class.h:1.8 Sat Mar 26 10:44:40 2005
+++ llvm-java/lib/Compiler/Class.h Sat Mar 26 11:15:47 2005
@@ -50,13 +50,13 @@
// Resolver interface.
// Load primitive class for type.
- Class(Resolver& resolver, const Type* type);
+ Class(Resolver* resolver, const Type* type);
// Load class by name.
- Class(Resolver& resolver, const std::string& className);
+ Class(Resolver* resolver, const std::string& className);
// Load array class of component the passed class.
- Class(Resolver& resolver, const Class& componentClass);
+ Class(Resolver* resolver, const Class* componentClass);
// Link the class.
void link();
Index: llvm-java/lib/Compiler/Class.cpp
diff -u llvm-java/lib/Compiler/Class.cpp:1.8 llvm-java/lib/Compiler/Class.cpp:1.9
--- llvm-java/lib/Compiler/Class.cpp:1.8 Sat Mar 26 10:44:40 2005
+++ llvm-java/lib/Compiler/Class.cpp Sat Mar 26 11:15:47 2005
@@ -26,8 +26,8 @@
using namespace llvm;
using namespace llvm::Java;
-Class::Class(Resolver& resolver, const std::string& className)
- : resolver_(&resolver),
+Class::Class(Resolver* resolver, const std::string& className)
+ : resolver_(resolver),
classFile_(ClassFile::get(className)),
superClass_(NULL),
componentClass_(NULL),
@@ -39,11 +39,11 @@
}
-Class::Class(Resolver& resolver, const Class& componentClass)
- : resolver_(&resolver),
+Class::Class(Resolver* resolver, const Class* componentClass)
+ : resolver_(resolver),
classFile_(NULL),
superClass_(NULL),
- componentClass_(&componentClass),
+ componentClass_(componentClass),
structType_(OpaqueType::get()),
type_(PointerType::get(structType_)),
interfaceIndex_(INVALID_INTERFACE_INDEX)
@@ -51,8 +51,8 @@
}
-Class::Class(Resolver& resolver, const Type* type)
- : resolver_(&resolver),
+Class::Class(Resolver* resolver, const Type* type)
+ : resolver_(resolver),
classFile_(NULL),
superClass_(NULL),
componentClass_(NULL),
@@ -87,7 +87,7 @@
assert(!isPrimitive() && "Should not link primitive classes!");
if (isArray()) {
- superClass_ = &resolver_->getClass("java/lang/Object");
+ superClass_ = resolver_->getClass("java/lang/Object");
addField("super", superClass_->getStructType());
addField("<length>", Type::UIntTy);
addField("<data>", ArrayType::get(componentClass_->getType(), 0));
@@ -95,11 +95,11 @@
else {
// This is any class but java/lang/Object.
if (classFile_->getSuperClass()) {
- const Class& superClass =
+ const Class* superClass =
resolver_->getClass(classFile_->getSuperClass()->getName()->str());
// We first add the struct of the super class.
- addField("super", superClass.getStructType());
+ addField("super", superClass->getStructType());
// Although we can safely assume that all interfaces inherits
// from java/lang/Object, java/lang/Class.getSuperclass()
@@ -110,7 +110,7 @@
if (classFile_->isInterface())
interfaceIndex_ = resolver_->getNextInterfaceIndex();
else
- superClass_ = &superClass;
+ superClass_ = superClass;
}
// This is java/lang/Object.
else
@@ -121,7 +121,7 @@
for (unsigned i = 0, e = fields.size(); i != e; ++i) {
Field& field = *fields[i];
if (!field.isStatic())
- addField(field.getName()->str(), resolver_->getClass(field).getType());
+ addField(field.getName()->str(), resolver_->getClass(field)->getType());
}
}
@@ -144,15 +144,15 @@
if (!resolvedConstantPool_[index]) {
Constant* jc = classFile_->getConstant(index);
if (ConstantString* s = dynamic_cast<ConstantString*>(jc)) {
- const Class& stringClass = resolver_->getClass("java/lang/String");
- const Type* stringType = stringClass.getStructType();
+ const Class* stringClass = resolver_->getClass("java/lang/String");
+ const Type* stringType = stringClass->getStructType();
resolvedConstantPool_[index] =
new GlobalVariable(stringType,
false,
GlobalVariable::LinkOnceLinkage,
llvm::Constant::getNullValue(stringType),
s->getValue()->str() + ".java/lang/String",
- &resolver_->getModule());
+ resolver_->getModule());
}
else if (ConstantInteger* i = dynamic_cast<ConstantInteger*>(jc))
resolvedConstantPool_[index] =
@@ -183,7 +183,7 @@
if (!resolvedConstantPool_[index]) {
ConstantClass* jc = classFile_->getConstantClass(index);
resolvedConstantPool_[index] =
- const_cast<Class*>(&resolver_->getClass(jc->getName()->str()));
+ const_cast<Class*>(resolver_->getClass(jc->getName()->str()));
}
return static_cast<const Class*>(resolvedConstantPool_[index]);
More information about the llvm-commits
mailing list