Mercurial > projects > ldc
comparison gen/typinf.c @ 73:b706170e24a9 trunk
[svn r77] Fixed foreach on slice.
Fixed some nested function problems when accessing outer function parameters.
Major changes to handling of structs.
Initial support for unions.
Probably more...
author | lindquist |
---|---|
date | Wed, 31 Oct 2007 03:11:32 +0100 |
parents | d7e764e62462 |
children | 3587401b6eeb |
comparison
equal
deleted
inserted
replaced
72:d7e764e62462 | 73:b706170e24a9 |
---|---|
322 sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(cisize), cicast)); | 322 sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(cisize), cicast)); |
323 } | 323 } |
324 | 324 |
325 // create the symbol | 325 // create the symbol |
326 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 326 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
327 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::InternalLinkage,tiInit,toChars(),gIR->module); | 327 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
328 | 328 |
329 llvmValue = gvar; | 329 llvmValue = gvar; |
330 } | 330 } |
331 | 331 |
332 /* ========================================================================= */ | 332 /* ========================================================================= */ |
387 sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(cisize), cicast)); | 387 sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(cisize), cicast)); |
388 } | 388 } |
389 | 389 |
390 // create the symbol | 390 // create the symbol |
391 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 391 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
392 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::InternalLinkage,tiInit,toChars(),gIR->module); | 392 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
393 | 393 |
394 llvmValue = gvar; | 394 llvmValue = gvar; |
395 } | 395 } |
396 | 396 |
397 /* ========================================================================= */ | 397 /* ========================================================================= */ |
419 castbase = llvm::ConstantExpr::getBitCast(castbase, initZ->getOperand(1)->getType()); | 419 castbase = llvm::ConstantExpr::getBitCast(castbase, initZ->getOperand(1)->getType()); |
420 sinits.push_back(castbase); | 420 sinits.push_back(castbase); |
421 | 421 |
422 // create the symbol | 422 // create the symbol |
423 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 423 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
424 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::InternalLinkage,tiInit,tid->toChars(),gIR->module); | 424 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,tid->toChars(),gIR->module); |
425 | 425 |
426 tid->llvmValue = gvar; | 426 tid->llvmValue = gvar; |
427 } | 427 } |
428 | 428 |
429 /* ========================================================================= */ | 429 /* ========================================================================= */ |
543 sinits.push_back(base->llvmVtbl); | 543 sinits.push_back(base->llvmVtbl); |
544 | 544 |
545 // char[] name | 545 // char[] name |
546 char *name = sd->toPrettyChars(); | 546 char *name = sd->toPrettyChars(); |
547 sinits.push_back(LLVM_DtoConstString(name)); | 547 sinits.push_back(LLVM_DtoConstString(name)); |
548 Logger::println("************** A"); | |
548 assert(sinits.back()->getType() == stype->getElementType(1)); | 549 assert(sinits.back()->getType() == stype->getElementType(1)); |
549 | 550 |
550 // void[] init | 551 // void[] init |
551 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); | 552 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); |
552 if (sd->zeroInit) // 0 initializer, or the same as the base type | 553 if (sd->zeroInit) // 0 initializer, or the same as the base type |
604 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | 605 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); |
605 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | 606 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); |
606 } | 607 } |
607 #endif | 608 #endif |
608 | 609 |
610 Logger::println("************** B"); | |
609 const llvm::PointerType* ptty = llvm::cast<llvm::PointerType>(stype->getElementType(3)); | 611 const llvm::PointerType* ptty = llvm::cast<llvm::PointerType>(stype->getElementType(3)); |
610 | 612 |
611 s = search_function(sd, Id::tohash); | 613 s = search_function(sd, Id::tohash); |
612 fdx = s ? s->isFuncDeclaration() : NULL; | 614 fdx = s ? s->isFuncDeclaration() : NULL; |
613 if (fdx) | 615 if (fdx) |
631 | 633 |
632 s = search_function(sd, Id::eq); | 634 s = search_function(sd, Id::eq); |
633 fdx = s ? s->isFuncDeclaration() : NULL; | 635 fdx = s ? s->isFuncDeclaration() : NULL; |
634 for (int i = 0; i < 2; i++) | 636 for (int i = 0; i < 2; i++) |
635 { | 637 { |
638 Logger::println("************** C %d", i); | |
636 ptty = llvm::cast<llvm::PointerType>(stype->getElementType(4+i)); | 639 ptty = llvm::cast<llvm::PointerType>(stype->getElementType(4+i)); |
637 if (fdx) | 640 if (fdx) |
638 { | 641 { |
639 fd = fdx->overloadExactMatch(tfeqptr); | 642 fd = fdx->overloadExactMatch(tfeqptr); |
640 if (fd) { | 643 if (fd) { |
655 | 658 |
656 s = search_function(sd, Id::cmp); | 659 s = search_function(sd, Id::cmp); |
657 fdx = s ? s->isFuncDeclaration() : NULL; | 660 fdx = s ? s->isFuncDeclaration() : NULL; |
658 } | 661 } |
659 | 662 |
663 Logger::println("************** D"); | |
660 ptty = llvm::cast<llvm::PointerType>(stype->getElementType(6)); | 664 ptty = llvm::cast<llvm::PointerType>(stype->getElementType(6)); |
661 s = search_function(sd, Id::tostring); | 665 s = search_function(sd, Id::tostring); |
662 fdx = s ? s->isFuncDeclaration() : NULL; | 666 fdx = s ? s->isFuncDeclaration() : NULL; |
663 if (fdx) | 667 if (fdx) |
664 { | 668 { |
682 // uint m_flags; | 686 // uint m_flags; |
683 sinits.push_back(LLVM_DtoConstUint(tc->hasPointers())); | 687 sinits.push_back(LLVM_DtoConstUint(tc->hasPointers())); |
684 | 688 |
685 // create the symbol | 689 // create the symbol |
686 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 690 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
687 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::InternalLinkage,tiInit,toChars(),gIR->module); | 691 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
688 | 692 |
689 llvmValue = gvar; | 693 llvmValue = gvar; |
690 | |
691 /* | |
692 //printf("TypeInfoStructDeclaration::toDt() '%s'\n", toChars()); | |
693 | |
694 unsigned offset = Type::typeinfostruct->structsize; | |
695 | |
696 dtxoff(pdt, Type::typeinfostruct->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Struct | |
697 dtdword(pdt, 0); // monitor | |
698 | |
699 assert(tinfo->ty == Tstruct); | |
700 | |
701 TypeStruct *tc = (TypeStruct *)tinfo; | |
702 StructDeclaration *sd = tc->sym; | |
703 | |
704 // Put out: | |
705 // char[] name; | |
706 // void[] init; | |
707 // hash_t function(void*) xtoHash; | |
708 // int function(void*,void*) xopEquals; | |
709 // int function(void*,void*) xopCmp; | |
710 // char[] function(void*) xtoString; | |
711 // uint m_flags; | |
712 // | |
713 // name[] | |
714 // | |
715 | |
716 char *name = sd->toPrettyChars(); | |
717 size_t namelen = strlen(name); | |
718 dtdword(pdt, namelen); | |
719 //dtabytes(pdt, TYnptr, 0, namelen + 1, name); | |
720 dtxoff(pdt, toSymbol(), offset, TYnptr); | |
721 offset += namelen + 1; | |
722 | |
723 // void[] init; | |
724 dtdword(pdt, sd->structsize); // init.length | |
725 if (sd->zeroInit) | |
726 dtdword(pdt, 0); // NULL for 0 initialization | |
727 else | |
728 dtxoff(pdt, sd->toInitializer(), 0, TYnptr); // init.ptr | |
729 | |
730 FuncDeclaration *fd; | |
731 FuncDeclaration *fdx; | |
732 TypeFunction *tf; | |
733 Type *ta; | |
734 Dsymbol *s; | |
735 | |
736 static TypeFunction *tftohash; | |
737 static TypeFunction *tftostring; | |
738 | |
739 if (!tftohash) | |
740 { | |
741 Scope sc; | |
742 | |
743 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd); | |
744 tftohash = (TypeFunction *)tftohash->semantic(0, &sc); | |
745 | |
746 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd); | |
747 tftostring = (TypeFunction *)tftostring->semantic(0, &sc); | |
748 } | |
749 | |
750 TypeFunction *tfeqptr; | |
751 { | |
752 Scope sc; | |
753 Arguments *arguments = new Arguments; | |
754 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL); | |
755 | |
756 arguments->push(arg); | |
757 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
758 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc); | |
759 } | |
760 | |
761 #if 0 | |
762 TypeFunction *tfeq; | |
763 { | |
764 Scope sc; | |
765 Array *arguments = new Array; | |
766 Argument *arg = new Argument(In, tc, NULL, NULL); | |
767 | |
768 arguments->push(arg); | |
769 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
770 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | |
771 } | |
772 #endif | |
773 | |
774 s = search_function(sd, Id::tohash); | |
775 fdx = s ? s->isFuncDeclaration() : NULL; | |
776 if (fdx) | |
777 { fd = fdx->overloadExactMatch(tftohash); | |
778 if (fd) | |
779 dtxoff(pdt, fd->toSymbol(), 0, TYnptr); | |
780 else | |
781 //fdx->error("must be declared as extern (D) uint toHash()"); | |
782 dtdword(pdt, 0); | |
783 } | |
784 else | |
785 dtdword(pdt, 0); | |
786 | |
787 s = search_function(sd, Id::eq); | |
788 fdx = s ? s->isFuncDeclaration() : NULL; | |
789 for (int i = 0; i < 2; i++) | |
790 { | |
791 if (fdx) | |
792 { fd = fdx->overloadExactMatch(tfeqptr); | |
793 if (fd) | |
794 dtxoff(pdt, fd->toSymbol(), 0, TYnptr); | |
795 else | |
796 //fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); | |
797 dtdword(pdt, 0); | |
798 } | |
799 else | |
800 dtdword(pdt, 0); | |
801 | |
802 s = search_function(sd, Id::cmp); | |
803 fdx = s ? s->isFuncDeclaration() : NULL; | |
804 } | |
805 | |
806 s = search_function(sd, Id::tostring); | |
807 fdx = s ? s->isFuncDeclaration() : NULL; | |
808 if (fdx) | |
809 { fd = fdx->overloadExactMatch(tftostring); | |
810 if (fd) | |
811 dtxoff(pdt, fd->toSymbol(), 0, TYnptr); | |
812 else | |
813 //fdx->error("must be declared as extern (D) char[] toString()"); | |
814 dtdword(pdt, 0); | |
815 } | |
816 else | |
817 dtdword(pdt, 0); | |
818 | |
819 // uint m_flags; | |
820 dtdword(pdt, tc->hasPointers()); | |
821 | |
822 // name[] | |
823 dtnbytes(pdt, namelen + 1, name); | |
824 */ | |
825 } | 694 } |
826 | 695 |
827 /* ========================================================================= */ | 696 /* ========================================================================= */ |
828 | 697 |
829 void TypeInfoClassDeclaration::toDt(dt_t **pdt) | 698 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |