changeset 593:7042d912767e

Undid some of the previous changes: DtoArrayInit has issues with arrays similar to T[n][].
author Christian Kamm <kamm incasoftware de>
date Sun, 14 Sep 2008 13:47:38 +0200
parents 5fb7ed0ac580
children e096a1502428
files gen/arrays.cpp runtime/internal/arrayInit.d
diffstat 2 files changed, 38 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/gen/arrays.cpp	Sun Sep 14 10:56:01 2008 +0200
+++ b/gen/arrays.cpp	Sun Sep 14 13:47:38 2008 +0200
@@ -136,7 +136,8 @@
 
     // determine the right runtime function to call
     const char* funcname = NULL;
-    Type* t = value->getType()->toBasetype();
+    Type* arrayelemty = array->getType()->nextOf()->toBasetype();
+    Type* valuety = value->getType()->toBasetype();
 
     // lets first optimize all zero initializations down to a memset.
     // this simplifies codegen later on as llvm null's have no address!
@@ -149,7 +150,7 @@
     }
 
     // if not a zero initializer, call the appropriate runtime function!
-    switch (t->ty)
+    switch (arrayelemty->ty)
     {
     case Tbool:
         funcname = "_d_array_init_i1";
@@ -220,9 +221,10 @@
     case Tarray:
     case Tsarray:
         funcname = "_d_array_init_mem";
+        assert(arrayelemty == valuety && "ArrayInit doesn't work on elem-initialized static arrays");
         args[0] = DtoBitCast(args[0], getVoidPtrType());
         args[2] = DtoBitCast(args[2], getVoidPtrType());
-        args.push_back(DtoConstSize_t(getABITypeSize(DtoType(t))));
+        args.push_back(DtoConstSize_t(getABITypeSize(DtoType(arrayelemty))));
         break;
 
     default:
@@ -412,7 +414,9 @@
     LLValue* arrayLen = dim->getRVal();
 
     // get runtime function
-    LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newarrayvT");
+    bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
+    const char* fnname = defaultInit ? (zeroInit ? "_d_newarrayT" : "_d_newarrayiT") : "_d_newarrayvT";
+    LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname);
 
     // call allocator
     LLValue* newptr = gIR->CreateCallOrInvoke2(fn, arrayTypeInfo, arrayLen, ".gc_mem")->get();
@@ -424,14 +428,7 @@
 
     Logger::cout() << "final ptr = " << *newptr << '\n';
 
-    DSliceValue* ret = new DSliceValue(arrayType, arrayLen, newptr);
-
-    if (defaultInit) {
-        DValue* e = arrayType->nextOf()->defaultInit()->toElem(gIR);
-        DtoArrayInit(loc, ret, e);
-    }
-
-    return ret;
+    return new DSliceValue(arrayType, arrayLen, newptr);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -450,7 +447,8 @@
 
     // get runtime function
     bool zeroInit = vtype->isZeroInit();
-    LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarraymT" : "_d_newarraymiT" );
+    const char* fnname = defaultInit ? (zeroInit ? "_d_newarraymT" : "_d_newarraymiT") : "_d_newarraymvT";
+    LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname);
 
     // build dims
     LLValue* dimsArg = DtoAlloca(DtoSize_t(), DtoConstUint(ndims), ".newdims");
@@ -472,14 +470,6 @@
 
     Logger::cout() << "final ptr = " << *newptr << '\n';
 
-#if 0
-    // using this would reinit all arrays beyond the first level to []
-    if (defaultInit) {
-        DValue* e = dty->defaultInit()->toElem(gIR);
-        DtoArrayInit(newptr,dim,e->getRVal());
-    }
-#endif
-
     assert(firstDim);
     return new DSliceValue(arrayType, firstDim, newptr);
 }
--- a/runtime/internal/arrayInit.d	Sun Sep 14 10:56:01 2008 +0200
+++ b/runtime/internal/arrayInit.d	Sun Sep 14 13:47:38 2008 +0200
@@ -118,6 +118,33 @@
     }
 }
 
+/*
+void _d_array_init(TypeInfo ti, void* a)
+{
+    auto initializer = ti.next.init();
+    auto isize = initializer.length;
+    auto q = initializer.ptr;
+
+    if (isize == 1)
+        memset(p, *cast(ubyte*)q, size);
+    else if (isize == int.sizeof)
+    {
+        int init = *cast(int*)q;
+        size /= int.sizeof;
+        for (size_t u = 0; u < size; u++)
+        {
+            (cast(int*)p)[u] = init;
+        }
+    }
+    else
+    {
+        for (size_t u = 0; u < size; u += isize)
+        {
+            memcpy(p + u, q, isize);
+        }
+    }
+}*/
+
 // for array cast
 size_t _d_array_cast_len(size_t len, size_t elemsz, size_t newelemsz)
 {