diff gen/toir.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/toir.cpp	Tue Nov 20 00:02:35 2007 +0100
+++ b/gen/toir.cpp	Tue Nov 20 05:29:20 2007 +0100
@@ -488,7 +488,9 @@
             DtoAssign(l, r);
     }
 
-    return l;
+    if (l->isSlice() || l->isComplex())
+        return l;
+    return new DImValue(type, l->getRVal());
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -507,7 +509,8 @@
     Type* e2type = DtoDType(e2->type);
 
     if (e1type != e2type) {
-        if (e1type->ty == Tpointer && e1next && e1next->ty == Tstruct) {
+        if (llvmFieldIndex) {
+            assert(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);
@@ -1001,8 +1004,9 @@
                 llargs[j] = DtoArgument(llfnty->getParamType(j), fnarg, (Expression*)arguments->data[i]);
                 // this hack is necessary :/
                 if (dfn && dfn->func && dfn->func->llvmRunTimeHack) {
-                    Logger::println("llvmRunTimeHack==true");
+                    Logger::println("llvmRunTimeHack==true - force casting argument");
                     if (llargs[j]->getType() != llfnty->getParamType(j)) {
+                        Logger::cout() << "from: " << *llargs[j]->getType() << " to: " << *llfnty->getParamType(j);
                         llargs[j] = DtoBitCast(llargs[j], llfnty->getParamType(j));
                     }
                 }
@@ -1155,12 +1159,15 @@
 
 DValue* AddrExp::toElem(IRState* p)
 {
-    Logger::print("AddrExp::toElem: %s | %s\n", toChars(), type->toChars());
+    Logger::println("AddrExp::toElem: %s | %s", toChars(), type->toChars());
     LOG_SCOPE;
     DValue* v = e1->toElem(p);
-    if (v->isField())
+    if (v->isField()) {
+        Logger::println("is field");
         return v;
+    }
     else if (DFuncValue* fv = v->isFunc()) {
+        Logger::println("is func");
         //Logger::println("FuncDeclaration");
         FuncDeclaration* fd = fv->func;
         assert(fd);
@@ -1169,8 +1176,10 @@
         return new DFuncValue(fd, fd->llvmValue);
     }
     else if (DImValue* im = v->isIm()) {
+        Logger::println("is immediate");
         return v;
     }
+    Logger::println("is nothing special");
     return new DFieldValue(type, v->getLVal(), false);
 }
 
@@ -1178,7 +1187,7 @@
 
 DValue* PtrExp::toElem(IRState* p)
 {
-    Logger::print("PtrExp::toElem: %s | %s\n", toChars(), type->toChars());
+    Logger::println("PtrExp::toElem: %s | %s", toChars(), type->toChars());
     LOG_SCOPE;
 
     DValue* a = e1->toElem(p);
@@ -1552,7 +1561,7 @@
 
     Type* t = DtoDType(e1->type);
     Type* e2t = DtoDType(e2->type);
-    assert(t == e2t);
+    //assert(t == e2t);
 
     llvm::Value* eval = 0;
 
@@ -1571,7 +1580,12 @@
         default:
             assert(0);
         }
-        eval = new llvm::ICmpInst(cmpop, l->getRVal(), r->getRVal(), "tmp", p->scopebb());
+        llvm::Value* lv = l->getRVal();
+        llvm::Value* rv = r->getRVal();
+        if (rv->getType() != lv->getType()) {
+            rv = DtoBitCast(rv, lv->getType());
+        }
+        eval = new llvm::ICmpInst(cmpop, lv, rv, "tmp", p->scopebb());
     }
     else if (t->iscomplex())
     {
@@ -2212,7 +2226,7 @@
     if (fd->isNested()) Logger::println("nested");
     Logger::println("kind = %s\n", fd->kind());
 
-    DtoForceDeclareDsymbol(fd);
+    DtoForceDefineDsymbol(fd);
 
     bool temp = false;
     llvm::Value* lval = NULL;