[vmkit-commits] [vmkit] r54584 - in /vmkit/trunk/lib/N3/VMCore: Assembly.cpp Assembly.h

Tilmann Scheller tilmann.scheller at googlemail.com
Sat Aug 9 09:49:08 PDT 2008


Author: tilmann
Date: Sat Aug  9 11:49:08 2008
New Revision: 54584

URL: http://llvm.org/viewvc/llvm-project?rev=54584&view=rev
Log:
refactoring of generic method instantiation

Modified:
    vmkit/trunk/lib/N3/VMCore/Assembly.cpp
    vmkit/trunk/lib/N3/VMCore/Assembly.h

Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=54584&r1=54583&r2=54584&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Sat Aug  9 11:49:08 2008
@@ -1701,6 +1701,42 @@
   return i + 1 + (CONSTANT_TypeDef << 24);
 }
 
+VMMethod *Assembly::instantiateGenericMethod(
+    std::vector<VMCommonClass*> *genArgs, VMCommonClass *type,
+    const UTF8 *& name, std::vector<VMCommonClass*> & args, uint32 token,
+    bool virt) {
+  VMMethod *meth;
+  
+  if (genArgs != NULL) {
+    VMClass* cl = dynamic_cast<VMClass*> (type);
+
+    if (cl == NULL) {
+      VMThread::get()->vm->error(
+          "Only instances of generic classes are allowed.");
+    }
+
+    // search for matching signature
+    for (uint i = 0; i < cl->genericMethods.size(); ++i) {
+      VMMethod* genMethod = cl->genericMethods.at(i);
+
+      if (!name->equals(genMethod->name) || !genMethod->signatureEqualsGeneric(
+          args)) {
+        continue;
+      }
+
+      // use found token to create instance of generic method
+      VMThread::get()->genMethodInstantiation = genArgs;
+      meth = readMethodDef(genMethod->token & 0xFFFFFF, type);
+      VMThread::get()->genMethodInstantiation = NULL;
+      meth->token = token;
+    }
+  } else {
+    meth = type->lookupMethod(name, args, !virt, true);
+  }
+  
+  return meth;
+}
+
 VMMethod* Assembly::readMemberRefAsMethod(uint32 token, std::vector<VMCommonClass*>* genArgs) {
   uint32 index = token & 0xffff;
   Table* memberTable = CLIHeader->tables[CONSTANT_MemberRef];
@@ -1725,37 +1761,9 @@
   switch (table) {
     case 0 : {
       uint32 typeToken = index + (CONSTANT_TypeDef << 24);
-      VMCommonClass* type = loadType(((N3*)VMThread::get()->vm), typeToken,
-                                     true, false, false, true);
+      VMCommonClass* type = loadType(((N3*)(VMThread::get()->vm)), typeToken, true, false, false, true);
       bool virt = extractMethodSignature(offset, type, args);
-      VMMethod* meth;
-      
-      if (genArgs != NULL) {
-        VMClass* cl = dynamic_cast<VMClass*>(type);
-        
-        if (cl == NULL) {
-          VMThread::get()->vm->error("Only instances of generic classes are allowed.");
-        }
-        
-        // search for matching signature
-        for (uint i = 0; i < cl->genericMethods.size(); ++i) {
-          VMMethod* genMethod = cl->genericMethods.at(i);
-          
-          if (!name->equals(genMethod->name) || !genMethod->signatureEqualsGeneric(args)) {
-            continue;
-          }
-        
-          // use found token to create instance of generic method
-          VMThread::get()->genMethodInstantiation = genArgs;
-          meth = readMethodDef(genMethod->token & 0xFFFFFF, type);
-          VMThread::get()->genMethodInstantiation = NULL;
-          meth->token = token;
-          // insert in global hashmap
-        }
-      } else {
-        meth = type->lookupMethod(name, args, !virt, true);
-      }
-
+      VMMethod *meth = instantiateGenericMethod(genArgs, type, name, args, token, virt);
       return meth;
     }
 
@@ -1764,7 +1772,7 @@
       VMCommonClass* type = loadType(((N3*)VMThread::get()->vm), typeToken,
                                      true, false, false, true);
       bool virt = extractMethodSignature(offset, type, args);
-      VMMethod* meth = type->lookupMethod(name, args, !virt, true);
+      VMMethod *meth = instantiateGenericMethod(genArgs, type, name, args, token, virt);
       return meth;
     }
 
@@ -1772,25 +1780,28 @@
     case 3: VMThread::get()->vm->error("implement me %d", table); break;
     case 4: {
       VMClass* type = (VMClass*) readTypeSpec(vm, index);
-      
-      VMGenericClass* genClass = dynamic_cast<VMGenericClass*>(type);
-
+      type->resolveType(false, false);
+  
+      VMGenericClass* genClass = dynamic_cast<VMGenericClass*> (type);
+  
       if (genClass) {
         bool virt = extractMethodSignature(offset, type, args);
-        VMMethod* meth = type->lookupMethod(name, args, !virt, true);
+        VMMethod* meth = instantiateGenericMethod(genArgs, type, name, args,
+            token, virt);
         return meth;
       } else {
-	    VMMethod* meth = gc_new(VMMethod)();
-	    bool virt = extractMethodSignature(offset, type, args);
-	    bool structReturn = false;
-	    const llvm::FunctionType* signature = VMMethod::resolveSignature(args, virt, structReturn);
-	    meth->_signature = signature;
-	    meth->classDef = type;
-	    meth->name = name;
-	    meth->virt = virt;
-	    meth->structReturn = structReturn;
-	    meth->parameters = args; // TODO check whether this fix is correct
-	    return meth;
+        VMMethod* meth = gc_new(VMMethod)() ;
+        bool virt = extractMethodSignature(offset, type, args);
+        bool structReturn = false;
+        const llvm::FunctionType* signature = VMMethod::resolveSignature(args,
+            virt, structReturn);
+        meth->_signature = signature;
+        meth->classDef = type;
+        meth->name = name;
+        meth->virt = virt;
+        meth->structReturn = structReturn;
+        meth->parameters = args; // TODO check whether this fix is correct
+        return meth;
       }
     }
     default:
@@ -1826,17 +1837,18 @@
   switch (table) {
     case 0 : {
       methodToken = index + (CONSTANT_MethodDef << 24);
+      VMThread::get()->vm->error("implement me");
       break;
     }
     case 1 : {
       methodToken = index + (CONSTANT_MemberRef << 24);
       return readMemberRefAsMethod(methodToken, &genArgs);
     }
+    default:
+      VMThread::get()->vm->error("Invalid MethodSpec!");
   }
   
-  VMThread::get()->vm->error("MethodSpec");
-//  return NULL;
-  return (VMMethod*) (method ^ instantiation);
+  return NULL;
 }
 
 const UTF8* Assembly::readUserString(uint32 token) {

Modified: vmkit/trunk/lib/N3/VMCore/Assembly.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.h?rev=54584&r1=54583&r2=54584&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.h (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.h Sat Aug  9 11:49:08 2008
@@ -259,6 +259,8 @@
 
   void readCustomAttributes(uint32 offset, std::vector<llvm::GenericValue>& args, VMMethod* meth);
   ArrayObject* getCustomAttributes(uint32 token, VMCommonClass* cl);
+private:
+    VMMethod *instantiateGenericMethod(std::vector<VMCommonClass*> *genArgs, VMCommonClass *type, const UTF8 *& name, std::vector<VMCommonClass*> & args, uint32 token, bool virt);
 
 
 };





More information about the vmkit-commits mailing list