[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Sat Aug 14 01:58:17 PDT 2004



Changes in directory llvm-java/lib/Compiler:

Compiler.cpp updated: 1.84 -> 1.85
---
Log message:

Implement instanceof and checkcast bytecodes.


---
Diffs of the changes:  (+26 -3)

Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.84 llvm-java/lib/Compiler/Compiler.cpp:1.85
--- llvm-java/lib/Compiler/Compiler.cpp:1.84	Fri Aug  6 10:19:03 2004
+++ llvm-java/lib/Compiler/Compiler.cpp	Sat Aug 14 03:58:06 2004
@@ -375,8 +375,10 @@
         fieldRef->getClass()->getName()->str() + '/' +
         nameAndType->getName()->str();
 
+      DEBUG(std::cerr << "Looking up global: " << globalName << '\n');
       GlobalVariable* global = module_->getGlobalVariable
         (globalName, getType(nameAndType->getDescriptor()));
+      assert(global && "Got NULL global variable!");
 
       return global;
     }
@@ -496,13 +498,17 @@
                 field->getConstantValueAttribute())
               init = getConstant(cv->getValue());
 
+            std::string globalName =
+              classfile->getThisClass()->getName()->str() + '/' +
+              field->getName()->str();
+            DEBUG(std::cerr << "Adding global: " << globalName << '\n');
             new GlobalVariable(getType(field->getDescriptor()),
                                field->isFinal(),
                                (field->isPrivate() & bool(init) ?
                                 GlobalVariable::InternalLinkage :
                                 GlobalVariable::ExternalLinkage),
                                init,
-                               classfile->getThisClass()->getName()->str() + '/' + field->getName()->str(),
+                               globalName,
                                module_);
           }
         }
@@ -1039,11 +1045,28 @@
     }
 
     void do_checkcast(unsigned bcI, unsigned index) {
-      assert(0 && "not implemented");
+      do_dup(bcI);
+      do_instanceof(bcI, index);
+      Value* r = opStack_.top(); opStack_.pop();
+      Value* b = new SetCondInst(Instruction::SetEQ,
+                                 r, ConstantSInt::get(Type::IntTy, 1),
+                                 TMP, getBBAt(bcI));
+      // FIXME: if b is false we must throw a ClassCast exception
     }
 
     void do_instanceof(unsigned bcI, unsigned index) {
-      assert(0 && "not implemented");
+      ConstantClass* classRef = cf_->getConstantClass(index);
+      const std::string& className = classRef->getName()->str();
+      const VTableInfo& vi = getVTableInfo(className);
+
+      Value* objRef = opStack_.top(); opStack_.pop();
+      Value* vtable = getField(bcI, className, "<llvm_java_base>", objRef);
+      Function* f = module_->getOrInsertFunction("<llvm_java_instanceof>",
+                                                 Type::IntTy,
+                                                 vtable->getType(),
+                                                 vtable->getType(), NULL);
+      Value* r = new CallInst(f, vtable, vi.vtable, TMP, getBBAt(bcI));
+      opStack_.push(r);
     }
 
     void do_monitorenter(unsigned bcI) {






More information about the llvm-commits mailing list