comparison gen/tollvm.cpp @ 155:7f92f477ff53 trunk

[svn r171] starting to move IR data from AST nodes into IRState; started with IrFunction
author ChristianK
date Tue, 29 Apr 2008 21:33:50 +0200
parents 4c577c2b7229
children ccd07d9f2ce9
comparison
equal deleted inserted replaced
154:5cb946f323d2 155:7f92f477ff53
722 if (!p->isFuncDeclaration() && !p->isClassDeclaration()) 722 if (!p->isFuncDeclaration() && !p->isClassDeclaration())
723 Logger::println("unexpected parent symbol found while resolving frame pointer - '%s' kind: '%s'", p->toChars(), p->kind()); 723 Logger::println("unexpected parent symbol found while resolving frame pointer - '%s' kind: '%s'", p->toChars(), p->kind());
724 assert(p->isFuncDeclaration() || p->isClassDeclaration()); 724 assert(p->isFuncDeclaration() || p->isClassDeclaration());
725 if (FuncDeclaration* fd = p->isFuncDeclaration()) 725 if (FuncDeclaration* fd = p->isFuncDeclaration())
726 { 726 {
727 llvm::Value* v = fd->irFunc->nestedVar; 727 llvm::Value* v = gIR->irFunc[fd]->nestedVar;
728 assert(v); 728 assert(v);
729 return v->getType(); 729 return v->getType();
730 } 730 }
731 else if (ClassDeclaration* cd = p->isClassDeclaration()) 731 else if (ClassDeclaration* cd = p->isClassDeclaration())
732 { 732 {
752 { 752 {
753 Logger::println("scope is function: %s", fd->toChars()); 753 Logger::println("scope is function: %s", fd->toChars());
754 754
755 if (fd->toParent2() == func) 755 if (fd->toParent2() == func)
756 { 756 {
757 if (!func->irFunc->nestedVar) 757 if (!gIR->irFunc[func]->nestedVar)
758 return NULL; 758 return NULL;
759 return DtoBitCast(v, func->irFunc->nestedVar->getType()); 759 return DtoBitCast(v, gIR->irFunc[func]->nestedVar->getType());
760 } 760 }
761 761
762 v = DtoBitCast(v, get_next_frame_ptr_type(fd)); 762 v = DtoBitCast(v, get_next_frame_ptr_type(fd));
763 Logger::cout() << "v = " << *v << '\n'; 763 Logger::cout() << "v = " << *v << '\n';
764 764
805 LOG_SCOPE; 805 LOG_SCOPE;
806 IrFunction* irfunc = gIR->func(); 806 IrFunction* irfunc = gIR->func();
807 807
808 // in the right scope already 808 // in the right scope already
809 if (func == irfunc->decl) 809 if (func == irfunc->decl)
810 return irfunc->decl->irFunc->nestedVar; 810 return gIR->irFunc[irfunc->decl]->nestedVar;
811 811
812 // use the 'this' pointer 812 // use the 'this' pointer
813 llvm::Value* ptr = irfunc->decl->irFunc->thisVar; 813 llvm::Value* ptr = gIR->irFunc[irfunc->decl]->thisVar;
814 assert(ptr); 814 assert(ptr);
815 815
816 // return the fully resolved frame pointer 816 // return the fully resolved frame pointer
817 ptr = get_frame_ptr_impl(func, irfunc->decl, ptr); 817 ptr = get_frame_ptr_impl(func, irfunc->decl, ptr);
818 if (ptr) Logger::cout() << "Found context!" << *ptr; 818 if (ptr) Logger::cout() << "Found context!" << *ptr;
876 assert(func); 876 assert(func);
877 llvm::Value* ptr = DtoNestedContext(func); 877 llvm::Value* ptr = DtoNestedContext(func);
878 assert(ptr && "nested var, but no context"); 878 assert(ptr && "nested var, but no context");
879 879
880 // we must cast here to be sure. nested classes just have a void* 880 // we must cast here to be sure. nested classes just have a void*
881 ptr = DtoBitCast(ptr, func->irFunc->nestedVar->getType()); 881 ptr = DtoBitCast(ptr, gIR->irFunc[func]->nestedVar->getType());
882 882
883 // index nested var and load (if necessary) 883 // index nested var and load (if necessary)
884 llvm::Value* v = DtoGEPi(ptr, 0, vd->irLocal->nestedIndex, "tmp"); 884 llvm::Value* v = DtoGEPi(ptr, 0, vd->irLocal->nestedIndex, "tmp");
885 // references must be loaded, for normal variables this IS already the variable storage!!! 885 // references must be loaded, for normal variables this IS already the variable storage!!!
886 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) 886 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type)))
962 // assignment to this in constructor special case 962 // assignment to this in constructor special case
963 if (lhs->isThis()) { 963 if (lhs->isThis()) {
964 llvm::Value* tmp = rhs->getRVal(); 964 llvm::Value* tmp = rhs->getRVal();
965 FuncDeclaration* fdecl = gIR->func()->decl; 965 FuncDeclaration* fdecl = gIR->func()->decl;
966 // respecify the this param 966 // respecify the this param
967 if (!llvm::isa<llvm::AllocaInst>(fdecl->irFunc->thisVar)) 967 if (!llvm::isa<llvm::AllocaInst>(gIR->irFunc[fdecl]->thisVar))
968 fdecl->irFunc->thisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint()); 968 gIR->irFunc[fdecl]->thisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint());
969 DtoStore(tmp, fdecl->irFunc->thisVar); 969 DtoStore(tmp, gIR->irFunc[fdecl]->thisVar);
970 } 970 }
971 // regular class ref -> class ref assignment 971 // regular class ref -> class ref assignment
972 else { 972 else {
973 DtoStore(rhs->getRVal(), lhs->getLVal()); 973 DtoStore(rhs->getRVal(), lhs->getLVal());
974 } 974 }