changeset 1464:93644700a0b3

Some minor changes to handling of variables referenced from nested functions in D2 . Added generation of new 'void*[4] reserved;' !ModuleInfo member .
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Wed, 03 Jun 2009 03:04:47 +0200
parents a5526b7a5ae6
children dd72f56ad211
files dmd/declaration.c gen/functions.cpp gen/toobj.cpp
diffstat 3 files changed, 33 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/declaration.c	Wed Jun 03 02:28:48 2009 +0200
+++ b/dmd/declaration.c	Wed Jun 03 03:04:47 2009 +0200
@@ -1163,7 +1163,11 @@
 		fdthis->getLevel(loc, fdv);
 	    nestedref = 1;
 	    fdv->nestedFrameRef = 1;
+#if IN_LLVM
+#if DMDV1
         fdv->nestedVars.insert(this);
+#endif
+#endif
 	    //printf("var %s in function %s is nested ref\n", toChars(), fdv->toChars());
 	}
     }
--- a/gen/functions.cpp	Wed Jun 03 02:28:48 2009 +0200
+++ b/gen/functions.cpp	Wed Jun 03 03:04:47 2009 +0200
@@ -665,7 +665,7 @@
         LLValue* thismem = DtoRawAlloca(thisvar->getType(), 0, "this"); // FIXME: align?
         DtoStore(thisvar, thismem);
         irfunction->thisArg = thismem;
-        
+
         assert(!fd->vthis->ir.irLocal);
         fd->vthis->ir.irLocal = new IrLocal(fd->vthis);
         fd->vthis->ir.irLocal->value = thismem;
@@ -673,14 +673,12 @@
         if (global.params.symdebug)
             DtoDwarfLocalVariable(thismem, fd->vthis);
 
-    #if DMDV2
-        if (fd->vthis->nestedrefs.dim)
-    #else
+    #if DMDV1
         if (fd->vthis->nestedref)
-    #endif
         {
             fd->nestedVars.insert(fd->vthis);
         }
+    #endif
     }
 
     // give arguments storage
@@ -698,14 +696,12 @@
             IrLocal* irloc = vd->ir.irLocal;
             assert(irloc);
 
-        #if DMDV2
-            if (vd->nestedrefs.dim)
-        #else
+        #if DMDV1
             if (vd->nestedref)
-        #endif
             {
                 fd->nestedVars.insert(vd);
             }
+        #endif
 
             bool refout = vd->storage_class & (STCref | STCout);
             bool lazy = vd->storage_class & STClazy;
@@ -734,19 +730,27 @@
     }
 
 // need result variable? (nested)
-#if DMDV2
-    if (fd->vresult && fd->vresult->nestedrefs.dim) {
-#else
+#if DMDV1
     if (fd->vresult && fd->vresult->nestedref) {
-#endif
         Logger::println("nested vresult value: %s", fd->vresult->toChars());
         fd->nestedVars.insert(fd->vresult);
     }
+#endif
+
+#if DMDV2
+    // fill nestedVars
+    size_t nnest = fd->closureVars.dim;
+    for (size_t i = 0; i < nnest; ++i)
+    {
+        VarDeclaration* vd = (VarDeclaration*)fd->closureVars.data[i];
+        fd->nestedVars.insert(vd);
+    }
+#endif
 
     DtoCreateNestedContext(fd);
 
 #if DMDV2
-    if (fd->vresult && fd->vresult->nestedrefs.dim)
+    if (fd->vresult && fd->vresult->nestedrefs.dim) // FIXME: not sure here :/
 #else
     if (fd->vresult && fd->vresult->nestedref)
 #endif
--- a/gen/toobj.cpp	Wed Jun 03 02:28:48 2009 +0200
+++ b/gen/toobj.cpp	Wed Jun 03 03:04:47 2009 +0200
@@ -611,6 +611,8 @@
 // 
 //         void* xgetMembers;
 //         void function() ictor;
+//
+//         void*[4] reserved; // useless to us
 //         }
 
     // resolve ModuleInfo
@@ -756,6 +758,15 @@
     c = getNullValue(fnptrTy);
     b.push(c);
 
+#if DMDV2
+
+    // void*[4] reserved :/
+    const LLType* AT = llvm::ArrayType::get(getVoidPtrType(), 4);
+    c = getNullValue(AT);
+    b.push(c);
+
+#endif
+
     /*Logger::println("MODULE INFO INITIALIZERS");
     for (size_t i=0; i<initVec.size(); ++i)
     {