Mercurial > projects > ldc
comparison gen/classes.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 |
---|---|
551 assert(dsym); | 551 assert(dsym); |
552 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; | 552 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; |
553 | 553 |
554 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { | 554 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { |
555 DtoForceDeclareDsymbol(fd); | 555 DtoForceDeclareDsymbol(fd); |
556 assert(fd->irFunc->func); | 556 assert(gIR->irFunc[fd]->func); |
557 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->irFunc->func); | 557 llvm::Constant* c = llvm::cast<llvm::Constant>(gIR->irFunc[fd]->func); |
558 // cast if necessary (overridden method) | 558 // cast if necessary (overridden method) |
559 if (c->getType() != vtbltype->getElementType(k)) | 559 if (c->getType() != vtbltype->getElementType(k)) |
560 c = llvm::ConstantExpr::getBitCast(c, vtbltype->getElementType(k)); | 560 c = llvm::ConstantExpr::getBitCast(c, vtbltype->getElementType(k)); |
561 sinits.push_back(c); | 561 sinits.push_back(c); |
562 } | 562 } |
634 Dsymbol* dsym = (Dsymbol*)b->vtbl.data[k]; | 634 Dsymbol* dsym = (Dsymbol*)b->vtbl.data[k]; |
635 assert(dsym); | 635 assert(dsym); |
636 FuncDeclaration* fd = dsym->isFuncDeclaration(); | 636 FuncDeclaration* fd = dsym->isFuncDeclaration(); |
637 assert(fd); | 637 assert(fd); |
638 DtoForceDeclareDsymbol(fd); | 638 DtoForceDeclareDsymbol(fd); |
639 assert(fd->irFunc->func); | 639 assert(gIR->irFunc[fd]->func); |
640 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->irFunc->func); | 640 llvm::Constant* c = llvm::cast<llvm::Constant>(gIR->irFunc[fd]->func); |
641 | 641 |
642 // we have to bitcast, as the type created in ResolveClass expects a different this type | 642 // we have to bitcast, as the type created in ResolveClass expects a different this type |
643 c = llvm::ConstantExpr::getBitCast(c, iri->vtblTy->getContainedType(k)); | 643 c = llvm::ConstantExpr::getBitCast(c, iri->vtblTy->getContainedType(k)); |
644 iinits.push_back(c); | 644 iinits.push_back(c); |
645 } | 645 } |
781 { | 781 { |
782 Logger::println("Resolving nested context"); | 782 Logger::println("Resolving nested context"); |
783 LOG_SCOPE; | 783 LOG_SCOPE; |
784 size_t idx = 2; | 784 size_t idx = 2; |
785 //idx += tc->sym->irStruct->interfaces.size(); | 785 //idx += tc->sym->irStruct->interfaces.size(); |
786 llvm::Value* nest = gIR->func()->decl->irFunc->nestedVar; | 786 llvm::Value* nest = gIR->irFunc[gIR->func()->decl]->nestedVar; |
787 if (!nest) | 787 if (!nest) |
788 nest = gIR->func()->decl->irFunc->thisVar; | 788 nest = gIR->irFunc[gIR->func()->decl]->thisVar; |
789 assert(nest); | 789 assert(nest); |
790 llvm::Value* gep = DtoGEPi(mem,0,idx,"tmp"); | 790 llvm::Value* gep = DtoGEPi(mem,0,idx,"tmp"); |
791 nest = DtoBitCast(nest, gep->getType()->getContainedType(0)); | 791 nest = DtoBitCast(nest, gep->getType()->getContainedType(0)); |
792 DtoStore(nest, gep); | 792 DtoStore(nest, gep); |
793 } | 793 } |
849 Logger::println("Calling constructor"); | 849 Logger::println("Calling constructor"); |
850 LOG_SCOPE; | 850 LOG_SCOPE; |
851 | 851 |
852 assert(ctor); | 852 assert(ctor); |
853 DtoForceDeclareDsymbol(ctor); | 853 DtoForceDeclareDsymbol(ctor); |
854 llvm::Function* fn = ctor->irFunc->func; | 854 llvm::Function* fn = gIR->irFunc[ctor]->func; |
855 TypeFunction* tf = (TypeFunction*)DtoDType(ctor->type); | 855 TypeFunction* tf = (TypeFunction*)DtoDType(ctor->type); |
856 | 856 |
857 std::vector<llvm::Value*> ctorargs; | 857 std::vector<llvm::Value*> ctorargs; |
858 ctorargs.push_back(mem); | 858 ctorargs.push_back(mem); |
859 for (size_t i=0; i<arguments->dim; ++i) | 859 for (size_t i=0; i<arguments->dim; ++i) |
879 { | 879 { |
880 Array* arr = &tc->sym->dtors; | 880 Array* arr = &tc->sym->dtors; |
881 for (size_t i=0; i<arr->dim; i++) | 881 for (size_t i=0; i<arr->dim; i++) |
882 { | 882 { |
883 FuncDeclaration* fd = (FuncDeclaration*)arr->data[i]; | 883 FuncDeclaration* fd = (FuncDeclaration*)arr->data[i]; |
884 assert(fd->irFunc->func); | 884 assert(gIR->irFunc[fd]->func); |
885 new llvm::CallInst(fd->irFunc->func, instance, "", gIR->scopebb()); | 885 new llvm::CallInst(gIR->irFunc[fd]->func, instance, "", gIR->scopebb()); |
886 } | 886 } |
887 } | 887 } |
888 | 888 |
889 ////////////////////////////////////////////////////////////////////////////////////////// | 889 ////////////////////////////////////////////////////////////////////////////////////////// |
890 | 890 |
1298 return llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)); | 1298 return llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)); |
1299 } | 1299 } |
1300 else if (cd->dtors.dim == 1) { | 1300 else if (cd->dtors.dim == 1) { |
1301 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[0]; | 1301 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[0]; |
1302 DtoForceDeclareDsymbol(d); | 1302 DtoForceDeclareDsymbol(d); |
1303 assert(d->irFunc->func); | 1303 assert(gIR->irFunc[d]->func); |
1304 return llvm::ConstantExpr::getBitCast(isaConstant(d->irFunc->func), getPtrToType(llvm::Type::Int8Ty)); | 1304 return llvm::ConstantExpr::getBitCast(isaConstant(gIR->irFunc[d]->func), getPtrToType(llvm::Type::Int8Ty)); |
1305 } | 1305 } |
1306 | 1306 |
1307 std::string gname("_D"); | 1307 std::string gname("_D"); |
1308 gname.append(cd->mangle()); | 1308 gname.append(cd->mangle()); |
1309 gname.append("12__destructorMFZv"); | 1309 gname.append("12__destructorMFZv"); |
1317 | 1317 |
1318 for (size_t i = 0; i < cd->dtors.dim; i++) | 1318 for (size_t i = 0; i < cd->dtors.dim; i++) |
1319 { | 1319 { |
1320 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[i]; | 1320 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[i]; |
1321 DtoForceDeclareDsymbol(d); | 1321 DtoForceDeclareDsymbol(d); |
1322 assert(d->irFunc->func); | 1322 assert(gIR->irFunc[d]->func); |
1323 builder.CreateCall(d->irFunc->func, thisptr); | 1323 builder.CreateCall(gIR->irFunc[d]->func, thisptr); |
1324 } | 1324 } |
1325 builder.CreateRetVoid(); | 1325 builder.CreateRetVoid(); |
1326 | 1326 |
1327 return llvm::ConstantExpr::getBitCast(func, getPtrToType(llvm::Type::Int8Ty)); | 1327 return llvm::ConstantExpr::getBitCast(func, getPtrToType(llvm::Type::Int8Ty)); |
1328 } | 1328 } |
1514 inits.push_back(c); | 1514 inits.push_back(c); |
1515 | 1515 |
1516 // default constructor | 1516 // default constructor |
1517 if (cd->defaultCtor && !cd->isInterfaceDeclaration() && !cd->isAbstract()) { | 1517 if (cd->defaultCtor && !cd->isInterfaceDeclaration() && !cd->isAbstract()) { |
1518 DtoForceDeclareDsymbol(cd->defaultCtor); | 1518 DtoForceDeclareDsymbol(cd->defaultCtor); |
1519 c = isaConstant(cd->defaultCtor->irFunc->func); | 1519 c = isaConstant(gIR->irFunc[cd->defaultCtor]->func); |
1520 const llvm::Type* toTy = cinfo->irStruct->constInit->getOperand(12)->getType(); | 1520 const llvm::Type* toTy = cinfo->irStruct->constInit->getOperand(12)->getType(); |
1521 c = llvm::ConstantExpr::getBitCast(c, toTy); | 1521 c = llvm::ConstantExpr::getBitCast(c, toTy); |
1522 } | 1522 } |
1523 else { | 1523 else { |
1524 c = cinfo->irStruct->constInit->getOperand(12); | 1524 c = cinfo->irStruct->constInit->getOperand(12); |