diff gen/toir.cpp @ 92:70d6113eeb8c trunk

[svn r96] Updated to DMD 1.023. Regular bugfixes.
author lindquist
date Thu, 08 Nov 2007 19:13:28 +0100
parents 3f949c6e2e9d
children 61615fa85940
line wrap: on
line diff
--- a/gen/toir.cpp	Wed Nov 07 04:52:56 2007 +0100
+++ b/gen/toir.cpp	Thu Nov 08 19:13:28 2007 +0100
@@ -66,7 +66,8 @@
                 //allocainst->setAlignment(vd->type->alignsize()); // TODO
                 vd->llvmValue = allocainst;
             }
-            DValue* ie = DtoInitializer(vd->init);
+            DVarValue* vv = new DVarValue(type, vd->llvmValue, true);
+            DValue* ie = DtoInitializer(vd->init, vv);
             delete ie;
         }
 
@@ -322,7 +323,7 @@
 {
     Logger::print("ComplexExp::toElem(): %s | %s\n", toChars(), type->toChars());
     LOG_SCOPE;
-    assert(0);
+    assert(0 && "no complex yet");
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -331,7 +332,7 @@
 {
     Logger::print("ComplexExp::toConstElem(): %s | %s\n", toChars(), type->toChars());
     LOG_SCOPE;
-    assert(0);
+    assert(0 && "no complex yet");
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -462,10 +463,14 @@
 
     p->exps.pop_back();
 
-    if (l->isArrayLen())
-        DtoResizeDynArray(l->getLVal(), r->getRVal());
-    else
-        DtoAssign(l, r);
+    DImValue* im = r->isIm();
+    if (!im || !im->inPlace()) {
+        if (l->isArrayLen())
+            DtoResizeDynArray(l->getLVal(), r->getRVal());
+        else
+            DtoAssign(l, r);
+    }
+
     return l;
 
     /*
@@ -639,19 +644,22 @@
 
     Type* t = DtoDType(type);
     Type* e1type = DtoDType(e1->type);
+    Type* e1next = e1type->next ? DtoDType(e1type->next) : NULL;
     Type* e2type = DtoDType(e2->type);
 
     if (e1type != e2type) {
-        if (e1type->ty == Tpointer && e1type->next->ty == Tstruct) {
+        if (e1type->ty == Tpointer && e1next && e1next->ty == Tstruct) {
+            Logger::println("add to AddrExp of struct");
             assert(r->isConst());
             llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c);
 
-            TypeStruct* ts = (TypeStruct*)e1type->next;
+            TypeStruct* ts = (TypeStruct*)e1next;
             std::vector<unsigned> offsets;
             llvm::Value* v = DtoIndexStruct(l->getRVal(), ts->sym, t->next, cofs->getZExtValue(), offsets);
             return new DFieldValue(type, v, true);
         }
-        else if (e1->type->ty == Tpointer) {
+        else if (e1type->ty == Tpointer) {
+            Logger::println("add to AddrExp of struct");
             llvm::Value* v = new llvm::GetElementPtrInst(l->getRVal(), r->getRVal(), "tmp", p->scopebb());
             return new DImValue(type, v);
         }
@@ -2667,13 +2675,14 @@
     Logger::print("ArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars());
     LOG_SCOPE;
 
-    const llvm::Type* t = DtoType(type);
+    Type* ty = DtoDType(type);
+    const llvm::Type* t = DtoType(ty);
     Logger::cout() << "array literal has llvm type: " << *t << '\n';
 
     llvm::Value* mem = 0;
     if (!p->topexp() || p->topexp()->e2 != this) {
         assert(DtoDType(type)->ty == Tsarray);
-        mem = new llvm::AllocaInst(t,"tmparrayliteral",p->topallocapoint());
+        mem = new llvm::AllocaInst(t,"arrayliteral",p->topallocapoint());
     }
     else if (p->topexp()->e2 == this) {
         DValue* tlv = p->topexp()->v;
@@ -2688,8 +2697,10 @@
         if (!llvm::isa<llvm::PointerType>(mem->getType()) ||
             !llvm::isa<llvm::ArrayType>(mem->getType()->getContainedType(0)))
         {
-            error("TODO array literals can currently only be used to initialise static arrays");
-            fatal();
+            assert(ty->ty == Tarray);
+            // we need to give this array literal storage
+            const llvm::ArrayType* arrty = llvm::ArrayType::get(DtoType(ty->next), elements->dim);
+            mem = new llvm::AllocaInst(arrty, "arrayliteral", p->topallocapoint());
         }
     }
     else
@@ -2703,7 +2714,14 @@
         new llvm::StoreInst(e->getRVal(), elemAddr, p->scopebb());
     }
 
-    return new DImValue(type, mem, true);
+    if (ty->ty == Tsarray)
+        return new DImValue(type, mem, true);
+    else if (ty->ty == Tarray)
+        return new DSliceValue(type, DtoConstSize_t(elements->dim), DtoGEPi(mem,0,0,"tmp"));
+    else {
+        assert(0);
+        return 0;
+    }
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -2897,6 +2915,7 @@
 //STUB(ArrayLiteralExp);
 STUB(AssocArrayLiteralExp);
 //STUB(StructLiteralExp);
+STUB(TupleExp);
 
 #define CONSTSTUB(x) llvm::Constant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); fatal(); return NULL; }
 CONSTSTUB(Expression);