Mercurial > projects > ldc
comparison gen/typinf.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 | 6e7a4c3b64d2 |
children | 2dfd05525e2e |
comparison
equal
deleted
inserted
replaced
796:6e7a4c3b64d2 | 797:340acf1535d0 |
---|---|
377 DtoResolveClass(base); | 377 DtoResolveClass(base); |
378 | 378 |
379 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | 379 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
380 | 380 |
381 // create the symbol | 381 // create the symbol |
382 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | 382 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
383 } | 383 } |
384 | 384 |
385 void TypeInfoTypedefDeclaration::llvmDefine() | 385 void TypeInfoTypedefDeclaration::llvmDefine() |
386 { | 386 { |
387 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars()); | 387 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars()); |
388 LOG_SCOPE; | 388 LOG_SCOPE; |
389 | 389 |
390 ClassDeclaration* base = Type::typeinfotypedef; | 390 ClassDeclaration* base = Type::typeinfotypedef; |
391 DtoForceConstInitDsymbol(base); | 391 DtoForceConstInitDsymbol(base); |
392 | |
393 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
394 if (Logger::enabled()) | |
395 Logger::cout() << "got stype: " << *stype << '\n'; | |
396 | 392 |
397 // vtbl | 393 // vtbl |
398 std::vector<LLConstant*> sinits; | 394 std::vector<LLConstant*> sinits; |
399 sinits.push_back(base->ir.irStruct->vtbl); | 395 sinits.push_back(base->ir.irStruct->vtbl); |
400 | 396 |
406 TypedefDeclaration *sd = tc->sym; | 402 TypedefDeclaration *sd = tc->sym; |
407 | 403 |
408 // TypeInfo base | 404 // TypeInfo base |
409 sd->basetype = sd->basetype->merge(); // DMD does this! | 405 sd->basetype = sd->basetype->merge(); // DMD does this! |
410 LLConstant* castbase = DtoTypeInfoOf(sd->basetype, true); | 406 LLConstant* castbase = DtoTypeInfoOf(sd->basetype, true); |
411 assert(castbase->getType() == stype->getElementType(2)); | |
412 sinits.push_back(castbase); | 407 sinits.push_back(castbase); |
413 | 408 |
414 // char[] name | 409 // char[] name |
415 char *name = sd->toPrettyChars(); | 410 char *name = sd->toPrettyChars(); |
416 sinits.push_back(DtoConstString(name)); | 411 sinits.push_back(DtoConstString(name)); |
417 assert(sinits.back()->getType() == stype->getElementType(3)); | |
418 | 412 |
419 // void[] init | 413 // void[] init |
420 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); | 414 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); |
421 if (tinfo->isZeroInit() || !sd->init) // 0 initializer, or the same as the base type | 415 if (tinfo->isZeroInit() || !sd->init) // 0 initializer, or the same as the base type |
422 { | 416 { |
431 LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); | 425 LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
432 size_t cisize = getTypeStoreSize(DtoType(sd->basetype)); | 426 size_t cisize = getTypeStoreSize(DtoType(sd->basetype)); |
433 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); | 427 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
434 } | 428 } |
435 | 429 |
436 // create the symbol | 430 // create the inititalizer |
437 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 431 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); |
438 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); | 432 |
433 // refine global type | |
434 llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
435 | |
436 // set the initializer | |
437 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); | |
439 } | 438 } |
440 | 439 |
441 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) | 440 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) |
442 { | 441 { |
443 assert(0); | 442 assert(0); |
451 LOG_SCOPE; | 450 LOG_SCOPE; |
452 | 451 |
453 ClassDeclaration* base = Type::typeinfoenum; | 452 ClassDeclaration* base = Type::typeinfoenum; |
454 DtoResolveClass(base); | 453 DtoResolveClass(base); |
455 | 454 |
456 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
457 | |
458 // create the symbol | 455 // create the symbol |
459 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | 456 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
460 } | 457 } |
461 | 458 |
462 void TypeInfoEnumDeclaration::llvmDefine() | 459 void TypeInfoEnumDeclaration::llvmDefine() |
463 { | 460 { |
464 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars()); | 461 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars()); |
465 LOG_SCOPE; | 462 LOG_SCOPE; |
466 | 463 |
467 ClassDeclaration* base = Type::typeinfoenum; | 464 ClassDeclaration* base = Type::typeinfoenum; |
468 DtoForceConstInitDsymbol(base); | 465 DtoForceConstInitDsymbol(base); |
469 | |
470 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
471 | 466 |
472 // vtbl | 467 // vtbl |
473 std::vector<LLConstant*> sinits; | 468 std::vector<LLConstant*> sinits; |
474 sinits.push_back(base->ir.irStruct->vtbl); | 469 sinits.push_back(base->ir.irStruct->vtbl); |
475 | 470 |
480 TypeEnum *tc = (TypeEnum *)tinfo; | 475 TypeEnum *tc = (TypeEnum *)tinfo; |
481 EnumDeclaration *sd = tc->sym; | 476 EnumDeclaration *sd = tc->sym; |
482 | 477 |
483 // TypeInfo base | 478 // TypeInfo base |
484 LLConstant* castbase = DtoTypeInfoOf(sd->memtype, true); | 479 LLConstant* castbase = DtoTypeInfoOf(sd->memtype, true); |
485 assert(castbase->getType() == stype->getElementType(2)); | |
486 sinits.push_back(castbase); | 480 sinits.push_back(castbase); |
487 | 481 |
488 // char[] name | 482 // char[] name |
489 char *name = sd->toPrettyChars(); | 483 char *name = sd->toPrettyChars(); |
490 sinits.push_back(DtoConstString(name)); | 484 sinits.push_back(DtoConstString(name)); |
491 assert(sinits.back()->getType() == stype->getElementType(3)); | |
492 | 485 |
493 // void[] init | 486 // void[] init |
494 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); | 487 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); |
495 if (tinfo->isZeroInit() || !sd->defaultval) // 0 initializer, or the same as the base type | 488 if (tinfo->isZeroInit() || !sd->defaultval) // 0 initializer, or the same as the base type |
496 { | 489 { |
510 size_t cisize = getTypeStoreSize(memty); | 503 size_t cisize = getTypeStoreSize(memty); |
511 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); | 504 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
512 #endif | 505 #endif |
513 } | 506 } |
514 | 507 |
515 // create the symbol | 508 // create the inititalizer |
516 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 509 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); |
517 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); | 510 |
511 // refine global type | |
512 llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
513 | |
514 // set the initializer | |
515 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); | |
518 } | 516 } |
519 | 517 |
520 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) | 518 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) |
521 { | 519 { |
522 assert(0); | 520 assert(0); |
527 static LLConstant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) | 525 static LLConstant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) |
528 { | 526 { |
529 ClassDeclaration* base = cd; | 527 ClassDeclaration* base = cd; |
530 DtoResolveClass(base); | 528 DtoResolveClass(base); |
531 | 529 |
532 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
533 | |
534 // create the symbol | 530 // create the symbol |
535 tid->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); | 531 tid->ir.irGlobal->value = new llvm::GlobalVariable(tid->ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); |
536 } | 532 } |
537 | 533 |
538 static LLConstant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) | 534 static LLConstant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) |
539 { | 535 { |
540 ClassDeclaration* base = cd; | 536 ClassDeclaration* base = cd; |
541 DtoForceConstInitDsymbol(base); | 537 DtoForceConstInitDsymbol(base); |
542 | |
543 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
544 | 538 |
545 // vtbl | 539 // vtbl |
546 std::vector<LLConstant*> sinits; | 540 std::vector<LLConstant*> sinits; |
547 sinits.push_back(base->ir.irStruct->vtbl); | 541 sinits.push_back(base->ir.irStruct->vtbl); |
548 | 542 |
549 // monitor | 543 // monitor |
550 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); | 544 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
551 | 545 |
552 // TypeInfo base | 546 // TypeInfo base |
553 LLConstant* castbase = DtoTypeInfoOf(basetype, true); | 547 LLConstant* castbase = DtoTypeInfoOf(basetype, true); |
554 assert(castbase->getType() == stype->getElementType(2)); | |
555 sinits.push_back(castbase); | 548 sinits.push_back(castbase); |
556 | 549 |
557 // create the symbol | 550 // create the inititalizer |
558 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 551 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); |
552 | |
553 // refine global type | |
554 llvm::cast<llvm::OpaqueType>(tid->ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
555 | |
556 // set the initializer | |
559 isaGlobalVar(tid->ir.irGlobal->value)->setInitializer(tiInit); | 557 isaGlobalVar(tid->ir.irGlobal->value)->setInitializer(tiInit); |
560 } | 558 } |
561 | 559 |
562 /* ========================================================================= */ | 560 /* ========================================================================= */ |
563 | 561 |
626 | 624 |
627 // init typeinfo class | 625 // init typeinfo class |
628 ClassDeclaration* base = Type::typeinfostaticarray; | 626 ClassDeclaration* base = Type::typeinfostaticarray; |
629 DtoResolveClass(base); | 627 DtoResolveClass(base); |
630 | 628 |
631 // get type of typeinfo class | |
632 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
633 | |
634 // create the symbol | 629 // create the symbol |
635 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | 630 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
636 } | 631 } |
637 | 632 |
638 void TypeInfoStaticArrayDeclaration::llvmDefine() | 633 void TypeInfoStaticArrayDeclaration::llvmDefine() |
639 { | 634 { |
640 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); | 635 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); |
663 sinits.push_back(castbase); | 658 sinits.push_back(castbase); |
664 | 659 |
665 // length | 660 // length |
666 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); | 661 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); |
667 | 662 |
668 // create the symbol | 663 // create the inititalizer |
669 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 664 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); |
670 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); | 665 |
666 // refine global type | |
667 llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
668 | |
669 // set the initializer | |
670 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); | |
671 } | 671 } |
672 | 672 |
673 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) | 673 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) |
674 { | 674 { |
675 assert(0); | 675 assert(0); |
684 | 684 |
685 // init typeinfo class | 685 // init typeinfo class |
686 ClassDeclaration* base = Type::typeinfoassociativearray; | 686 ClassDeclaration* base = Type::typeinfoassociativearray; |
687 DtoResolveClass(base); | 687 DtoResolveClass(base); |
688 | 688 |
689 // get type of typeinfo class | |
690 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
691 | |
692 // create the symbol | 689 // create the symbol |
693 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | 690 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
694 } | 691 } |
695 | 692 |
696 void TypeInfoAssociativeArrayDeclaration::llvmDefine() | 693 void TypeInfoAssociativeArrayDeclaration::llvmDefine() |
697 { | 694 { |
698 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); | 695 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
699 LOG_SCOPE; | 696 LOG_SCOPE; |
700 | 697 |
701 // init typeinfo class | 698 // init typeinfo class |
702 ClassDeclaration* base = Type::typeinfoassociativearray; | 699 ClassDeclaration* base = Type::typeinfoassociativearray; |
703 DtoForceConstInitDsymbol(base); | 700 DtoForceConstInitDsymbol(base); |
704 | |
705 // get type of typeinfo class | |
706 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
707 | 701 |
708 // initializer vector | 702 // initializer vector |
709 std::vector<LLConstant*> sinits; | 703 std::vector<LLConstant*> sinits; |
710 // first is always the vtable | 704 // first is always the vtable |
711 sinits.push_back(base->ir.irStruct->vtbl); | 705 sinits.push_back(base->ir.irStruct->vtbl); |
717 assert(tinfo->ty == Taarray); | 711 assert(tinfo->ty == Taarray); |
718 TypeAArray *tc = (TypeAArray *)tinfo; | 712 TypeAArray *tc = (TypeAArray *)tinfo; |
719 | 713 |
720 // value typeinfo | 714 // value typeinfo |
721 LLConstant* castbase = DtoTypeInfoOf(tc->next, true); | 715 LLConstant* castbase = DtoTypeInfoOf(tc->next, true); |
722 assert(castbase->getType() == stype->getElementType(2)); | |
723 sinits.push_back(castbase); | 716 sinits.push_back(castbase); |
724 | 717 |
725 // key typeinfo | 718 // key typeinfo |
726 castbase = DtoTypeInfoOf(tc->index, true); | 719 castbase = DtoTypeInfoOf(tc->index, true); |
727 assert(castbase->getType() == stype->getElementType(3)); | |
728 sinits.push_back(castbase); | 720 sinits.push_back(castbase); |
729 | 721 |
730 // create the symbol | 722 // create the inititalizer |
731 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 723 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); |
732 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); | 724 |
725 // refine global type | |
726 llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
727 | |
728 // set the initializer | |
729 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); | |
733 } | 730 } |
734 | 731 |
735 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) | 732 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
736 { | 733 { |
737 assert(0); | 734 assert(0); |
808 DtoResolveDsymbol(sd); | 805 DtoResolveDsymbol(sd); |
809 | 806 |
810 ClassDeclaration* base = Type::typeinfostruct; | 807 ClassDeclaration* base = Type::typeinfostruct; |
811 DtoResolveClass(base); | 808 DtoResolveClass(base); |
812 | 809 |
813 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
814 | |
815 // create the symbol | 810 // create the symbol |
816 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | 811 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
817 } | 812 } |
818 | 813 |
819 void TypeInfoStructDeclaration::llvmDefine() | 814 void TypeInfoStructDeclaration::llvmDefine() |
820 { | 815 { |
821 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); | 816 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); |
999 //void function(void*) xpostblit; | 994 //void function(void*) xpostblit; |
1000 sinits.push_back(LLConstant::getNullValue(stype->getElementType(sinits.size()))); | 995 sinits.push_back(LLConstant::getNullValue(stype->getElementType(sinits.size()))); |
1001 | 996 |
1002 #endif | 997 #endif |
1003 | 998 |
1004 // create the symbol | 999 // create the inititalizer |
1005 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 1000 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); |
1006 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); | 1001 |
1002 // refine global type | |
1003 llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
1004 | |
1005 // set the initializer | |
1006 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); | |
1007 } | 1007 } |
1008 | 1008 |
1009 void TypeInfoStructDeclaration::toDt(dt_t **pdt) | 1009 void TypeInfoStructDeclaration::toDt(dt_t **pdt) |
1010 { | 1010 { |
1011 assert(0); | 1011 assert(0); |
1021 // init typeinfo class | 1021 // init typeinfo class |
1022 ClassDeclaration* base = Type::typeinfoclass; | 1022 ClassDeclaration* base = Type::typeinfoclass; |
1023 assert(base); | 1023 assert(base); |
1024 DtoResolveClass(base); | 1024 DtoResolveClass(base); |
1025 | 1025 |
1026 // get type of typeinfo class | |
1027 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
1028 | |
1029 // create the symbol | 1026 // create the symbol |
1030 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | 1027 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, llvm::GlobalValue::WeakLinkage, NULL, toChars(), gIR->module); |
1031 } | 1028 } |
1032 | 1029 |
1033 void TypeInfoClassDeclaration::llvmDefine() | 1030 void TypeInfoClassDeclaration::llvmDefine() |
1034 { | 1031 { |
1035 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); | 1032 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); |
1037 | 1034 |
1038 // init typeinfo class | 1035 // init typeinfo class |
1039 ClassDeclaration* base = Type::typeinfoclass; | 1036 ClassDeclaration* base = Type::typeinfoclass; |
1040 assert(base); | 1037 assert(base); |
1041 DtoForceConstInitDsymbol(base); | 1038 DtoForceConstInitDsymbol(base); |
1042 | |
1043 // get type of typeinfo class | |
1044 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
1045 | 1039 |
1046 // initializer vector | 1040 // initializer vector |
1047 std::vector<LLConstant*> sinits; | 1041 std::vector<LLConstant*> sinits; |
1048 // first is always the vtable | 1042 // first is always the vtable |
1049 sinits.push_back(base->ir.irStruct->vtbl); | 1043 sinits.push_back(base->ir.irStruct->vtbl); |
1056 TypeClass *tc = (TypeClass *)tinfo; | 1050 TypeClass *tc = (TypeClass *)tinfo; |
1057 DtoForceDeclareDsymbol(tc->sym); | 1051 DtoForceDeclareDsymbol(tc->sym); |
1058 assert(tc->sym->ir.irStruct->classInfo); | 1052 assert(tc->sym->ir.irStruct->classInfo); |
1059 sinits.push_back(tc->sym->ir.irStruct->classInfo); | 1053 sinits.push_back(tc->sym->ir.irStruct->classInfo); |
1060 | 1054 |
1061 // create the symbol | 1055 // create the inititalizer |
1062 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 1056 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); |
1063 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); | 1057 |
1058 // refine global type | |
1059 llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
1060 | |
1061 // set the initializer | |
1062 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); | |
1064 } | 1063 } |
1065 | 1064 |
1066 void TypeInfoClassDeclaration::toDt(dt_t **pdt) | 1065 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |
1067 { | 1066 { |
1068 assert(0); | 1067 assert(0); |
1078 // init typeinfo class | 1077 // init typeinfo class |
1079 ClassDeclaration* base = Type::typeinfointerface; | 1078 ClassDeclaration* base = Type::typeinfointerface; |
1080 assert(base); | 1079 assert(base); |
1081 DtoResolveClass(base); | 1080 DtoResolveClass(base); |
1082 | 1081 |
1083 // get type of typeinfo class | |
1084 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
1085 | |
1086 // create the symbol | 1082 // create the symbol |
1087 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | 1083 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
1088 } | 1084 } |
1089 | 1085 |
1090 void TypeInfoInterfaceDeclaration::llvmDefine() | 1086 void TypeInfoInterfaceDeclaration::llvmDefine() |
1091 { | 1087 { |
1092 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars()); | 1088 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars()); |
1112 assert(tinfo->ty == Tclass); | 1108 assert(tinfo->ty == Tclass); |
1113 TypeClass *tc = (TypeClass *)tinfo; | 1109 TypeClass *tc = (TypeClass *)tinfo; |
1114 assert(tc->sym->ir.irStruct->classInfo); | 1110 assert(tc->sym->ir.irStruct->classInfo); |
1115 sinits.push_back(tc->sym->ir.irStruct->classInfo); | 1111 sinits.push_back(tc->sym->ir.irStruct->classInfo); |
1116 | 1112 |
1117 // create the symbol | 1113 // create the inititalizer |
1118 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 1114 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); |
1119 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); | 1115 |
1116 // refine global type | |
1117 llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
1118 | |
1119 // set the initializer | |
1120 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); | |
1120 } | 1121 } |
1121 | 1122 |
1122 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) | 1123 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) |
1123 { | 1124 { |
1124 assert(0); | 1125 assert(0); |
1134 // init typeinfo class | 1135 // init typeinfo class |
1135 ClassDeclaration* base = Type::typeinfotypelist; | 1136 ClassDeclaration* base = Type::typeinfotypelist; |
1136 assert(base); | 1137 assert(base); |
1137 DtoResolveClass(base); | 1138 DtoResolveClass(base); |
1138 | 1139 |
1139 // get type of typeinfo class | |
1140 const LLStructType* stype = isaStruct(base->type->ir.type->get()); | |
1141 | |
1142 // create the symbol | 1140 // create the symbol |
1143 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | 1141 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
1144 } | 1142 } |
1145 | 1143 |
1146 void TypeInfoTupleDeclaration::llvmDefine() | 1144 void TypeInfoTupleDeclaration::llvmDefine() |
1147 { | 1145 { |
1148 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars()); | 1146 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars()); |
1197 | 1195 |
1198 // build the slice | 1196 // build the slice |
1199 LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrptr); | 1197 LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrptr); |
1200 sinits.push_back(slice); | 1198 sinits.push_back(slice); |
1201 | 1199 |
1202 // create the symbol | 1200 // create the inititalizer |
1203 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 1201 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); |
1204 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); | 1202 |
1203 // refine global type | |
1204 llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
1205 | |
1206 // set the initializer | |
1207 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); | |
1205 } | 1208 } |
1206 | 1209 |
1207 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) | 1210 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
1208 { | 1211 { |
1209 assert(0); | 1212 assert(0); |