comparison gen/typinf.cpp @ 213:7816aafeea3c trunk

[svn r229] Updated the object.d implementation to the latest Tango. Fixed a bunch of the built-in typeinfos for arrays, they did not inherit TypeInfo_Array. Applied patch to tango/text/convert/Layout.d by fvbommel, closes #47 . Cleaned up some type code. Replaced uses of llvm::Type with LLType (a typedef), same for Value and Constant. Fixed a few cases where typeinfo for user structs could be emitted multiple times, seems to still be some cases of this :/
author lindquist
date Fri, 30 May 2008 19:32:04 +0200
parents db9890b3fb64
children a95056b3c996
comparison
equal deleted inserted replaced
212:4c2689d57ba4 213:7816aafeea3c
231 * Used to supply hidden _arguments[] value for variadic D functions. 231 * Used to supply hidden _arguments[] value for variadic D functions.
232 */ 232 */
233 233
234 Expression *createTypeInfoArray(Scope *sc, Expression *exps[], int dim) 234 Expression *createTypeInfoArray(Scope *sc, Expression *exps[], int dim)
235 { 235 {
236 assert(0); 236 assert(0); // done elsewhere in llvmdc
237 return NULL; 237 return NULL;
238 } 238 }
239 239
240 /* ========================================================================= */ 240 /* ========================================================================= */
241 241
274 Logger::println("type = '%s'", tid->tinfo->toChars()); 274 Logger::println("type = '%s'", tid->tinfo->toChars());
275 Logger::println("typeinfo mangle: %s", mangled.c_str()); 275 Logger::println("typeinfo mangle: %s", mangled.c_str());
276 276
277 // this is a declaration of a builtin __initZ var 277 // this is a declaration of a builtin __initZ var
278 if (tid->tinfo->builtinTypeInfo()) { 278 if (tid->tinfo->builtinTypeInfo()) {
279 llvm::Value* found = gIR->module->getNamedGlobal(mangled); 279 LLValue* found = gIR->module->getNamedGlobal(mangled);
280 if (!found) 280 if (!found)
281 { 281 {
282 const llvm::Type* t = llvm::OpaqueType::get(); 282 const LLType* t = llvm::OpaqueType::get();
283 llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module); 283 llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module);
284 assert(g); 284 assert(g);
285 /*if (!tid->ir.irGlobal) 285 /*if (!tid->ir.irGlobal)
286 tid->ir.irGlobal = new IrGlobal(tid);*/ 286 tid->ir.irGlobal = new IrGlobal(tid);*/
287 tid->ir.irGlobal->value = g; 287 tid->ir.irGlobal->value = g;
369 369
370 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 370 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
371 Logger::cout() << "got stype: " << *stype << '\n'; 371 Logger::cout() << "got stype: " << *stype << '\n';
372 372
373 // vtbl 373 // vtbl
374 std::vector<llvm::Constant*> sinits; 374 std::vector<LLConstant*> sinits;
375 sinits.push_back(base->ir.irStruct->vtbl); 375 sinits.push_back(base->ir.irStruct->vtbl);
376 376
377 // monitor 377 // monitor
378 sinits.push_back(getNullPtr(getPtrToType(llvm::Type::Int8Ty))); 378 sinits.push_back(getNullPtr(getPtrToType(llvm::Type::Int8Ty)));
379 379
391 assert(sd->basetype->vtinfo); 391 assert(sd->basetype->vtinfo);
392 DtoForceDeclareDsymbol(sd->basetype->vtinfo); 392 DtoForceDeclareDsymbol(sd->basetype->vtinfo);
393 393
394 assert(sd->basetype->vtinfo->ir.irGlobal->value); 394 assert(sd->basetype->vtinfo->ir.irGlobal->value);
395 assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->ir.irGlobal->value)); 395 assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->ir.irGlobal->value));
396 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->ir.irGlobal->value); 396 LLConstant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->ir.irGlobal->value);
397 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); 397 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
398 sinits.push_back(castbase); 398 sinits.push_back(castbase);
399 399
400 // char[] name 400 // char[] name
401 char *name = sd->toPrettyChars(); 401 char *name = sd->toPrettyChars();
408 { 408 {
409 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), getNullPtr(initpt))); 409 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), getNullPtr(initpt)));
410 } 410 }
411 else 411 else
412 { 412 {
413 llvm::Constant* ci = DtoConstInitializer(sd->basetype, sd->init); 413 LLConstant* ci = DtoConstInitializer(sd->basetype, sd->init);
414 std::string ciname(sd->mangle()); 414 std::string ciname(sd->mangle());
415 ciname.append("__init"); 415 ciname.append("__init");
416 llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); 416 llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
417 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); 417 LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt);
418 size_t cisize = getTypeStoreSize(DtoType(sd->basetype)); 418 size_t cisize = getTypeStoreSize(DtoType(sd->basetype));
419 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); 419 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
420 } 420 }
421 421
422 // create the symbol 422 // create the symbol
423 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 423 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
424 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 424 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
425 } 425 }
426 426
427 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) 427 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt)
428 { 428 {
454 DtoForceConstInitDsymbol(base); 454 DtoForceConstInitDsymbol(base);
455 455
456 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 456 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
457 457
458 // vtbl 458 // vtbl
459 std::vector<llvm::Constant*> sinits; 459 std::vector<LLConstant*> sinits;
460 sinits.push_back(base->ir.irStruct->vtbl); 460 sinits.push_back(base->ir.irStruct->vtbl);
461 461
462 // monitor 462 // monitor
463 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 463 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
464 464
475 sd->memtype->getTypeInfo(NULL); // generate vtinfo 475 sd->memtype->getTypeInfo(NULL); // generate vtinfo
476 assert(sd->memtype->vtinfo); 476 assert(sd->memtype->vtinfo);
477 DtoForceDeclareDsymbol(sd->memtype->vtinfo); 477 DtoForceDeclareDsymbol(sd->memtype->vtinfo);
478 478
479 assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->ir.irGlobal->value)); 479 assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->ir.irGlobal->value));
480 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->ir.irGlobal->value); 480 LLConstant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->ir.irGlobal->value);
481 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); 481 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
482 sinits.push_back(castbase); 482 sinits.push_back(castbase);
483 483
484 // char[] name 484 // char[] name
485 char *name = sd->toPrettyChars(); 485 char *name = sd->toPrettyChars();
492 { 492 {
493 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); 493 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
494 } 494 }
495 else 495 else
496 { 496 {
497 const llvm::Type* memty = DtoType(sd->memtype); 497 const LLType* memty = DtoType(sd->memtype);
498 llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); 498 LLConstant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned());
499 std::string ciname(sd->mangle()); 499 std::string ciname(sd->mangle());
500 ciname.append("__init"); 500 ciname.append("__init");
501 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); 501 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
502 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); 502 LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt);
503 size_t cisize = getTypeStoreSize(memty); 503 size_t cisize = getTypeStoreSize(memty);
504 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); 504 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
505 } 505 }
506 506
507 // create the symbol 507 // create the symbol
508 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 508 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
509 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 509 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
510 } 510 }
511 511
512 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) 512 void TypeInfoEnumDeclaration::toDt(dt_t **pdt)
513 { 513 {
514 assert(0); 514 assert(0);
515 } 515 }
516 516
517 /* ========================================================================= */ 517 /* ========================================================================= */
518 518
519 static llvm::Constant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) 519 static LLConstant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd)
520 { 520 {
521 ClassDeclaration* base = cd; 521 ClassDeclaration* base = cd;
522 DtoResolveClass(base); 522 DtoResolveClass(base);
523 523
524 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 524 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
525 525
526 // create the symbol 526 // create the symbol
527 tid->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); 527 tid->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module);
528 } 528 }
529 529
530 static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) 530 static LLConstant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd)
531 { 531 {
532 ClassDeclaration* base = cd; 532 ClassDeclaration* base = cd;
533 DtoForceConstInitDsymbol(base); 533 DtoForceConstInitDsymbol(base);
534 534
535 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 535 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
536 536
537 // vtbl 537 // vtbl
538 std::vector<llvm::Constant*> sinits; 538 std::vector<LLConstant*> sinits;
539 sinits.push_back(base->ir.irStruct->vtbl); 539 sinits.push_back(base->ir.irStruct->vtbl);
540 540
541 // monitor 541 // monitor
542 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 542 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
543 543
545 Logger::println("generating base typeinfo"); 545 Logger::println("generating base typeinfo");
546 basetype->getTypeInfo(NULL); 546 basetype->getTypeInfo(NULL);
547 assert(basetype->vtinfo); 547 assert(basetype->vtinfo);
548 DtoForceDeclareDsymbol(basetype->vtinfo); 548 DtoForceDeclareDsymbol(basetype->vtinfo);
549 assert(llvm::isa<llvm::Constant>(basetype->vtinfo->ir.irGlobal->value)); 549 assert(llvm::isa<llvm::Constant>(basetype->vtinfo->ir.irGlobal->value));
550 llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->ir.irGlobal->value); 550 LLConstant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->ir.irGlobal->value);
551 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); 551 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
552 sinits.push_back(castbase); 552 sinits.push_back(castbase);
553 553
554 // create the symbol 554 // create the symbol
555 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 555 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
556 isaGlobalVar(tid->ir.irGlobal->value)->setInitializer(tiInit); 556 isaGlobalVar(tid->ir.irGlobal->value)->setInitializer(tiInit);
557 } 557 }
558 558
559 /* ========================================================================= */ 559 /* ========================================================================= */
560 560
643 643
644 // get type of typeinfo class 644 // get type of typeinfo class
645 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 645 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
646 646
647 // initializer vector 647 // initializer vector
648 std::vector<llvm::Constant*> sinits; 648 std::vector<LLConstant*> sinits;
649 // first is always the vtable 649 // first is always the vtable
650 sinits.push_back(base->ir.irStruct->vtbl); 650 sinits.push_back(base->ir.irStruct->vtbl);
651 651
652 // monitor 652 // monitor
653 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 653 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
658 tc->next->getTypeInfo(NULL); 658 tc->next->getTypeInfo(NULL);
659 659
660 // get symbol 660 // get symbol
661 assert(tc->next->vtinfo); 661 assert(tc->next->vtinfo);
662 DtoForceDeclareDsymbol(tc->next->vtinfo); 662 DtoForceDeclareDsymbol(tc->next->vtinfo);
663 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value); 663 LLConstant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value);
664 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); 664 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
665 sinits.push_back(castbase); 665 sinits.push_back(castbase);
666 666
667 // length 667 // length
668 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); 668 sinits.push_back(DtoConstSize_t(tc->dim->toInteger()));
669 669
670 // create the symbol 670 // create the symbol
671 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 671 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
672 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 672 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
673 } 673 }
674 674
675 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) 675 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt)
676 { 676 {
706 706
707 // get type of typeinfo class 707 // get type of typeinfo class
708 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 708 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
709 709
710 // initializer vector 710 // initializer vector
711 std::vector<llvm::Constant*> sinits; 711 std::vector<LLConstant*> sinits;
712 // first is always the vtable 712 // first is always the vtable
713 sinits.push_back(base->ir.irStruct->vtbl); 713 sinits.push_back(base->ir.irStruct->vtbl);
714 714
715 // monitor 715 // monitor
716 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 716 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
723 tc->next->getTypeInfo(NULL); 723 tc->next->getTypeInfo(NULL);
724 724
725 // get symbol 725 // get symbol
726 assert(tc->next->vtinfo); 726 assert(tc->next->vtinfo);
727 DtoForceDeclareDsymbol(tc->next->vtinfo); 727 DtoForceDeclareDsymbol(tc->next->vtinfo);
728 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value); 728 LLConstant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value);
729 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); 729 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
730 sinits.push_back(castbase); 730 sinits.push_back(castbase);
731 731
732 // key typeinfo 732 // key typeinfo
733 tc->index->getTypeInfo(NULL); 733 tc->index->getTypeInfo(NULL);
738 castbase = isaConstant(tc->index->vtinfo->ir.irGlobal->value); 738 castbase = isaConstant(tc->index->vtinfo->ir.irGlobal->value);
739 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(3)); 739 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(3));
740 sinits.push_back(castbase); 740 sinits.push_back(castbase);
741 741
742 // create the symbol 742 // create the symbol
743 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 743 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
744 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 744 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
745 } 745 }
746 746
747 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) 747 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt)
748 { 748 {
842 DtoForceConstInitDsymbol(base); 842 DtoForceConstInitDsymbol(base);
843 843
844 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 844 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
845 845
846 // vtbl 846 // vtbl
847 std::vector<llvm::Constant*> sinits; 847 std::vector<LLConstant*> sinits;
848 sinits.push_back(base->ir.irStruct->vtbl); 848 sinits.push_back(base->ir.irStruct->vtbl);
849 849
850 // monitor 850 // monitor
851 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 851 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
852 852
856 //Logger::println("************** A"); 856 //Logger::println("************** A");
857 assert(sinits.back()->getType() == stype->getElementType(2)); 857 assert(sinits.back()->getType() == stype->getElementType(2));
858 858
859 // void[] init 859 // void[] init
860 const llvm::PointerType* initpt = getPtrToType(llvm::Type::Int8Ty); 860 const llvm::PointerType* initpt = getPtrToType(llvm::Type::Int8Ty);
861 #if 0
862 // the implementation of TypeInfo_Struct uses this to determine size. :/
861 if (sd->zeroInit) // 0 initializer, or the same as the base type 863 if (sd->zeroInit) // 0 initializer, or the same as the base type
862 { 864 {
863 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); 865 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
864 } 866 }
865 else 867 else
868 #endif
866 { 869 {
867 size_t cisize = getTypeStoreSize(tc->ir.type->get()); 870 size_t cisize = getTypeStoreSize(tc->ir.type->get());
868 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(sd->ir.irStruct->init, initpt); 871 LLConstant* cicast = llvm::ConstantExpr::getBitCast(sd->ir.irStruct->init, initpt);
869 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); 872 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
870 } 873 }
871 874
872 // toX functions ground work 875 // toX functions ground work
873 FuncDeclaration *fd; 876 FuncDeclaration *fd;
924 { 927 {
925 fd = fdx->overloadExactMatch(tftohash); 928 fd = fdx->overloadExactMatch(tftohash);
926 if (fd) { 929 if (fd) {
927 DtoForceDeclareDsymbol(fd); 930 DtoForceDeclareDsymbol(fd);
928 assert(fd->ir.irFunc->func != 0); 931 assert(fd->ir.irFunc->func != 0);
929 llvm::Constant* c = isaConstant(fd->ir.irFunc->func); 932 LLConstant* c = isaConstant(fd->ir.irFunc->func);
930 assert(c); 933 assert(c);
931 c = llvm::ConstantExpr::getBitCast(c, ptty); 934 c = llvm::ConstantExpr::getBitCast(c, ptty);
932 sinits.push_back(c); 935 sinits.push_back(c);
933 } 936 }
934 else { 937 else {
950 { 953 {
951 fd = fdx->overloadExactMatch(tfeqptr); 954 fd = fdx->overloadExactMatch(tfeqptr);
952 if (fd) { 955 if (fd) {
953 DtoForceDeclareDsymbol(fd); 956 DtoForceDeclareDsymbol(fd);
954 assert(fd->ir.irFunc->func != 0); 957 assert(fd->ir.irFunc->func != 0);
955 llvm::Constant* c = isaConstant(fd->ir.irFunc->func); 958 LLConstant* c = isaConstant(fd->ir.irFunc->func);
956 assert(c); 959 assert(c);
957 c = llvm::ConstantExpr::getBitCast(c, ptty); 960 c = llvm::ConstantExpr::getBitCast(c, ptty);
958 sinits.push_back(c); 961 sinits.push_back(c);
959 } 962 }
960 else { 963 else {
978 { 981 {
979 fd = fdx->overloadExactMatch(tftostring); 982 fd = fdx->overloadExactMatch(tftostring);
980 if (fd) { 983 if (fd) {
981 DtoForceDeclareDsymbol(fd); 984 DtoForceDeclareDsymbol(fd);
982 assert(fd->ir.irFunc->func != 0); 985 assert(fd->ir.irFunc->func != 0);
983 llvm::Constant* c = isaConstant(fd->ir.irFunc->func); 986 LLConstant* c = isaConstant(fd->ir.irFunc->func);
984 assert(c); 987 assert(c);
985 c = llvm::ConstantExpr::getBitCast(c, ptty); 988 c = llvm::ConstantExpr::getBitCast(c, ptty);
986 sinits.push_back(c); 989 sinits.push_back(c);
987 } 990 }
988 else { 991 else {
996 999
997 // uint m_flags; 1000 // uint m_flags;
998 sinits.push_back(DtoConstUint(tc->hasPointers())); 1001 sinits.push_back(DtoConstUint(tc->hasPointers()));
999 1002
1000 // create the symbol 1003 // create the symbol
1001 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 1004 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
1002 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); 1005 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module);
1003 1006
1004 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 1007 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
1005 } 1008 }
1006 1009
1040 1043
1041 // get type of typeinfo class 1044 // get type of typeinfo class
1042 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 1045 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
1043 1046
1044 // initializer vector 1047 // initializer vector
1045 std::vector<llvm::Constant*> sinits; 1048 std::vector<LLConstant*> sinits;
1046 // first is always the vtable 1049 // first is always the vtable
1047 sinits.push_back(base->ir.irStruct->vtbl); 1050 sinits.push_back(base->ir.irStruct->vtbl);
1048 1051
1049 // monitor 1052 // monitor
1050 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 1053 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
1055 DtoForceDeclareDsymbol(tc->sym); 1058 DtoForceDeclareDsymbol(tc->sym);
1056 assert(tc->sym->ir.irStruct->classInfo); 1059 assert(tc->sym->ir.irStruct->classInfo);
1057 sinits.push_back(tc->sym->ir.irStruct->classInfo); 1060 sinits.push_back(tc->sym->ir.irStruct->classInfo);
1058 1061
1059 // create the symbol 1062 // create the symbol
1060 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 1063 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
1061 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 1064 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
1062 } 1065 }
1063 1066
1064 void TypeInfoClassDeclaration::toDt(dt_t **pdt) 1067 void TypeInfoClassDeclaration::toDt(dt_t **pdt)
1065 { 1068 {
1097 1100
1098 // get type of typeinfo class 1101 // get type of typeinfo class
1099 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 1102 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
1100 1103
1101 // initializer vector 1104 // initializer vector
1102 std::vector<llvm::Constant*> sinits; 1105 std::vector<LLConstant*> sinits;
1103 // first is always the vtable 1106 // first is always the vtable
1104 sinits.push_back(base->ir.irStruct->vtbl); 1107 sinits.push_back(base->ir.irStruct->vtbl);
1105 1108
1106 // monitor 1109 // monitor
1107 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 1110 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
1111 TypeClass *tc = (TypeClass *)tinfo; 1114 TypeClass *tc = (TypeClass *)tinfo;
1112 assert(tc->sym->ir.irStruct->classInfo); 1115 assert(tc->sym->ir.irStruct->classInfo);
1113 sinits.push_back(tc->sym->ir.irStruct->classInfo); 1116 sinits.push_back(tc->sym->ir.irStruct->classInfo);
1114 1117
1115 // create the symbol 1118 // create the symbol
1116 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 1119 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
1117 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 1120 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
1118 } 1121 }
1119 1122
1120 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) 1123 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt)
1121 { 1124 {
1153 1156
1154 // get type of typeinfo class 1157 // get type of typeinfo class
1155 const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); 1158 const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
1156 1159
1157 // initializer vector 1160 // initializer vector
1158 std::vector<llvm::Constant*> sinits; 1161 std::vector<LLConstant*> sinits;
1159 // first is always the vtable 1162 // first is always the vtable
1160 sinits.push_back(base->ir.irStruct->vtbl); 1163 sinits.push_back(base->ir.irStruct->vtbl);
1161 1164
1162 // monitor 1165 // monitor
1163 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 1166 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
1165 // create elements array 1168 // create elements array
1166 assert(tinfo->ty == Ttuple); 1169 assert(tinfo->ty == Ttuple);
1167 TypeTuple *tu = (TypeTuple *)tinfo; 1170 TypeTuple *tu = (TypeTuple *)tinfo;
1168 1171
1169 size_t dim = tu->arguments->dim; 1172 size_t dim = tu->arguments->dim;
1170 std::vector<llvm::Constant*> arrInits; 1173 std::vector<LLConstant*> arrInits;
1171 1174
1172 const llvm::Type* tiTy = Type::typeinfo->type->ir.type->get(); 1175 const LLType* tiTy = Type::typeinfo->type->ir.type->get();
1173 tiTy = getPtrToType(tiTy); 1176 tiTy = getPtrToType(tiTy);
1174 1177
1175 for (size_t i = 0; i < dim; i++) 1178 for (size_t i = 0; i < dim; i++)
1176 { 1179 {
1177 Argument *arg = (Argument *)tu->arguments->data[i]; 1180 Argument *arg = (Argument *)tu->arguments->data[i];
1178 arg->type->getTypeInfo(NULL); 1181 arg->type->getTypeInfo(NULL);
1179 DtoForceDeclareDsymbol(arg->type->vtinfo); 1182 DtoForceDeclareDsymbol(arg->type->vtinfo);
1180 assert(arg->type->vtinfo->ir.irGlobal->value); 1183 assert(arg->type->vtinfo->ir.irGlobal->value);
1181 llvm::Constant* c = isaConstant(arg->type->vtinfo->ir.irGlobal->value); 1184 LLConstant* c = isaConstant(arg->type->vtinfo->ir.irGlobal->value);
1182 c = llvm::ConstantExpr::getBitCast(c, tiTy); 1185 c = llvm::ConstantExpr::getBitCast(c, tiTy);
1183 arrInits.push_back(c); 1186 arrInits.push_back(c);
1184 } 1187 }
1185 1188
1186 // build array type 1189 // build array type
1187 const llvm::ArrayType* arrTy = llvm::ArrayType::get(tiTy, dim); 1190 const llvm::ArrayType* arrTy = llvm::ArrayType::get(tiTy, dim);
1188 llvm::Constant* arrC = llvm::ConstantArray::get(arrTy, arrInits); 1191 LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits);
1189 1192
1190 // build the slice 1193 // build the slice
1191 llvm::Constant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC); 1194 LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC);
1192 sinits.push_back(slice); 1195 sinits.push_back(slice);
1193 1196
1194 // create the symbol 1197 // create the symbol
1195 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 1198 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
1196 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 1199 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
1197 } 1200 }
1198 1201
1199 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) 1202 void TypeInfoTupleDeclaration::toDt(dt_t **pdt)
1200 { 1203 {