diff gen/llvmhelpers.cpp @ 1151:3cf0066e6faf

- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM. - Eliminated the DLRValue DValue. - Implemented proactive handling of l-value CastExpS. - Minor tweak in runtime memory.d .
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Sat, 28 Mar 2009 05:00:43 +0100
parents 3d1b16dabd25
children 7d28dcbff23e
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp	Fri Mar 27 23:24:47 2009 +0100
+++ b/gen/llvmhelpers.cpp	Sat Mar 28 05:00:43 2009 +0100
@@ -472,15 +472,9 @@
         DtoStore(r, l);
     }
     else if (t->iscomplex()) {
-        LLValue* dst;
-        if (DLRValue* lr = lhs->isLRValue()) {
-            dst = lr->getLVal();
-            rhs = DtoCastComplex(loc, rhs, lr->getLType());
-        }
-        else {
-            dst = lhs->getLVal();
-        }
-        DtoStore(rhs->getRVal(), dst);
+        LLValue* dst = lhs->getLVal();
+        LLValue* src = DtoCast(loc, rhs, lhs->getType())->getRVal();
+        DtoStore(src, dst);
     }
     else {
         LLValue* l = lhs->getLVal();
@@ -489,14 +483,7 @@
             Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
         const LLType* lit = l->getType()->getContainedType(0);
         if (r->getType() != lit) {
-            // handle lvalue cast assignments
-            if (DLRValue* lr = lhs->isLRValue()) {
-                Logger::println("lvalue cast!");
-                r = DtoCast(loc, rhs, lr->getLType())->getRVal();
-            }
-            else {
-                r = DtoCast(loc, rhs, lhs->getType())->getRVal();
-            }
+            r = DtoCast(loc, rhs, lhs->getType())->getRVal();
             if (Logger::enabled())
                 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n';
             assert(r->getType() == l->getType()->getContainedType(0));
@@ -723,7 +710,13 @@
 DValue* DtoCast(Loc& loc, DValue* val, Type* to)
 {
     Type* fromtype = val->getType()->toBasetype();
+    Type* totype = to->toBasetype();
+    if (fromtype->equals(totype))
+        return val;
+
     Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars());
+    LOG_SCOPE;
+
     if (fromtype->isintegral()) {
         return DtoCastInt(loc, val, to);
     }
@@ -864,78 +857,6 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-void DtoDeclareDsymbol(Dsymbol* dsym)
-{
-    DtoResolveDsymbol(dsym);
-
-    if (StructDeclaration* sd = dsym->isStructDeclaration()) {
-        DtoDeclareStruct(sd);
-    }
-    else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
-        DtoDeclareClass(cd);
-    }
-    else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
-        DtoDeclareFunction(fd);
-    }
-    else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
-        DtoDeclareTypeInfo(fd);
-    }
-    else {
-    error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
-    assert(0 && "unsupported dsymbol for DtoDeclareDsymbol");
-    }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
-void DtoConstInitDsymbol(Dsymbol* dsym)
-{
-    DtoDeclareDsymbol(dsym);
-
-    if (StructDeclaration* sd = dsym->isStructDeclaration()) {
-        DtoConstInitStruct(sd);
-    }
-    else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
-        DtoConstInitClass(cd);
-    }
-    else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
-        DtoConstInitTypeInfo(fd);
-    }
-    else if (VarDeclaration* vd = dsym->isVarDeclaration()) {
-        DtoConstInitGlobal(vd);
-    }
-    else {
-    error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
-    assert(0 && "unsupported dsymbol for DtoConstInitDsymbol");
-    }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
-void DtoDefineDsymbol(Dsymbol* dsym)
-{
-    DtoConstInitDsymbol(dsym);
-
-    if (StructDeclaration* sd = dsym->isStructDeclaration()) {
-        DtoDefineStruct(sd);
-    }
-    else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
-        DtoDefineClass(cd);
-    }
-    else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
-        Type::sir->addFunctionBody(fd->ir.irFunc);
-    }
-    else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
-        DtoDefineTypeInfo(fd);
-    }
-    else {
-    error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
-    assert(0 && "unsupported dsymbol for DtoDefineDsymbol");
-    }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
 void DtoConstInitGlobal(VarDeclaration* vd)
 {
     vd->codegen(Type::sir);