comparison 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
comparison
equal deleted inserted replaced
49:e5c4bece7fa1 50:6fcc08a4d406
697 697
698 Logger::cout() << "func type: " << *f->llvmType << '\n'; 698 Logger::cout() << "func type: " << *f->llvmType << '\n';
699 699
700 // this handling 700 // this handling
701 if (f->llvmUsesThis) { 701 if (f->llvmUsesThis) {
702 Logger::println("uses this");
702 if (f->llvmRetInPtr) 703 if (f->llvmRetInPtr)
703 llvmThisVar = ++func->arg_begin(); 704 llvmThisVar = ++func->arg_begin();
704 else 705 else
705 llvmThisVar = func->arg_begin(); 706 llvmThisVar = func->arg_begin();
706 assert(llvmThisVar != 0); 707 assert(llvmThisVar != 0);
716 gIR->scopes.push_back(IRScope(beginbb, endbb)); 717 gIR->scopes.push_back(IRScope(beginbb, endbb));
717 718
718 // create alloca point 719 // create alloca point
719 f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb()); 720 f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb());
720 gIR->func().allocapoint = f->llvmAllocaPoint; 721 gIR->func().allocapoint = f->llvmAllocaPoint;
722
723 llvm::Value* parentNested = NULL;
724 if (FuncDeclaration* fd = toParent()->isFuncDeclaration()) {
725 parentNested = fd->llvmNested;
726 }
727
728 // construct nested variables struct
729 if (!llvmNestedVars.empty() || parentNested) {
730 std::vector<const llvm::Type*> nestTypes;
731 int j = 0;
732 if (parentNested) {
733 nestTypes.push_back(parentNested->getType());
734 j++;
735 }
736 for (std::set<VarDeclaration*>::iterator i=llvmNestedVars.begin(); i!=llvmNestedVars.end(); ++i) {
737 VarDeclaration* vd = *i;
738 vd->llvmNestedIndex = j++;
739 nestTypes.push_back(LLVM_DtoType(vd->type));
740 }
741 const llvm::StructType* nestSType = llvm::StructType::get(nestTypes);
742 Logger::cout() << "nested var struct has type:" << '\n' << *nestSType;
743 llvmNested = new llvm::AllocaInst(nestSType,"nestedvars",f->llvmAllocaPoint);
744 if (parentNested) {
745 assert(llvmThisVar);
746 llvm::Value* ptr = gIR->ir->CreateBitCast(llvmThisVar, parentNested->getType(), "tmp");
747 gIR->ir->CreateStore(ptr, LLVM_DtoGEPi(llvmNested, 0,0, "tmp"));
748 }
749 }
721 750
722 // output function body 751 // output function body
723 fbody->toIR(gIR); 752 fbody->toIR(gIR);
724 753
725 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement 754 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement
729 // pass the previous block into this block 758 // pass the previous block into this block
730 //new llvm::BranchInst(irs.end, irs.begin); 759 //new llvm::BranchInst(irs.end, irs.begin);
731 if (func->getReturnType() == llvm::Type::VoidTy) { 760 if (func->getReturnType() == llvm::Type::VoidTy) {
732 new llvm::ReturnInst(gIR->scopebb()); 761 new llvm::ReturnInst(gIR->scopebb());
733 } 762 }
734
735 } 763 }
736 } 764 }
737 765
738 // erase alloca point 766 // erase alloca point
739 f->llvmAllocaPoint->eraseFromParent(); 767 f->llvmAllocaPoint->eraseFromParent();