Mercurial > projects > ldc
changeset 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 |
files | gen/toir.c gen/tollvm.c gen/tollvm.h test/bug3.d test/bug4.d |
diffstat | 5 files changed, 62 insertions(+), 3 deletions(-) [+] |
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; \
--- a/gen/tollvm.c Thu Oct 04 12:49:37 2007 +0200 +++ b/gen/tollvm.c Thu Oct 04 13:45:22 2007 +0200 @@ -982,3 +982,17 @@ return func; } + +////////////////////////////////////////////////////////////////////////////////////////// + +void LLVM_DtoGiveArgumentStorage(elem* l) +{ + assert(l->mem == 0); + assert(l->val); + assert(llvm::isa<llvm::Argument>(l->val)); + assert(l->vardecl != 0); + + llvm::AllocaInst* allocainst = new llvm::AllocaInst(l->val->getType(), l->val->getName()+"_storage", gIR->topallocapoint()); + l->mem = allocainst; + l->vardecl->llvmValue = l->mem; +}
--- a/gen/tollvm.h Thu Oct 04 12:49:37 2007 +0200 +++ b/gen/tollvm.h Thu Oct 04 13:45:22 2007 +0200 @@ -42,4 +42,6 @@ llvm::Value* LLVM_DtoGEPi(llvm::Value* ptr, unsigned i0, const std::string& var, llvm::BasicBlock* bb); llvm::Value* LLVM_DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb); +void LLVM_DtoGiveArgumentStorage(elem* e); + #include "enums.h"