[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Mon Nov 8 00:04:38 PST 2004
Changes in directory llvm-java/lib/Compiler:
Compiler.cpp updated: 1.142 -> 1.143
---
Log message:
Handle the case where a static method defined on the Base class is
called through a reference to a Derived.
---
Diffs of the changes: (+28 -21)
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.142 llvm-java/lib/Compiler/Compiler.cpp:1.143
--- llvm-java/lib/Compiler/Compiler.cpp:1.142 Sun Nov 7 03:47:03 2004
+++ llvm-java/lib/Compiler/Compiler.cpp Mon Nov 8 02:04:27 2004
@@ -1089,6 +1089,7 @@
cf_ = method->getParent();
Function* function = getFunction(method);
+ assert(function->empty() && "Compiling an already compiled method!");
if (method->isNative()) {
DEBUG(std::cerr << "Ignoring native method: ";
@@ -1250,6 +1251,14 @@
return function;
}
+ /// Returns the llvm::Java::Method given a
+ /// llvm::Java::ClassMethodRef.
+ Method* getMethod(ConstantMethodRef* methodRef) {
+ return getMethod(methodRef->getClass()->getName()->str() + '/' +
+ methodRef->getNameAndType()->getName()->str() +
+ methodRef->getNameAndType()->getDescriptor()->str());
+ }
+
/// Returns the llvm::Java::Method given a <class,method>
/// descriptor.
Method* getMethod(const std::string& classMethodDesc) {
@@ -1257,15 +1266,22 @@
std::string className = classMethodDesc.substr(0, slash);
std::string methodNameAndDescr = classMethodDesc.substr(slash+1);
- ClassFile* classfile = ClassFile::get(className);
- emitStaticInitializers(classfile);
- Method* method = classfile->getMethod(methodNameAndDescr);
-
- if (!method)
- throw InvocationTargetException("Method " + methodNameAndDescr +
- " not found in class " + className);
+ while (true) {
+ ClassFile* classfile = ClassFile::get(className);
+ emitStaticInitializers(classfile);
+
+ Method* method = classfile->getMethod(methodNameAndDescr);
+ if (method)
+ return method;
+
+ if (!classfile->getSuperClass())
+ break;
+
+ className = classfile->getSuperClass()->getName()->str();
+ }
- return method;
+ throw InvocationTargetException("Method " + methodNameAndDescr +
+ " not found in class " + className);
}
public:
@@ -1829,7 +1845,7 @@
}
}
- std::vector<Value*> getParams(FunctionType* funTy) {
+ std::vector<Value*> getParams(const FunctionType* funTy) {
unsigned numParams = funTy->getNumParams();
std::vector<Value*> params(numParams);
while (numParams--) {
@@ -1959,19 +1975,10 @@
}
void do_invokestatic(unsigned index) {
- ConstantMethodRef* methodRef = cf_->getConstantMethodRef(index);
- ConstantNameAndType* nameAndType = methodRef->getNameAndType();
-
- std::string funcName =
- methodRef->getClass()->getName()->str() + '/' +
- nameAndType->getName()->str() +
- nameAndType->getDescriptor()->str();
-
- FunctionType* funcTy =
- cast<FunctionType>(getType(nameAndType->getDescriptor()));
- Function* function = module_.getOrInsertFunction(funcName, funcTy);
+ Method* method = getMethod(cf_->getConstantMethodRef(index));
+ Function* function = getFunction(method);
toCompileFunctions_.insert(function);
- makeCall(function, getParams(funcTy));
+ makeCall(function, getParams(function->getFunctionType()));
}
void do_invokeinterface(unsigned index) {
More information about the llvm-commits
mailing list