comparison gen/typinf.cpp @ 1148:3d1b16dabd25

Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Fri, 27 Mar 2009 21:50:32 +0100
parents dbe4af57b240
children 19d4ded7204a
comparison
equal deleted inserted replaced
1147:dbe4af57b240 1148:3d1b16dabd25
269 269
270 ////////////////////////////////////////////////////////////////////////////// 270 //////////////////////////////////////////////////////////////////////////////
271 // MAGIC PLACE 271 // MAGIC PLACE
272 ////////////////////////////////////////////////////////////////////////////// 272 //////////////////////////////////////////////////////////////////////////////
273 273
274 void DtoResolveTypeInfo(TypeInfoDeclaration* tid);
275 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid);
276 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid);
277
278 void TypeInfoDeclaration::codegen(Ir*)
279 {
280 DtoResolveTypeInfo(this);
281 }
282
274 void DtoResolveTypeInfo(TypeInfoDeclaration* tid) 283 void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
275 { 284 {
276 if (tid->ir.resolved) return; 285 if (tid->ir.resolved) return;
277 tid->ir.resolved = true; 286 tid->ir.resolved = true;
278 287
279 Logger::println("DtoResolveTypeInfo(%s)", tid->toChars()); 288 Logger::println("DtoResolveTypeInfo(%s)", tid->toChars());
280 LOG_SCOPE; 289 LOG_SCOPE;
281 290
282 tid->ir.irGlobal = new IrGlobal(tid); 291 IrGlobal* irg = new IrGlobal(tid);
283 292 irg->value = new llvm::GlobalVariable(irg->type.get(), true,
284 gIR->declareList.push_back(tid); 293 TYPEINFO_LINKAGE_TYPE, NULL, tid->mangle(), gIR->module);
285 } 294
286 295 tid->ir.irGlobal = irg;
287 void TypeInfoDeclaration::codegen(Ir*) 296
288 { 297 DtoDeclareTypeInfo(tid);
289 DtoResolveTypeInfo(this);
290 } 298 }
291 299
292 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid) 300 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
293 { 301 {
302 DtoResolveTypeInfo(tid);
303
294 if (tid->ir.declared) return; 304 if (tid->ir.declared) return;
295 tid->ir.declared = true; 305 tid->ir.declared = true;
296 306
297 Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars()); 307 Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars());
298 LOG_SCOPE; 308 LOG_SCOPE;
299 309
310 IrGlobal* irg = tid->ir.irGlobal;
311
300 std::string mangled(tid->mangle()); 312 std::string mangled(tid->mangle());
301 313
302 Logger::println("type = '%s'", tid->tinfo->toChars()); 314 Logger::println("type = '%s'", tid->tinfo->toChars());
303 Logger::println("typeinfo mangle: %s", mangled.c_str()); 315 Logger::println("typeinfo mangle: %s", mangled.c_str());
304 316
317 assert(irg->value != NULL);
318
305 // this is a declaration of a builtin __initZ var 319 // this is a declaration of a builtin __initZ var
306 if (tid->tinfo->builtinTypeInfo()) { 320 if (tid->tinfo->builtinTypeInfo()) {
307 LLValue* found = gIR->module->getNamedGlobal(mangled); 321 // fixup the global
308 if (!found) 322 const llvm::Type* rty = Type::typeinfo->type->ir.type->get();
309 { 323 llvm::cast<llvm::OpaqueType>(irg->type.get())->refineAbstractTypeTo(rty);
310 const LLType* t = LLOpaqueType::get(); 324 LLGlobalVariable* g = isaGlobalVar(irg->value);
311 llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module); 325 g->setLinkage(llvm::GlobalValue::ExternalLinkage);
312 assert(g); 326 return;
313 /*if (!tid->ir.irGlobal) 327 }
314 tid->ir.irGlobal = new IrGlobal(tid);*/ 328
315 tid->ir.irGlobal->value = g;
316 mangled.append("__TYPE");
317 gIR->module->addTypeName(mangled, tid->ir.irGlobal->value->getType()->getContainedType(0));
318 Logger::println("Got typeinfo var: %s", tid->ir.irGlobal->value->getName().c_str());
319 tid->ir.initialized = true;
320 tid->ir.defined = true;
321 }
322 else if (!tid->ir.irGlobal->value) {
323 tid->ir.irGlobal->value = found;
324 tid->ir.initialized = true;
325 tid->ir.defined = true;
326 }
327 }
328 // custom typedef 329 // custom typedef
329 else { 330 DtoConstInitTypeInfo(tid);
330 tid->llvmDeclare();
331 gIR->constInitList.push_back(tid);
332 }
333 } 331 }
334 332
335 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid) 333 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid)
336 { 334 {
337 if (tid->ir.initialized) return; 335 if (tid->ir.initialized) return;
338 tid->ir.initialized = true; 336 tid->ir.initialized = true;
339 337
340 Logger::println("DtoConstInitTypeInfo(%s)", tid->toChars()); 338 Logger::println("DtoConstInitTypeInfo(%s)", tid->toChars());
341 LOG_SCOPE; 339 LOG_SCOPE;
342 340
343 gIR->defineList.push_back(tid); 341 tid->llvmDefine();
344 } 342 }
345 343
346 void DtoDefineTypeInfo(TypeInfoDeclaration* tid) 344 void DtoDefineTypeInfo(TypeInfoDeclaration* tid)
347 { 345 {
348 if (tid->ir.defined) return; 346 if (tid->ir.defined) return;
354 tid->llvmDefine(); 352 tid->llvmDefine();
355 } 353 }
356 354
357 /* ========================================================================= */ 355 /* ========================================================================= */
358 356
359 void TypeInfoDeclaration::llvmDeclare() 357 void TypeInfoDeclaration::llvmDefine()
360 { 358 {
361 assert(0 && "TypeInfoDeclaration::llvmDeclare"); 359 assert(0 && "TypeInfoDeclaration::llvmDeclare");
362 } 360 }
363 361
364 void TypeInfoDeclaration::llvmDefine() 362 /* ========================================================================= */
365 { 363
366 assert(0 && "TypeInfoDeclaration::llvmDeclare"); 364 void TypeInfoTypedefDeclaration::llvmDefine()
367 } 365 {
368 366 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars());
369 /* ========================================================================= */
370
371 void TypeInfoTypedefDeclaration::llvmDeclare()
372 {
373 Logger::println("TypeInfoTypedefDeclaration::llvmDeclare() %s", toChars());
374 LOG_SCOPE; 367 LOG_SCOPE;
375 368
376 ClassDeclaration* base = Type::typeinfotypedef; 369 ClassDeclaration* base = Type::typeinfotypedef;
377 DtoResolveClass(base); 370 base->codegen(Type::sir);
378
379 const LLStructType* stype = isaStruct(base->type->ir.type->get());
380
381 // create the symbol
382 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
383 }
384
385 void TypeInfoTypedefDeclaration::llvmDefine()
386 {
387 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars());
388 LOG_SCOPE;
389
390 ClassDeclaration* base = Type::typeinfotypedef;
391 DtoForceConstInitDsymbol(base);
392 371
393 // vtbl 372 // vtbl
394 std::vector<LLConstant*> sinits; 373 std::vector<LLConstant*> sinits;
395 sinits.push_back(base->ir.irStruct->vtbl); 374 sinits.push_back(base->ir.irStruct->vtbl);
396 375
437 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); 416 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit);
438 } 417 }
439 418
440 /* ========================================================================= */ 419 /* ========================================================================= */
441 420
442 void TypeInfoEnumDeclaration::llvmDeclare() 421 void TypeInfoEnumDeclaration::llvmDefine()
443 { 422 {
444 Logger::println("TypeInfoEnumDeclaration::llvmDeclare() %s", toChars()); 423 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars());
445 LOG_SCOPE; 424 LOG_SCOPE;
446 425
447 ClassDeclaration* base = Type::typeinfoenum; 426 ClassDeclaration* base = Type::typeinfoenum;
448 DtoResolveClass(base); 427 base->codegen(Type::sir);
449
450 // create the symbol
451 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
452 }
453
454 void TypeInfoEnumDeclaration::llvmDefine()
455 {
456 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars());
457 LOG_SCOPE;
458
459 ClassDeclaration* base = Type::typeinfoenum;
460 DtoForceConstInitDsymbol(base);
461 428
462 // vtbl 429 // vtbl
463 std::vector<LLConstant*> sinits; 430 std::vector<LLConstant*> sinits;
464 sinits.push_back(base->ir.irStruct->vtbl); 431 sinits.push_back(base->ir.irStruct->vtbl);
465 432
510 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); 477 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit);
511 } 478 }
512 479
513 /* ========================================================================= */ 480 /* ========================================================================= */
514 481
515 static void LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) 482 static void LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd)
516 { 483 {
517 ClassDeclaration* base = cd; 484 ClassDeclaration* base = cd;
518 DtoResolveClass(base); 485 base->codegen(Type::sir);
519
520 // create the symbol
521 tid->ir.irGlobal->value = new llvm::GlobalVariable(tid->ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, tid->toChars(), gIR->module);
522 }
523
524 static void LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd)
525 {
526 ClassDeclaration* base = cd;
527 DtoForceConstInitDsymbol(base);
528 486
529 // vtbl 487 // vtbl
530 std::vector<LLConstant*> sinits; 488 std::vector<LLConstant*> sinits;
531 sinits.push_back(base->ir.irStruct->vtbl); 489 sinits.push_back(base->ir.irStruct->vtbl);
532 490
547 isaGlobalVar(tid->ir.irGlobal->value)->setInitializer(tiInit); 505 isaGlobalVar(tid->ir.irGlobal->value)->setInitializer(tiInit);
548 } 506 }
549 507
550 /* ========================================================================= */ 508 /* ========================================================================= */
551 509
552 void TypeInfoPointerDeclaration::llvmDeclare() 510 void TypeInfoPointerDeclaration::llvmDefine()
553 { 511 {
554 Logger::println("TypeInfoPointerDeclaration::llvmDeclare() %s", toChars()); 512 Logger::println("TypeInfoPointerDeclaration::llvmDefine() %s", toChars());
555 LOG_SCOPE; 513 LOG_SCOPE;
556 514
557 assert(tinfo->ty == Tpointer); 515 assert(tinfo->ty == Tpointer);
558 TypePointer *tc = (TypePointer *)tinfo; 516 TypePointer *tc = (TypePointer *)tinfo;
559 517
560 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfopointer);
561 }
562
563 void TypeInfoPointerDeclaration::llvmDefine()
564 {
565 Logger::println("TypeInfoPointerDeclaration::llvmDefine() %s", toChars());
566 LOG_SCOPE;
567
568 assert(tinfo->ty == Tpointer);
569 TypePointer *tc = (TypePointer *)tinfo;
570
571 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfopointer); 518 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfopointer);
572 } 519 }
573 520
574 /* ========================================================================= */ 521 /* ========================================================================= */
575 522
576 void TypeInfoArrayDeclaration::llvmDeclare() 523 void TypeInfoArrayDeclaration::llvmDefine()
577 { 524 {
578 Logger::println("TypeInfoArrayDeclaration::llvmDeclare() %s", toChars()); 525 Logger::println("TypeInfoArrayDeclaration::llvmDefine() %s", toChars());
579 LOG_SCOPE; 526 LOG_SCOPE;
580 527
581 assert(tinfo->ty == Tarray); 528 assert(tinfo->ty == Tarray);
582 TypeDArray *tc = (TypeDArray *)tinfo; 529 TypeDArray *tc = (TypeDArray *)tinfo;
583 530
584 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoarray);
585 }
586
587 void TypeInfoArrayDeclaration::llvmDefine()
588 {
589 Logger::println("TypeInfoArrayDeclaration::llvmDefine() %s", toChars());
590 LOG_SCOPE;
591
592 assert(tinfo->ty == Tarray);
593 TypeDArray *tc = (TypeDArray *)tinfo;
594
595 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfoarray); 531 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfoarray);
596 } 532 }
597 533
598 /* ========================================================================= */ 534 /* ========================================================================= */
599 535
600 void TypeInfoStaticArrayDeclaration::llvmDeclare() 536 void TypeInfoStaticArrayDeclaration::llvmDefine()
601 { 537 {
602 Logger::println("TypeInfoStaticArrayDeclaration::llvmDeclare() %s", toChars()); 538 Logger::println("TypeInfoStaticArrayDeclaration::llvmDefine() %s", toChars());
603 LOG_SCOPE; 539 LOG_SCOPE;
604 540
605 // init typeinfo class 541 // init typeinfo class
606 ClassDeclaration* base = Type::typeinfostaticarray; 542 ClassDeclaration* base = Type::typeinfostaticarray;
607 DtoResolveClass(base); 543 base->codegen(Type::sir);
608
609 // create the symbol
610 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
611 }
612
613 void TypeInfoStaticArrayDeclaration::llvmDefine()
614 {
615 Logger::println("TypeInfoStaticArrayDeclaration::llvmDefine() %s", toChars());
616 LOG_SCOPE;
617
618 // init typeinfo class
619 ClassDeclaration* base = Type::typeinfostaticarray;
620 DtoForceConstInitDsymbol(base);
621 544
622 // get type of typeinfo class 545 // get type of typeinfo class
623 const LLStructType* stype = isaStruct(base->type->ir.type->get()); 546 const LLStructType* stype = isaStruct(base->type->ir.type->get());
624 547
625 // initializer vector 548 // initializer vector
650 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); 573 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit);
651 } 574 }
652 575
653 /* ========================================================================= */ 576 /* ========================================================================= */
654 577
655 void TypeInfoAssociativeArrayDeclaration::llvmDeclare() 578 void TypeInfoAssociativeArrayDeclaration::llvmDefine()
656 { 579 {
657 Logger::println("TypeInfoAssociativeArrayDeclaration::llvmDeclare() %s", toChars()); 580 Logger::println("TypeInfoAssociativeArrayDeclaration::llvmDefine() %s", toChars());
658 LOG_SCOPE; 581 LOG_SCOPE;
659 582
660 // init typeinfo class 583 // init typeinfo class
661 ClassDeclaration* base = Type::typeinfoassociativearray; 584 ClassDeclaration* base = Type::typeinfoassociativearray;
662 DtoResolveClass(base); 585 base->codegen(Type::sir);
663
664 // create the symbol
665 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
666 }
667
668 void TypeInfoAssociativeArrayDeclaration::llvmDefine()
669 {
670 Logger::println("TypeInfoAssociativeArrayDeclaration::llvmDefine() %s", toChars());
671 LOG_SCOPE;
672
673 // init typeinfo class
674 ClassDeclaration* base = Type::typeinfoassociativearray;
675 DtoForceConstInitDsymbol(base);
676 586
677 // initializer vector 587 // initializer vector
678 std::vector<LLConstant*> sinits; 588 std::vector<LLConstant*> sinits;
679 // first is always the vtable 589 // first is always the vtable
680 sinits.push_back(base->ir.irStruct->vtbl); 590 sinits.push_back(base->ir.irStruct->vtbl);
704 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); 614 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit);
705 } 615 }
706 616
707 /* ========================================================================= */ 617 /* ========================================================================= */
708 618
709 void TypeInfoFunctionDeclaration::llvmDeclare() 619 void TypeInfoFunctionDeclaration::llvmDefine()
710 { 620 {
711 Logger::println("TypeInfoFunctionDeclaration::llvmDeclare() %s", toChars()); 621 Logger::println("TypeInfoFunctionDeclaration::llvmDefine() %s", toChars());
712 LOG_SCOPE; 622 LOG_SCOPE;
713 623
714 assert(tinfo->ty == Tfunction); 624 assert(tinfo->ty == Tfunction);
715 TypeFunction *tc = (TypeFunction *)tinfo; 625 TypeFunction *tc = (TypeFunction *)tinfo;
716 626
717 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfofunction);
718 }
719
720 void TypeInfoFunctionDeclaration::llvmDefine()
721 {
722 Logger::println("TypeInfoFunctionDeclaration::llvmDefine() %s", toChars());
723 LOG_SCOPE;
724
725 assert(tinfo->ty == Tfunction);
726 TypeFunction *tc = (TypeFunction *)tinfo;
727
728 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfofunction); 627 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfofunction);
729 } 628 }
730 629
731 /* ========================================================================= */ 630 /* ========================================================================= */
732 631
733 void TypeInfoDelegateDeclaration::llvmDeclare() 632 void TypeInfoDelegateDeclaration::llvmDefine()
734 { 633 {
735 Logger::println("TypeInfoDelegateDeclaration::llvmDeclare() %s", toChars()); 634 Logger::println("TypeInfoDelegateDeclaration::llvmDefine() %s", toChars());
736 LOG_SCOPE; 635 LOG_SCOPE;
737 636
738 assert(tinfo->ty == Tdelegate); 637 assert(tinfo->ty == Tdelegate);
739 TypeDelegate *tc = (TypeDelegate *)tinfo; 638 TypeDelegate *tc = (TypeDelegate *)tinfo;
740 639
741 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfodelegate);
742 }
743
744 void TypeInfoDelegateDeclaration::llvmDefine()
745 {
746 Logger::println("TypeInfoDelegateDeclaration::llvmDefine() %s", toChars());
747 LOG_SCOPE;
748
749 assert(tinfo->ty == Tdelegate);
750 TypeDelegate *tc = (TypeDelegate *)tinfo;
751
752 LLVM_D_Define_TypeInfoBase(tc->nextOf()->nextOf(), this, Type::typeinfodelegate); 640 LLVM_D_Define_TypeInfoBase(tc->nextOf()->nextOf(), this, Type::typeinfodelegate);
753 } 641 }
754 642
755 /* ========================================================================= */ 643 /* ========================================================================= */
756 644
757 void TypeInfoStructDeclaration::llvmDeclare() 645 void TypeInfoStructDeclaration::llvmDefine()
758 { 646 {
759 Logger::println("TypeInfoStructDeclaration::llvmDeclare() %s", toChars()); 647 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars());
760 LOG_SCOPE; 648 LOG_SCOPE;
761 649
762 assert(tinfo->ty == Tstruct); 650 assert(tinfo->ty == Tstruct);
763 TypeStruct *tc = (TypeStruct *)tinfo; 651 TypeStruct *tc = (TypeStruct *)tinfo;
764 StructDeclaration *sd = tc->sym; 652 StructDeclaration *sd = tc->sym;
765 DtoResolveDsymbol(sd); 653 sd->codegen(Type::sir);
766 654
767 ClassDeclaration* base = Type::typeinfostruct; 655 ClassDeclaration* base = Type::typeinfostruct;
768 DtoResolveClass(base); 656 base->codegen(Type::sir);
769
770 // create the symbol
771 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
772 }
773
774 void TypeInfoStructDeclaration::llvmDefine()
775 {
776 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars());
777 LOG_SCOPE;
778
779 assert(tinfo->ty == Tstruct);
780 TypeStruct *tc = (TypeStruct *)tinfo;
781 StructDeclaration *sd = tc->sym;
782 DtoForceConstInitDsymbol(sd);
783
784 ClassDeclaration* base = Type::typeinfostruct;
785 DtoForceConstInitDsymbol(base);
786 657
787 const LLStructType* stype = isaStruct(base->type->ir.type->get()); 658 const LLStructType* stype = isaStruct(base->type->ir.type->get());
788 659
789 // vtbl 660 // vtbl
790 std::vector<LLConstant*> sinits; 661 std::vector<LLConstant*> sinits;
868 fdx = s ? s->isFuncDeclaration() : NULL; 739 fdx = s ? s->isFuncDeclaration() : NULL;
869 if (fdx) 740 if (fdx)
870 { 741 {
871 fd = fdx->overloadExactMatch(tftohash); 742 fd = fdx->overloadExactMatch(tftohash);
872 if (fd) { 743 if (fd) {
873 DtoForceDeclareDsymbol(fd); 744 fd->codegen(Type::sir);
874 assert(fd->ir.irFunc->func != 0); 745 assert(fd->ir.irFunc->func != 0);
875 LLConstant* c = isaConstant(fd->ir.irFunc->func); 746 LLConstant* c = isaConstant(fd->ir.irFunc->func);
876 assert(c); 747 assert(c);
877 c = llvm::ConstantExpr::getBitCast(c, ptty); 748 c = llvm::ConstantExpr::getBitCast(c, ptty);
878 sinits.push_back(c); 749 sinits.push_back(c);
894 ptty = isaPointer(stype->getElementType(5+i)); 765 ptty = isaPointer(stype->getElementType(5+i));
895 if (fdx) 766 if (fdx)
896 { 767 {
897 fd = fdx->overloadExactMatch(tfeqptr); 768 fd = fdx->overloadExactMatch(tfeqptr);
898 if (fd) { 769 if (fd) {
899 DtoForceDeclareDsymbol(fd); 770 fd->codegen(Type::sir);
900 assert(fd->ir.irFunc->func != 0); 771 assert(fd->ir.irFunc->func != 0);
901 LLConstant* c = isaConstant(fd->ir.irFunc->func); 772 LLConstant* c = isaConstant(fd->ir.irFunc->func);
902 assert(c); 773 assert(c);
903 c = llvm::ConstantExpr::getBitCast(c, ptty); 774 c = llvm::ConstantExpr::getBitCast(c, ptty);
904 sinits.push_back(c); 775 sinits.push_back(c);
922 fdx = s ? s->isFuncDeclaration() : NULL; 793 fdx = s ? s->isFuncDeclaration() : NULL;
923 if (fdx) 794 if (fdx)
924 { 795 {
925 fd = fdx->overloadExactMatch(tftostring); 796 fd = fdx->overloadExactMatch(tftostring);
926 if (fd) { 797 if (fd) {
927 DtoForceDeclareDsymbol(fd); 798 fd->codegen(Type::sir);
928 assert(fd->ir.irFunc->func != 0); 799 assert(fd->ir.irFunc->func != 0);
929 LLConstant* c = isaConstant(fd->ir.irFunc->func); 800 LLConstant* c = isaConstant(fd->ir.irFunc->func);
930 assert(c); 801 assert(c);
931 c = llvm::ConstantExpr::getBitCast(c, ptty); 802 c = llvm::ConstantExpr::getBitCast(c, ptty);
932 sinits.push_back(c); 803 sinits.push_back(c);
966 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); 837 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit);
967 } 838 }
968 839
969 /* ========================================================================= */ 840 /* ========================================================================= */
970 841
971 void TypeInfoClassDeclaration::llvmDeclare() 842 void TypeInfoClassDeclaration::llvmDefine()
972 { 843 {
973 Logger::println("TypeInfoClassDeclaration::llvmDeclare() %s", toChars()); 844 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars());
974 LOG_SCOPE; 845 LOG_SCOPE;
975 846
976 // init typeinfo class 847 // init typeinfo class
977 ClassDeclaration* base = Type::typeinfoclass; 848 ClassDeclaration* base = Type::typeinfoclass;
978 assert(base); 849 assert(base);
979 DtoResolveClass(base); 850 base->codegen(Type::sir);
980
981 // create the symbol
982 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
983 }
984
985 void TypeInfoClassDeclaration::llvmDefine()
986 {
987 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars());
988 LOG_SCOPE;
989
990 // init typeinfo class
991 ClassDeclaration* base = Type::typeinfoclass;
992 assert(base);
993 DtoForceConstInitDsymbol(base);
994 851
995 // initializer vector 852 // initializer vector
996 std::vector<LLConstant*> sinits; 853 std::vector<LLConstant*> sinits;
997 // first is always the vtable 854 // first is always the vtable
998 sinits.push_back(base->ir.irStruct->vtbl); 855 sinits.push_back(base->ir.irStruct->vtbl);
1001 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); 858 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty)));
1002 859
1003 // get classinfo 860 // get classinfo
1004 assert(tinfo->ty == Tclass); 861 assert(tinfo->ty == Tclass);
1005 TypeClass *tc = (TypeClass *)tinfo; 862 TypeClass *tc = (TypeClass *)tinfo;
1006 DtoForceDeclareDsymbol(tc->sym); 863 tc->sym->codegen(Type::sir);;
1007 assert(tc->sym->ir.irStruct->classInfo); 864 assert(tc->sym->ir.irStruct->classInfo);
1008 sinits.push_back(tc->sym->ir.irStruct->classInfo); 865 sinits.push_back(tc->sym->ir.irStruct->classInfo);
1009 866
1010 // create the inititalizer 867 // create the inititalizer
1011 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); 868 LLConstant* tiInit = llvm::ConstantStruct::get(sinits);
1017 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); 874 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit);
1018 } 875 }
1019 876
1020 /* ========================================================================= */ 877 /* ========================================================================= */
1021 878
1022 void TypeInfoInterfaceDeclaration::llvmDeclare() 879 void TypeInfoInterfaceDeclaration::llvmDefine()
1023 { 880 {
1024 Logger::println("TypeInfoInterfaceDeclaration::llvmDeclare() %s", toChars()); 881 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars());
1025 LOG_SCOPE; 882 LOG_SCOPE;
1026 883
1027 // init typeinfo class 884 // init typeinfo class
1028 ClassDeclaration* base = Type::typeinfointerface; 885 ClassDeclaration* base = Type::typeinfointerface;
1029 assert(base); 886 assert(base);
1030 DtoResolveClass(base); 887 base->codegen(Type::sir);
1031
1032 // create the symbol
1033 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
1034 }
1035
1036 void TypeInfoInterfaceDeclaration::llvmDefine()
1037 {
1038 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars());
1039 LOG_SCOPE;
1040
1041 // init typeinfo class
1042 ClassDeclaration* base = Type::typeinfointerface;
1043 assert(base);
1044 DtoForceConstInitDsymbol(base);
1045 888
1046 // get type of typeinfo class 889 // get type of typeinfo class
1047 const LLStructType* stype = isaStruct(base->type->ir.type->get()); 890 const LLStructType* stype = isaStruct(base->type->ir.type->get());
1048 891
1049 // initializer vector 892 // initializer vector
1070 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); 913 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit);
1071 } 914 }
1072 915
1073 /* ========================================================================= */ 916 /* ========================================================================= */
1074 917
1075 void TypeInfoTupleDeclaration::llvmDeclare() 918 void TypeInfoTupleDeclaration::llvmDefine()
1076 { 919 {
1077 Logger::println("TypeInfoTupleDeclaration::llvmDeclare() %s", toChars()); 920 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars());
1078 LOG_SCOPE; 921 LOG_SCOPE;
1079 922
1080 // init typeinfo class 923 // init typeinfo class
1081 ClassDeclaration* base = Type::typeinfotypelist; 924 ClassDeclaration* base = Type::typeinfotypelist;
1082 assert(base); 925 assert(base);
1083 DtoResolveClass(base); 926 base->codegen(Type::sir);
1084
1085 // create the symbol
1086 ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module);
1087 }
1088
1089 void TypeInfoTupleDeclaration::llvmDefine()
1090 {
1091 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars());
1092 LOG_SCOPE;
1093
1094 // init typeinfo class
1095 ClassDeclaration* base = Type::typeinfotypelist;
1096 assert(base);
1097 DtoForceConstInitDsymbol(base);
1098 927
1099 // get type of typeinfo class 928 // get type of typeinfo class
1100 const LLStructType* stype = isaStruct(base->type->ir.type->get()); 929 const LLStructType* stype = isaStruct(base->type->ir.type->get());
1101 930
1102 // initializer vector 931 // initializer vector
1154 983
1155 /* ========================================================================= */ 984 /* ========================================================================= */
1156 985
1157 #if DMDV2 986 #if DMDV2
1158 987
1159 void TypeInfoConstDeclaration::llvmDeclare()
1160 {
1161 Logger::println("TypeInfoConstDeclaration::llvmDeclare() %s", toChars());
1162 LOG_SCOPE;
1163
1164 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoconst);
1165 }
1166
1167 void TypeInfoConstDeclaration::llvmDefine() 988 void TypeInfoConstDeclaration::llvmDefine()
1168 { 989 {
1169 Logger::println("TypeInfoConstDeclaration::llvmDefine() %s", toChars()); 990 Logger::println("TypeInfoConstDeclaration::llvmDefine() %s", toChars());
1170 LOG_SCOPE; 991 LOG_SCOPE;
1171 992
1175 LLVM_D_Define_TypeInfoBase(tm, this, Type::typeinfoconst); 996 LLVM_D_Define_TypeInfoBase(tm, this, Type::typeinfoconst);
1176 } 997 }
1177 998
1178 /* ========================================================================= */ 999 /* ========================================================================= */
1179 1000
1180 void TypeInfoInvariantDeclaration::llvmDeclare()
1181 {
1182 Logger::println("TypeInfoInvariantDeclaration::llvmDeclare() %s", toChars());
1183 LOG_SCOPE;
1184
1185 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoinvariant);
1186 }
1187
1188 void TypeInfoInvariantDeclaration::llvmDefine() 1001 void TypeInfoInvariantDeclaration::llvmDefine()
1189 { 1002 {
1190 Logger::println("TypeInfoInvariantDeclaration::llvmDefine() %s", toChars()); 1003 Logger::println("TypeInfoInvariantDeclaration::llvmDefine() %s", toChars());
1191 LOG_SCOPE; 1004 LOG_SCOPE;
1192 1005