diff gen/toir.c @ 29:253a5fc4033a trunk

[svn r33] * Added support for assignment to function arguments
author lindquist
date Thu, 04 Oct 2007 13:45:22 +0200
parents 1c80c18f3c82
children 881158a93592
line wrap: on
line diff
--- a/gen/toir.c	Thu Oct 04 12:49:37 2007 +0200
+++ b/gen/toir.c	Thu Oct 04 13:45:22 2007 +0200
@@ -137,8 +137,17 @@
                     e->type = elem::VAR;
                 }
                 else {
-                    e->val = vd->llvmValue;
-                    e->type = elem::VAL;
+                    if (llvm::isa<llvm::Argument>(vd->llvmValue)) {
+                        e->val = vd->llvmValue;
+                        e->type = elem::VAL;
+                        e->vardecl = vd;
+                    }
+                    else if (llvm::isa<llvm::AllocaInst>(vd->llvmValue)) {
+                        e->mem = vd->llvmValue;
+                        e->type = elem::VAR;
+                    }
+                    else
+                    assert(0);
                 }
             }
         }
@@ -322,7 +331,10 @@
         elem* r = e2->toElem(p);
     p->lvals.pop_back();
 
-    assert(l->mem);
+    // handle function argument - allocate temp storage for it :/ annoying
+    if (l->mem == 0) {
+        LLVM_DtoGiveArgumentStorage(l);
+    }
     //e->val = l->store(r->getValue());
 
     TY e1ty = e1->type->ty;
@@ -516,6 +528,8 @@
         tmp = LLVM_DtoPointedType(storeVal, tmp);
     }*/
 
+    if (l->mem == 0)
+        LLVM_DtoGiveArgumentStorage(l);
     new llvm::StoreInst(val,l->mem,p->scopebb());
     e->type = elem::VAR;
 
@@ -585,6 +599,8 @@
         tmp = LLVM_DtoPointedType(storeVal, tmp);
     }*/
 
+    if (l->mem == 0)
+        LLVM_DtoGiveArgumentStorage(l);
     new llvm::StoreInst(tmp, l->mem, p->scopebb());
 
     delete l;
@@ -635,6 +651,8 @@
         tmp = LLVM_DtoPointedType(storeVal, tmp);
     }*/
 
+    if (l->mem == 0)
+        LLVM_DtoGiveArgumentStorage(l);
     new llvm::StoreInst(tmp,l->mem,p->scopebb());
 
     delete l;
@@ -696,6 +714,8 @@
         tmp = LLVM_DtoPointedType(storeVal, tmp);
     }*/
 
+    if (l->mem == 0)
+        LLVM_DtoGiveArgumentStorage(l);
     new llvm::StoreInst(tmp,l->mem,p->scopebb());
 
     delete l;
@@ -757,6 +777,8 @@
         tmp = LLVM_DtoPointedType(storeVal, tmp);
     }*/
 
+    if (l->mem == 0)
+        LLVM_DtoGiveArgumentStorage(l);
     new llvm::StoreInst(tmp,l->mem,p->scopebb());
 
     delete l;
@@ -2079,6 +2101,8 @@
     elem* v = e2->toElem(p); \
     llvm::Value* tmp = llvm::BinaryOperator::create(llvm::Instruction::Y, u->getValue(), v->getValue(), "tmp", p->scopebb()); \
     Logger::cout() << *tmp << '|' << *u->mem << '\n'; \
+    if (u->mem == 0) \
+        LLVM_DtoGiveArgumentStorage(u); \
     new llvm::StoreInst(LLVM_DtoPointedType(u->mem, tmp), u->mem, p->scopebb()); \
     delete u; \
     delete v; \