comparison gen/functions.cpp @ 797:340acf1535d0

Removed KDevelop3 project files, CMake can generate them just fine! Fixed function literals in static initializers. Changed alignment of delegates from 2*PTRSIZE to just PTRSIZE. Changed errors to go to stderr instead of stdout. Fairly major rewriting of struct/union/class handling, STILL A BIT BUGGY !!!
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 29 Nov 2008 21:25:43 +0100
parents f04dde6e882c
children 504a21e81a46
comparison
equal deleted inserted replaced
796:6e7a4c3b64d2 797:340acf1535d0
95 paramvec.push_back(nesttype); 95 paramvec.push_back(nesttype);
96 usesnest = true; 96 usesnest = true;
97 } 97 }
98 98
99 if (dVararg) { 99 if (dVararg) {
100 ClassDeclaration* ti = Type::typeinfo; 100 paramvec.push_back(DtoType(Type::typeinfo->type->arrayOf())); // _arguments
101 ti->toObjFile(0); // TODO: multiobj 101 paramvec.push_back(getVoidPtrType()); // _argptr
102 DtoForceConstInitDsymbol(ti);
103 assert(ti->ir.irStruct->constInit);
104 std::vector<const LLType*> types;
105 types.push_back(DtoSize_t());
106 types.push_back(getPtrToType(getPtrToType(ti->ir.irStruct->constInit->getType())));
107 const LLType* t1 = llvm::StructType::get(types);
108 paramvec.push_back(t1);
109 paramvec.push_back(getPtrToType(LLType::Int8Ty));
110 } 102 }
111 103
112 // number of formal params 104 // number of formal params
113 size_t n = Argument::dim(f->parameters); 105 size_t n = Argument::dim(f->parameters);
114 106
284 if (fdecl->needThis()) { 276 if (fdecl->needThis()) {
285 if (AggregateDeclaration* ad = fdecl->isMember2()) { 277 if (AggregateDeclaration* ad = fdecl->isMember2()) {
286 Logger::println("isMember = this is: %s", ad->type->toChars()); 278 Logger::println("isMember = this is: %s", ad->type->toChars());
287 thisty = DtoType(ad->type); 279 thisty = DtoType(ad->type);
288 //Logger::cout() << "this llvm type: " << *thisty << '\n'; 280 //Logger::cout() << "this llvm type: " << *thisty << '\n';
289 if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->recty.get())) 281 if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->type->ir.type->get()))
290 thisty = getPtrToType(thisty); 282 thisty = getPtrToType(thisty);
291 } 283 }
292 else { 284 else {
293 Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind()); 285 Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind());
294 assert(0); 286 assert(0);
545 else if (fdecl->isStaticDtorDeclaration() && fdecl->getModule() == gIR->dmodule) { 537 else if (fdecl->isStaticDtorDeclaration() && fdecl->getModule() == gIR->dmodule) {
546 gIR->dtors.push_back(fdecl); 538 gIR->dtors.push_back(fdecl);
547 } 539 }
548 540
549 // we never reference parameters of function prototypes 541 // we never reference parameters of function prototypes
542 std::string str;
550 if (!declareOnly) 543 if (!declareOnly)
551 { 544 {
552 // name parameters 545 // name parameters
553 llvm::Function::arg_iterator iarg = func->arg_begin(); 546 llvm::Function::arg_iterator iarg = func->arg_begin();
554 547
555 if (f->retInPtr) { 548 if (f->retInPtr) {
556 iarg->setName(".sretarg"); 549 iarg->setName(".sret_arg");
557 fdecl->ir.irFunc->retArg = iarg; 550 fdecl->ir.irFunc->retArg = iarg;
558 ++iarg; 551 ++iarg;
559 } 552 }
560 553
561 if (f->usesThis) { 554 if (f->usesThis) {
562 iarg->setName("this"); 555 iarg->setName(".this_arg");
563 fdecl->ir.irFunc->thisArg = iarg; 556 fdecl->ir.irFunc->thisArg = iarg;
564 assert(fdecl->ir.irFunc->thisArg); 557 assert(fdecl->ir.irFunc->thisArg);
565 ++iarg; 558 ++iarg;
566 } 559 }
567 else if (f->usesNest) { 560 else if (f->usesNest) {
568 iarg->setName(".nest"); 561 iarg->setName(".nest_arg");
569 fdecl->ir.irFunc->nestArg = iarg; 562 fdecl->ir.irFunc->nestArg = iarg;
570 assert(fdecl->ir.irFunc->nestArg); 563 assert(fdecl->ir.irFunc->nestArg);
571 ++iarg; 564 ++iarg;
572 } 565 }
573 566
574 if (f->linkage == LINKd && f->varargs == 1) { 567 if (f->linkage == LINKd && f->varargs == 1) {
575 iarg->setName("_arguments"); 568 iarg->setName("._arguments");
576 fdecl->ir.irFunc->_arguments = iarg; 569 fdecl->ir.irFunc->_arguments = iarg;
577 ++iarg; 570 ++iarg;
578 iarg->setName("_argptr"); 571 iarg->setName("._argptr");
579 fdecl->ir.irFunc->_argptr = iarg; 572 fdecl->ir.irFunc->_argptr = iarg;
580 ++iarg; 573 ++iarg;
581 } 574 }
582 575
583 int k = 0; 576 int k = 0;
595 VarDeclaration* argvd = argsym->isVarDeclaration(); 588 VarDeclaration* argvd = argsym->isVarDeclaration();
596 assert(argvd); 589 assert(argvd);
597 assert(!argvd->ir.irLocal); 590 assert(!argvd->ir.irLocal);
598 argvd->ir.irLocal = new IrLocal(argvd); 591 argvd->ir.irLocal = new IrLocal(argvd);
599 argvd->ir.irLocal->value = iarg; 592 argvd->ir.irLocal->value = iarg;
600 iarg->setName(argvd->ident->toChars()); 593
594 str = argvd->ident->toChars();
595 str.append("_arg");
596 iarg->setName(str);
601 597
602 k++; 598 k++;
603 } 599 }
604 else 600 else
605 { 601 {
669 gIR->functions.push_back(irfunction); 665 gIR->functions.push_back(irfunction);
670 666
671 if (fd->isMain()) 667 if (fd->isMain())
672 gIR->emitMain = true; 668 gIR->emitMain = true;
673 669
674 std::string entryname("entry_"); 670 std::string entryname("entry");
675 entryname.append(fd->toPrettyChars());
676 671
677 llvm::BasicBlock* beginbb = llvm::BasicBlock::Create(entryname,func); 672 llvm::BasicBlock* beginbb = llvm::BasicBlock::Create(entryname,func);
678 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endentry",func); 673 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endentry",func);
679 674
680 //assert(gIR->scopes.empty()); 675 //assert(gIR->scopes.empty());
708 if (f->usesThis) 703 if (f->usesThis)
709 { 704 {
710 LLValue* thisvar = irfunction->thisArg; 705 LLValue* thisvar = irfunction->thisArg;
711 assert(thisvar); 706 assert(thisvar);
712 707
713 LLValue* thismem = DtoAlloca(thisvar->getType(), ".this"); 708 LLValue* thismem = DtoAlloca(thisvar->getType(), "this");
714 DtoStore(thisvar, thismem); 709 DtoStore(thisvar, thismem);
715 irfunction->thisArg = thismem; 710 irfunction->thisArg = thismem;
716 711
717 assert(!fd->vthis->ir.irLocal); 712 assert(!fd->vthis->ir.irLocal);
718 fd->vthis->ir.irLocal = new IrLocal(fd->vthis); 713 fd->vthis->ir.irLocal = new IrLocal(fd->vthis);
758 bool lazy = vd->storage_class & STClazy; 753 bool lazy = vd->storage_class & STClazy;
759 754
760 if (!refout && (!DtoIsPassedByRef(vd->type) || lazy)) 755 if (!refout && (!DtoIsPassedByRef(vd->type) || lazy))
761 { 756 {
762 LLValue* a = irloc->value; 757 LLValue* a = irloc->value;
763 LLValue* v = DtoAlloca(a->getType(), "."+a->getName()); 758 LLValue* v = DtoAlloca(a->getType(), vd->ident->toChars());
764 DtoStore(a,v); 759 DtoStore(a,v);
765 irloc->value = v; 760 irloc->value = v;
766 } 761 }
767 if (global.params.symdebug && !(isaArgument(irloc->value) && !isaArgument(irloc->value)->hasByValAttr()) && !refout) 762 if (global.params.symdebug && !(isaArgument(irloc->value) && !isaArgument(irloc->value)->hasByValAttr()) && !refout)
768 DtoDwarfLocalVariable(irloc->value, vd); 763 DtoDwarfLocalVariable(irloc->value, vd);
820 assert(fd->isMember2()); 815 assert(fd->isMember2());
821 LLValue* thisval = DtoLoad(irfunction->thisArg); 816 LLValue* thisval = DtoLoad(irfunction->thisArg);
822 ClassDeclaration* cd = fd->isMember2()->isClassDeclaration(); 817 ClassDeclaration* cd = fd->isMember2()->isClassDeclaration();
823 assert(cd); 818 assert(cd);
824 assert(cd->vthis); 819 assert(cd->vthis);
825 src = DtoLoad(DtoGEPi(thisval, 0,2+cd->vthis->ir.irField->index, ".vthis")); 820 src = DtoLoad(DtoGEPi(thisval, 0,cd->vthis->ir.irField->index, ".vthis"));
826 } 821 }
827 DtoMemCpy(nestedVars, src, DtoConstSize_t(nparelems*PTRSIZE)); 822 DtoMemCpy(nestedVars, src, DtoConstSize_t(nparelems*PTRSIZE));
828 } 823 }
829 824
830 // store in IrFunction 825 // store in IrFunction