diff gen/tollvm.cpp @ 108:288fe1029e1f trunk

[svn r112] Fixed 'case 1,2,3:' style case statements. Fixed a bunch of bugs with return/break/continue in loops. Fixed support for the DMDFE hidden implicit return value variable. This can be needed for some foreach statements where the loop body is converted to a nested delegate, but also possibly returns from the function. Added std.math to phobos. Added AA runtime support code, done ground work for implementing AAs. Several other bugfixes.
author lindquist
date Tue, 20 Nov 2007 05:29:20 +0100
parents 3efbcc81ba45
children 5ab8e92611f9
line wrap: on
line diff
--- a/gen/tollvm.cpp	Tue Nov 20 00:02:35 2007 +0100
+++ b/gen/tollvm.cpp	Tue Nov 20 05:29:20 2007 +0100
@@ -174,6 +174,13 @@
         return DtoType(bt);
     }
 
+    // associative arrays
+    case Taarray:
+    {
+        // TODO this is a kludge
+        return llvm::PointerType::get(llvm::Type::Int8Ty);
+    }
+
     default:
         printf("trying to convert unknown type with value %d\n", t->ty);
         assert(0);
@@ -796,7 +803,15 @@
 
     // on this stack
     if (fd == f) {
-        llvm::Value* v = DtoGEPi(vd->llvmValue,0,unsigned(vd->llvmNestedIndex),"tmp");
+        llvm::Value* vdv = vd->llvmValue;
+        if (!vdv)
+        {
+            Logger::println(":o null vd->llvmValue for: %s", vd->toChars());
+            vdv = fd->llvmNested;
+            assert(vdv);
+        }
+        assert(vd->llvmNestedIndex != ~0);
+        llvm::Value* v = DtoGEPi(vdv,0,unsigned(vd->llvmNestedIndex),"tmp");
         if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) {
             Logger::cout() << "1267 loading: " << *v << '\n';
             v = gIR->ir->CreateLoad(v,"tmp");
@@ -859,7 +874,7 @@
         // lhs is slice
         if (DSliceValue* s = lhs->isSlice()) {
             if (DSliceValue* s2 = rhs->isSlice()) {
-                DtoArrayCopy(s, s2);
+                DtoArrayCopySlices(s, s2);
             }
             else if (t->next == t2) {
                 if (s->len)
@@ -867,8 +882,9 @@
                 else
                     DtoArrayInit(s->ptr, rhs->getRVal());
             }
-            else
-            assert(rhs->inPlace());
+            else {
+                DtoArrayCopyToSlice(s, rhs);
+            }
         }
         // rhs is slice
         else if (DSliceValue* s = rhs->isSlice()) {
@@ -926,8 +942,15 @@
             DtoComplexAssign(dst, rhs->getRVal());
     }
     else {
+        llvm::Value* l;
+        if (DLRValue* lr = lhs->isLRValue()) {
+            l = lr->getLVal();
+            rhs = DtoCast(rhs, lr->getLType());
+        }
+        else {
+            l = lhs->getLVal();
+        }
         llvm::Value* r = rhs->getRVal();
-        llvm::Value* l = lhs->getLVal();
         Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
         const llvm::Type* lit = l->getType()->getContainedType(0);
         if (r->getType() != lit) { // :(
@@ -1124,6 +1147,7 @@
 DValue* DtoCast(DValue* val, Type* to)
 {
     Type* fromtype = DtoDType(val->getType());
+    Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars());
     if (fromtype->isintegral()) {
         return DtoCastInt(val, to);
     }