Mercurial > projects > ldc
diff gen/toobj.c @ 50:6fcc08a4d406 trunk
[svn r54] Added support for nested delegates referencing parent's stack variables.
Replaced tester.sh with a version written in D.
A few bugfixes.
author | lindquist |
---|---|
date | Mon, 22 Oct 2007 15:40:56 +0200 |
parents | 8b0e809563df |
children | 0c77619e803b |
line wrap: on
line diff
--- a/gen/toobj.c Fri Oct 19 17:43:46 2007 +0200 +++ b/gen/toobj.c Mon Oct 22 15:40:56 2007 +0200 @@ -699,6 +699,7 @@ // this handling if (f->llvmUsesThis) { + Logger::println("uses this"); if (f->llvmRetInPtr) llvmThisVar = ++func->arg_begin(); else @@ -719,6 +720,34 @@ f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb()); gIR->func().allocapoint = f->llvmAllocaPoint; + llvm::Value* parentNested = NULL; + if (FuncDeclaration* fd = toParent()->isFuncDeclaration()) { + parentNested = fd->llvmNested; + } + + // construct nested variables struct + if (!llvmNestedVars.empty() || parentNested) { + std::vector<const llvm::Type*> nestTypes; + int j = 0; + if (parentNested) { + nestTypes.push_back(parentNested->getType()); + j++; + } + for (std::set<VarDeclaration*>::iterator i=llvmNestedVars.begin(); i!=llvmNestedVars.end(); ++i) { + VarDeclaration* vd = *i; + vd->llvmNestedIndex = j++; + nestTypes.push_back(LLVM_DtoType(vd->type)); + } + const llvm::StructType* nestSType = llvm::StructType::get(nestTypes); + Logger::cout() << "nested var struct has type:" << '\n' << *nestSType; + llvmNested = new llvm::AllocaInst(nestSType,"nestedvars",f->llvmAllocaPoint); + if (parentNested) { + assert(llvmThisVar); + llvm::Value* ptr = gIR->ir->CreateBitCast(llvmThisVar, parentNested->getType(), "tmp"); + gIR->ir->CreateStore(ptr, LLVM_DtoGEPi(llvmNested, 0,0, "tmp")); + } + } + // output function body fbody->toIR(gIR); @@ -731,7 +760,6 @@ if (func->getReturnType() == llvm::Type::VoidTy) { new llvm::ReturnInst(gIR->scopebb()); } - } }