comparison gen/tollvm.cpp @ 173:db9890b3fb64 trunk

[svn r189] moving IR data back into DMD frontend nodes
author ChristianK
date Tue, 06 May 2008 07:56:03 +0200
parents a8cd9bc1021a
children cea8dcfa76df
comparison
equal deleted inserted replaced
172:68a7dd38c03c 173:db9890b3fb64
96 case Tvoid: 96 case Tvoid:
97 return llvm::Type::VoidTy; 97 return llvm::Type::VoidTy;
98 98
99 // aggregates 99 // aggregates
100 case Tstruct: { 100 case Tstruct: {
101 if (!gIR->irType[t].type || *gIR->irType[t].type == NULL) { 101 if (!t->ir.type || *t->ir.type == NULL) {
102 // recursive or cyclic declaration 102 // recursive or cyclic declaration
103 if (!gIR->structs.empty()) 103 if (!gIR->structs.empty())
104 { 104 {
105 IrStruct* found = 0; 105 IrStruct* found = 0;
106 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i) 106 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i)
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 gIR->irDsymbol[ts->sym].irStruct->recty.get(); // gIR->irType[t].type->get(); 119 return ts->sym->ir.irStruct->recty.get(); // t->ir.type->get();
120 } 120 }
121 121
122 case Tclass: { 122 case Tclass: {
123 /*if (!gIR->irType[t].type || *gIR->irType[t].type == NULL) { 123 /*if (!t].type || *gIR->irType[t->ir.type == NULL) {
124 // recursive or cyclic declaration 124 // recursive or cyclic declaration
125 if (!gIR->structs.empty()) 125 if (!gIR->structs.empty())
126 { 126 {
127 IrStruct* found = 0; 127 IrStruct* found = 0;
128 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i) 128 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i)
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(gIR->irDsymbol[tc->sym].irStruct->recty.get()); // gIR->irType[t].type->get()); 142 return getPtrToType(tc->sym->ir.irStruct->recty.get()); // t->ir.type->get());
143 } 143 }
144 144
145 // functions 145 // functions
146 case Tfunction: 146 case Tfunction:
147 { 147 {
148 if (!gIR->irType[t].type || *gIR->irType[t].type == NULL) { 148 if (!t->ir.type || *t->ir.type == NULL) {
149 return DtoFunctionType(t,NULL); 149 return DtoFunctionType(t,NULL);
150 } 150 }
151 else { 151 else {
152 return gIR->irType[t].type->get(); 152 return t->ir.type->get();
153 } 153 }
154 } 154 }
155 155
156 // delegates 156 // delegates
157 case Tdelegate: 157 case Tdelegate:
158 { 158 {
159 if (!gIR->irType[t].type || *gIR->irType[t].type == NULL) { 159 if (!t->ir.type || *t->ir.type == NULL) {
160 return DtoDelegateType(t); 160 return DtoDelegateType(t);
161 } 161 }
162 else { 162 else {
163 return gIR->irType[t].type->get(); 163 return t->ir.type->get();
164 } 164 }
165 } 165 }
166 166
167 // typedefs 167 // typedefs
168 // enum 168 // enum
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(gIR->irDsymbol[ts->sym].irStruct->constInit); 564 assert(ts->sym->ir.irStruct->constInit);
565 _init = gIR->irDsymbol[ts->sym].irStruct->constInit; 565 _init = ts->sym->ir.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->irDsymbol[fd].irFunc->nestedVar; 727 llvm::Value* v = fd->ir.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->irDsymbol[func].irFunc->nestedVar) 757 if (!func->ir.irFunc->nestedVar)
758 return NULL; 758 return NULL;
759 return DtoBitCast(v, gIR->irDsymbol[func].irFunc->nestedVar->getType()); 759 return DtoBitCast(v, func->ir.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 += gIR->irDsymbol[cd].irStruct->interfaceVec.size(); 773 //idx += cd->ir.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->irDsymbol[irfunc->decl].irFunc->nestedVar; 810 return irfunc->decl->ir.irFunc->nestedVar;
811 811
812 // use the 'this' pointer 812 // use the 'this' pointer
813 llvm::Value* ptr = gIR->irDsymbol[irfunc->decl].irFunc->thisVar; 813 llvm::Value* ptr = irfunc->decl->ir.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->irDsymbol[func].irFunc->nestedVar->getType()); 881 ptr = DtoBitCast(ptr, func->ir.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, gIR->irDsymbol[vd].irLocal->nestedIndex, "tmp"); 884 llvm::Value* v = DtoGEPi(ptr, 0, vd->ir.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->irDsymbol[fdecl].irFunc->thisVar)) 967 if (!llvm::isa<llvm::AllocaInst>(fdecl->ir.irFunc->thisVar))
968 gIR->irDsymbol[fdecl].irFunc->thisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint()); 968 fdecl->ir.irFunc->thisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint());
969 DtoStore(tmp, gIR->irDsymbol[fdecl].irFunc->thisVar); 969 DtoStore(tmp, fdecl->ir.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 (gIR->irDsymbol[vd].initialized) return; 1575 if (vd->ir.initialized) return;
1576 gIR->irDsymbol[vd].initialized = gIR->dmodule; 1576 vd->ir.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(gIR->irDsymbol[ts->sym].irStruct->constInit); 1608 assert(ts->sym->ir.irStruct->constInit);
1609 _init = gIR->irDsymbol[ts->sym].irStruct->constInit; 1609 _init = ts->sym->ir.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>(gIR->irDsymbol[vd].irGlobal->type.get())->refineAbstractTypeTo(_type); 1629 llvm::cast<llvm::OpaqueType>(vd->ir.irGlobal->type.get())->refineAbstractTypeTo(_type);
1630 _type = gIR->irDsymbol[vd].irGlobal->type.get(); 1630 _type = vd->ir.irGlobal->type.get();
1631 //_type->dump(); 1631 //_type->dump();
1632 assert(!_type->isAbstract()); 1632 assert(!_type->isAbstract());
1633 1633
1634 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(gIR->irDsymbol[vd].irGlobal->value); 1634 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(vd->ir.irGlobal->value);
1635 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl)) 1635 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl))
1636 { 1636 {
1637 gvar->setInitializer(_init); 1637 gvar->setInitializer(_init);
1638 } 1638 }
1639 1639
1727 1727
1728 ////////////////////////////////////////////////////////////////////////////////////////// 1728 //////////////////////////////////////////////////////////////////////////////////////////
1729 1729
1730 void DtoForceDeclareDsymbol(Dsymbol* dsym) 1730 void DtoForceDeclareDsymbol(Dsymbol* dsym)
1731 { 1731 {
1732 if (gIR->irDsymbol[dsym].declared) return; 1732 if (dsym->ir.declared) return;
1733 Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toPrettyChars()); 1733 Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toPrettyChars());
1734 LOG_SCOPE; 1734 LOG_SCOPE;
1735 DtoResolveDsymbol(dsym); 1735 DtoResolveDsymbol(dsym);
1736 1736
1737 DtoEmptyResolveList(); 1737 DtoEmptyResolveList();
1741 1741
1742 ////////////////////////////////////////////////////////////////////////////////////////// 1742 //////////////////////////////////////////////////////////////////////////////////////////
1743 1743
1744 void DtoForceConstInitDsymbol(Dsymbol* dsym) 1744 void DtoForceConstInitDsymbol(Dsymbol* dsym)
1745 { 1745 {
1746 if (gIR->irDsymbol[dsym].initialized) return; 1746 if (dsym->ir.initialized) return;
1747 Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toPrettyChars()); 1747 Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toPrettyChars());
1748 LOG_SCOPE; 1748 LOG_SCOPE;
1749 DtoResolveDsymbol(dsym); 1749 DtoResolveDsymbol(dsym);
1750 1750
1751 DtoEmptyResolveList(); 1751 DtoEmptyResolveList();
1756 1756
1757 ////////////////////////////////////////////////////////////////////////////////////////// 1757 //////////////////////////////////////////////////////////////////////////////////////////
1758 1758
1759 void DtoForceDefineDsymbol(Dsymbol* dsym) 1759 void DtoForceDefineDsymbol(Dsymbol* dsym)
1760 { 1760 {
1761 if (gIR->irDsymbol[dsym].defined) return; 1761 if (dsym->ir.defined) return;
1762 Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars()); 1762 Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars());
1763 LOG_SCOPE; 1763 LOG_SCOPE;
1764 DtoResolveDsymbol(dsym); 1764 DtoResolveDsymbol(dsym);
1765 1765
1766 DtoEmptyResolveList(); 1766 DtoEmptyResolveList();
1795 // build interface info type 1795 // build interface info type
1796 std::vector<const llvm::Type*> types; 1796 std::vector<const llvm::Type*> types;
1797 // ClassInfo classinfo 1797 // ClassInfo classinfo
1798 ClassDeclaration* cd2 = ClassDeclaration::classinfo; 1798 ClassDeclaration* cd2 = ClassDeclaration::classinfo;
1799 DtoResolveClass(cd2); 1799 DtoResolveClass(cd2);
1800 types.push_back(getPtrToType(gIR->irType[cd2->type].type->get())); 1800 types.push_back(getPtrToType(cd2->type->ir.type->get()));
1801 // void*[] vtbl 1801 // void*[] vtbl
1802 std::vector<const llvm::Type*> vtbltypes; 1802 std::vector<const llvm::Type*> vtbltypes;
1803 vtbltypes.push_back(DtoSize_t()); 1803 vtbltypes.push_back(DtoSize_t());
1804 const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); 1804 const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
1805 vtbltypes.push_back(byteptrptrty); 1805 vtbltypes.push_back(byteptrptrty);