[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Thu Jul 8 19:04:01 PDT 2004
Changes in directory llvm-java/lib/Compiler:
Compiler.cpp updated: 1.48 -> 1.49
---
Log message:
Do not compile everything in a class. Compile main of the given class
and then all methods called from that and so on until all methods are
compiled.
---
Diffs of the changes: (+48 -12)
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.48 llvm-java/lib/Compiler/Compiler.cpp:1.49
--- llvm-java/lib/Compiler/Compiler.cpp:1.48 Tue Jul 6 08:21:40 2004
+++ llvm-java/lib/Compiler/Compiler.cpp Thu Jul 8 19:03:36 2004
@@ -23,6 +23,7 @@
#include <llvm/Value.h>
#include <llvm/Type.h>
#include <Support/Debug.h>
+#include <Support/SetVector.h>
#include <Support/StringExtras.h>
#include <iostream>
#include <stack>
@@ -122,6 +123,8 @@
Locals locals_;
BC2BBMap bc2bbMap_;
BasicBlock* prologue_;
+ typedef SetVector<Function*> FunctionSet;
+ FunctionSet toCompileFunctions_;
private:
BasicBlock* getBBAt(unsigned bcI) { return bc2bbMap_[bcI]; }
@@ -211,11 +214,11 @@
return locals_[index];
}
- public:
- void compileMethod(Module& module,
- const ClassFile& cf,
- const Method& method) {
- DEBUG(std::cerr << "compiling method: "
+ void compileMethodOnly(Module& module,
+ const ClassFile& cf,
+ const Method& method) {
+
+ DEBUG(std::cerr << "Compiling method: "
<< method.getName()->str() << '\n');
module_ = &module;
@@ -261,6 +264,42 @@
}
}
+ public:
+ void compileMethod(Module& module,
+ const ClassFile& cf,
+ const Method& method) {
+ compileMethodOnly(module, cf, method);
+ bool done;
+ do {
+ done = true;
+ for (FunctionSet::iterator
+ i = toCompileFunctions_.begin(),
+ e = toCompileFunctions_.end();
+ i != e; ++i) {
+ Function* f = *i;
+ if (f->isExternal()) {
+ done = false;
+ compileMethod(module, f->getName());
+ }
+ }
+ } while (!done);
+ }
+
+ void compileMethod(Module& module, const std::string& classMethodDesc) {
+ unsigned slash = classMethodDesc.find('/');
+ std::string className = classMethodDesc.substr(0, slash);
+ std::string methodNameAndDescr = classMethodDesc.substr(slash+1);
+
+ const ClassFile* classfile = ClassFile::getClassFile(className);
+ const Method* method = classfile->getMethod(methodNameAndDescr);
+ if (!method)
+ throw InvocationTargetException(
+ "Method " + methodNameAndDescr +
+ " not found in class " + className);
+
+ compileMethod(module, *classfile, *method);
+ }
+
void do_aconst_null(unsigned bcI) {
opStack_.push(llvm::Constant::getNullValue(
PointerType::get(getType(REFERENCE))));
@@ -646,7 +685,7 @@
}
void do_invokespecial(unsigned bcI, unsigned index) {
- DEBUG(std::cerr << "ignoring INVOKESPECIAL\n");
+ assert(0 && "not implemented");
}
void do_invokestatic(unsigned bcI, unsigned index) {
@@ -715,11 +754,8 @@
void Compiler::compile(Module& m, const ClassFile& cf)
{
- DEBUG(std::cerr << "compiling class: "
- << cf.getThisClass()->getName()->str() << '\n');
+ const std::string className = cf.getThisClass()->getName()->str();
+ DEBUG(std::cerr << "Compiling class: " << className << '\n');
- const Java::Methods& methods = cf.getMethods();
- for (Java::Methods::const_iterator
- i = methods.begin(), e = methods.end(); i != e; ++i)
- compilerImpl_->compileMethod(m, cf, **i);
+ compilerImpl_->compileMethod(m, className + "/main([Ljava/lang/String;)I");
}
More information about the llvm-commits
mailing list