comparison gen/tollvm.cpp @ 156:ccd07d9f2ce9 trunk

[svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
author ChristianK
date Thu, 01 May 2008 13:05:53 +0200
parents 7f92f477ff53
children 5c17f81fc1c1
comparison
equal deleted inserted replaced
155:7f92f477ff53 156:ccd07d9f2ce9
114 } 114 }
115 115
116 TypeStruct* ts = (TypeStruct*)t; 116 TypeStruct* ts = (TypeStruct*)t;
117 assert(ts->sym); 117 assert(ts->sym);
118 DtoResolveDsymbol(ts->sym); 118 DtoResolveDsymbol(ts->sym);
119 return ts->sym->irStruct->recty.get();//t->llvmType->get(); 119 return gIR->irDsymbol[ts->sym].irStruct->recty.get();//t->llvmType->get();
120 } 120 }
121 121
122 case Tclass: { 122 case Tclass: {
123 /*if (!t->llvmType || *t->llvmType == NULL) { 123 /*if (!t->llvmType || *t->llvmType == NULL) {
124 // recursive or cyclic declaration 124 // recursive or cyclic declaration
137 }*/ 137 }*/
138 138
139 TypeClass* tc = (TypeClass*)t; 139 TypeClass* tc = (TypeClass*)t;
140 assert(tc->sym); 140 assert(tc->sym);
141 DtoResolveDsymbol(tc->sym); 141 DtoResolveDsymbol(tc->sym);
142 return getPtrToType(tc->sym->irStruct->recty.get());//t->llvmType->get()); 142 return getPtrToType(gIR->irDsymbol[tc->sym].irStruct->recty.get());//t->llvmType->get());
143 } 143 }
144 144
145 // functions 145 // functions
146 case Tfunction: 146 case Tfunction:
147 { 147 {
559 { 559 {
560 const llvm::StructType* structty = isaStruct(_type); 560 const llvm::StructType* structty = isaStruct(_type);
561 TypeStruct* ts = (TypeStruct*)t; 561 TypeStruct* ts = (TypeStruct*)t;
562 assert(ts); 562 assert(ts);
563 assert(ts->sym); 563 assert(ts->sym);
564 assert(ts->sym->irStruct->constInit); 564 assert(gIR->irDsymbol[ts->sym].irStruct->constInit);
565 _init = ts->sym->irStruct->constInit; 565 _init = gIR->irDsymbol[ts->sym].irStruct->constInit;
566 } 566 }
567 else if (t->ty == Tclass) 567 else if (t->ty == Tclass)
568 { 568 {
569 _init = llvm::Constant::getNullValue(_type); 569 _init = llvm::Constant::getNullValue(_type);
570 } 570 }
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 = gIR->irFunc[fd]->nestedVar; 727 llvm::Value* v = gIR->irDsymbol[fd].irFunc->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 (!gIR->irFunc[func]->nestedVar) 757 if (!gIR->irDsymbol[func].irFunc->nestedVar)
758 return NULL; 758 return NULL;
759 return DtoBitCast(v, gIR->irFunc[func]->nestedVar->getType()); 759 return DtoBitCast(v, gIR->irDsymbol[func].irFunc->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
768 v = DtoLoad(v); 768 v = DtoLoad(v);
769 } 769 }
770 else if (ClassDeclaration* cd = fd->toParent2()->isClassDeclaration()) 770 else if (ClassDeclaration* cd = fd->toParent2()->isClassDeclaration())
771 { 771 {
772 size_t idx = 2; 772 size_t idx = 2;
773 //idx += cd->irStruct->interfaceVec.size(); 773 //idx += gIR->irDsymbol[cd].irStruct->interfaceVec.size();
774 v = DtoGEPi(v,0,idx,"tmp"); 774 v = DtoGEPi(v,0,idx,"tmp");
775 v = DtoLoad(v); 775 v = DtoLoad(v);
776 } 776 }
777 else 777 else
778 { 778 {
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 gIR->irFunc[irfunc->decl]->nestedVar; 810 return gIR->irDsymbol[irfunc->decl].irFunc->nestedVar;
811 811
812 // use the 'this' pointer 812 // use the 'this' pointer
813 llvm::Value* ptr = gIR->irFunc[irfunc->decl]->thisVar; 813 llvm::Value* ptr = gIR->irDsymbol[irfunc->decl].irFunc->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, gIR->irFunc[func]->nestedVar->getType()); 881 ptr = DtoBitCast(ptr, gIR->irDsymbol[func].irFunc->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, gIR->irDsymbol[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)))
887 v = DtoLoad(v); 887 v = DtoLoad(v);
888 888
889 // log and return 889 // log and return
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>(gIR->irFunc[fdecl]->thisVar)) 967 if (!llvm::isa<llvm::AllocaInst>(gIR->irDsymbol[fdecl].irFunc->thisVar))
968 gIR->irFunc[fdecl]->thisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint()); 968 gIR->irDsymbol[fdecl].irFunc->thisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint());
969 DtoStore(tmp, gIR->irFunc[fdecl]->thisVar); 969 DtoStore(tmp, gIR->irDsymbol[fdecl].irFunc->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 }
1570 1570
1571 ////////////////////////////////////////////////////////////////////////////////////////// 1571 //////////////////////////////////////////////////////////////////////////////////////////
1572 1572
1573 void DtoConstInitGlobal(VarDeclaration* vd) 1573 void DtoConstInitGlobal(VarDeclaration* vd)
1574 { 1574 {
1575 if (vd->llvmInitialized) return; 1575 if (gIR->irDsymbol[vd].initialized) return;
1576 vd->llvmInitialized = gIR->dmodule; 1576 gIR->irDsymbol[vd].initialized = gIR->dmodule;
1577 1577
1578 Logger::println("* DtoConstInitGlobal(%s)", vd->toChars()); 1578 Logger::println("* DtoConstInitGlobal(%s)", vd->toChars());
1579 LOG_SCOPE; 1579 LOG_SCOPE;
1580 1580
1581 bool emitRTstaticInit = false; 1581 bool emitRTstaticInit = false;
1603 { 1603 {
1604 assert(_init->getType()->getContainedType(0) == _type); 1604 assert(_init->getType()->getContainedType(0) == _type);
1605 llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init); 1605 llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init);
1606 assert(t->ty == Tstruct); 1606 assert(t->ty == Tstruct);
1607 TypeStruct* ts = (TypeStruct*)t; 1607 TypeStruct* ts = (TypeStruct*)t;
1608 assert(ts->sym->irStruct->constInit); 1608 assert(gIR->irDsymbol[ts->sym].irStruct->constInit);
1609 _init = ts->sym->irStruct->constInit; 1609 _init = gIR->irDsymbol[ts->sym].irStruct->constInit;
1610 } 1610 }
1611 // array single value init 1611 // array single value init
1612 else if (isaArray(_type)) 1612 else if (isaArray(_type))
1613 { 1613 {
1614 _init = DtoConstStaticArray(_type, _init); 1614 _init = DtoConstStaticArray(_type, _init);
1624 istempl = true; 1624 istempl = true;
1625 } 1625 }
1626 1626
1627 if (_init && _init->getType() != _type) 1627 if (_init && _init->getType() != _type)
1628 _type = _init->getType(); 1628 _type = _init->getType();
1629 llvm::cast<llvm::OpaqueType>(vd->irGlobal->type.get())->refineAbstractTypeTo(_type); 1629 llvm::cast<llvm::OpaqueType>(gIR->irDsymbol[vd].irGlobal->type.get())->refineAbstractTypeTo(_type);
1630 _type = vd->irGlobal->type.get(); 1630 _type = gIR->irDsymbol[vd].irGlobal->type.get();
1631 assert(!_type->isAbstract()); 1631 assert(!_type->isAbstract());
1632 1632
1633 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(vd->irGlobal->value); 1633 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(gIR->irDsymbol[vd].irGlobal->value);
1634 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl)) 1634 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl))
1635 { 1635 {
1636 gvar->setInitializer(_init); 1636 gvar->setInitializer(_init);
1637 } 1637 }
1638 1638
1726 1726
1727 ////////////////////////////////////////////////////////////////////////////////////////// 1727 //////////////////////////////////////////////////////////////////////////////////////////
1728 1728
1729 void DtoForceDeclareDsymbol(Dsymbol* dsym) 1729 void DtoForceDeclareDsymbol(Dsymbol* dsym)
1730 { 1730 {
1731 if (dsym->llvmDeclared) return; 1731 if (gIR->irDsymbol[dsym].declared) return;
1732 Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toPrettyChars()); 1732 Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toPrettyChars());
1733 LOG_SCOPE; 1733 LOG_SCOPE;
1734 DtoResolveDsymbol(dsym); 1734 DtoResolveDsymbol(dsym);
1735 1735
1736 DtoEmptyResolveList(); 1736 DtoEmptyResolveList();
1740 1740
1741 ////////////////////////////////////////////////////////////////////////////////////////// 1741 //////////////////////////////////////////////////////////////////////////////////////////
1742 1742
1743 void DtoForceConstInitDsymbol(Dsymbol* dsym) 1743 void DtoForceConstInitDsymbol(Dsymbol* dsym)
1744 { 1744 {
1745 if (dsym->llvmInitialized) return; 1745 if (gIR->irDsymbol[dsym].initialized) return;
1746 Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toPrettyChars()); 1746 Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toPrettyChars());
1747 LOG_SCOPE; 1747 LOG_SCOPE;
1748 DtoResolveDsymbol(dsym); 1748 DtoResolveDsymbol(dsym);
1749 1749
1750 DtoEmptyResolveList(); 1750 DtoEmptyResolveList();
1755 1755
1756 ////////////////////////////////////////////////////////////////////////////////////////// 1756 //////////////////////////////////////////////////////////////////////////////////////////
1757 1757
1758 void DtoForceDefineDsymbol(Dsymbol* dsym) 1758 void DtoForceDefineDsymbol(Dsymbol* dsym)
1759 { 1759 {
1760 if (dsym->llvmDefined) return; 1760 if (gIR->irDsymbol[dsym].defined) return;
1761 Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars()); 1761 Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars());
1762 LOG_SCOPE; 1762 LOG_SCOPE;
1763 DtoResolveDsymbol(dsym); 1763 DtoResolveDsymbol(dsym);
1764 1764
1765 DtoEmptyResolveList(); 1765 DtoEmptyResolveList();