comparison gen/typinf.cpp @ 157:5c17f81fc1c1 trunk

[svn r173] moved IR state previously stored in Type into IrType and a Type->IrType map; fixes #7
author ChristianK
date Thu, 01 May 2008 13:32:08 +0200
parents ccd07d9f2ce9
children a8cd9bc1021a
comparison
equal deleted inserted replaced
156:ccd07d9f2ce9 157:5c17f81fc1c1
351 LOG_SCOPE; 351 LOG_SCOPE;
352 352
353 ClassDeclaration* base = Type::typeinfotypedef; 353 ClassDeclaration* base = Type::typeinfotypedef;
354 DtoResolveClass(base); 354 DtoResolveClass(base);
355 355
356 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 356 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
357 357
358 // create the symbol 358 // create the symbol
359 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); 359 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
360 } 360 }
361 361
365 LOG_SCOPE; 365 LOG_SCOPE;
366 366
367 ClassDeclaration* base = Type::typeinfotypedef; 367 ClassDeclaration* base = Type::typeinfotypedef;
368 DtoForceConstInitDsymbol(base); 368 DtoForceConstInitDsymbol(base);
369 369
370 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 370 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].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<llvm::Constant*> sinits;
375 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); 375 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
437 LOG_SCOPE; 437 LOG_SCOPE;
438 438
439 ClassDeclaration* base = Type::typeinfoenum; 439 ClassDeclaration* base = Type::typeinfoenum;
440 DtoResolveClass(base); 440 DtoResolveClass(base);
441 441
442 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 442 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
443 443
444 // create the symbol 444 // create the symbol
445 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); 445 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
446 } 446 }
447 447
451 LOG_SCOPE; 451 LOG_SCOPE;
452 452
453 ClassDeclaration* base = Type::typeinfoenum; 453 ClassDeclaration* base = Type::typeinfoenum;
454 DtoForceConstInitDsymbol(base); 454 DtoForceConstInitDsymbol(base);
455 455
456 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 456 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
457 457
458 // vtbl 458 // vtbl
459 std::vector<llvm::Constant*> sinits; 459 std::vector<llvm::Constant*> sinits;
460 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); 460 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
461 461
519 static llvm::Constant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) 519 static llvm::Constant* 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->llvmType->get()); 524 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
525 525
526 // create the symbol 526 // create the symbol
527 gIR->irDsymbol[tid].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); 527 gIR->irDsymbol[tid].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 llvm::Constant* 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->llvmType->get()); 535 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
536 536
537 // vtbl 537 // vtbl
538 std::vector<llvm::Constant*> sinits; 538 std::vector<llvm::Constant*> sinits;
539 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); 539 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
540 540
624 // init typeinfo class 624 // init typeinfo class
625 ClassDeclaration* base = Type::typeinfostaticarray; 625 ClassDeclaration* base = Type::typeinfostaticarray;
626 DtoResolveClass(base); 626 DtoResolveClass(base);
627 627
628 // get type of typeinfo class 628 // get type of typeinfo class
629 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 629 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
630 630
631 // create the symbol 631 // create the symbol
632 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); 632 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
633 } 633 }
634 634
640 // init typeinfo class 640 // init typeinfo class
641 ClassDeclaration* base = Type::typeinfostaticarray; 641 ClassDeclaration* base = Type::typeinfostaticarray;
642 DtoForceConstInitDsymbol(base); 642 DtoForceConstInitDsymbol(base);
643 643
644 // get type of typeinfo class 644 // get type of typeinfo class
645 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 645 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
646 646
647 // initializer vector 647 // initializer vector
648 std::vector<llvm::Constant*> sinits; 648 std::vector<llvm::Constant*> sinits;
649 // first is always the vtable 649 // first is always the vtable
650 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); 650 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
687 // init typeinfo class 687 // init typeinfo class
688 ClassDeclaration* base = Type::typeinfoassociativearray; 688 ClassDeclaration* base = Type::typeinfoassociativearray;
689 DtoResolveClass(base); 689 DtoResolveClass(base);
690 690
691 // get type of typeinfo class 691 // get type of typeinfo class
692 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 692 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
693 693
694 // create the symbol 694 // create the symbol
695 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); 695 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
696 } 696 }
697 697
703 // init typeinfo class 703 // init typeinfo class
704 ClassDeclaration* base = Type::typeinfoassociativearray; 704 ClassDeclaration* base = Type::typeinfoassociativearray;
705 DtoForceConstInitDsymbol(base); 705 DtoForceConstInitDsymbol(base);
706 706
707 // get type of typeinfo class 707 // get type of typeinfo class
708 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 708 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
709 709
710 // initializer vector 710 // initializer vector
711 std::vector<llvm::Constant*> sinits; 711 std::vector<llvm::Constant*> sinits;
712 // first is always the vtable 712 // first is always the vtable
713 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); 713 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
820 DtoResolveDsymbol(sd); 820 DtoResolveDsymbol(sd);
821 821
822 ClassDeclaration* base = Type::typeinfostruct; 822 ClassDeclaration* base = Type::typeinfostruct;
823 DtoResolveClass(base); 823 DtoResolveClass(base);
824 824
825 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); 825 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
826 826
827 // create the symbol 827 // create the symbol
828 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); 828 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
829 } 829 }
830 830
839 DtoForceConstInitDsymbol(sd); 839 DtoForceConstInitDsymbol(sd);
840 840
841 ClassDeclaration* base = Type::typeinfostruct; 841 ClassDeclaration* base = Type::typeinfostruct;
842 DtoForceConstInitDsymbol(base); 842 DtoForceConstInitDsymbol(base);
843 843
844 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); 844 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
845 845
846 // vtbl 846 // vtbl
847 std::vector<llvm::Constant*> sinits; 847 std::vector<llvm::Constant*> sinits;
848 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); 848 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
849 849
862 { 862 {
863 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); 863 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
864 } 864 }
865 else 865 else
866 { 866 {
867 size_t cisize = getTypeStoreSize(tc->llvmType->get()); 867 size_t cisize = getTypeStoreSize(gIR->irType[tc].type->get());
868 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(gIR->irDsymbol[sd].irStruct->init, initpt); 868 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(gIR->irDsymbol[sd].irStruct->init, initpt);
869 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); 869 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
870 } 870 }
871 871
872 // toX functions ground work 872 // toX functions ground work
1020 ClassDeclaration* base = Type::typeinfoclass; 1020 ClassDeclaration* base = Type::typeinfoclass;
1021 assert(base); 1021 assert(base);
1022 DtoResolveClass(base); 1022 DtoResolveClass(base);
1023 1023
1024 // get type of typeinfo class 1024 // get type of typeinfo class
1025 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 1025 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
1026 1026
1027 // create the symbol 1027 // create the symbol
1028 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); 1028 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
1029 } 1029 }
1030 1030
1037 ClassDeclaration* base = Type::typeinfoclass; 1037 ClassDeclaration* base = Type::typeinfoclass;
1038 assert(base); 1038 assert(base);
1039 DtoForceConstInitDsymbol(base); 1039 DtoForceConstInitDsymbol(base);
1040 1040
1041 // get type of typeinfo class 1041 // get type of typeinfo class
1042 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 1042 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
1043 1043
1044 // initializer vector 1044 // initializer vector
1045 std::vector<llvm::Constant*> sinits; 1045 std::vector<llvm::Constant*> sinits;
1046 // first is always the vtable 1046 // first is always the vtable
1047 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); 1047 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
1076 ClassDeclaration* base = Type::typeinfointerface; 1076 ClassDeclaration* base = Type::typeinfointerface;
1077 assert(base); 1077 assert(base);
1078 DtoResolveClass(base); 1078 DtoResolveClass(base);
1079 1079
1080 // get type of typeinfo class 1080 // get type of typeinfo class
1081 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 1081 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
1082 1082
1083 // create the symbol 1083 // create the symbol
1084 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); 1084 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
1085 } 1085 }
1086 1086
1093 ClassDeclaration* base = Type::typeinfointerface; 1093 ClassDeclaration* base = Type::typeinfointerface;
1094 assert(base); 1094 assert(base);
1095 DtoForceConstInitDsymbol(base); 1095 DtoForceConstInitDsymbol(base);
1096 1096
1097 // get type of typeinfo class 1097 // get type of typeinfo class
1098 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 1098 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
1099 1099
1100 // initializer vector 1100 // initializer vector
1101 std::vector<llvm::Constant*> sinits; 1101 std::vector<llvm::Constant*> sinits;
1102 // first is always the vtable 1102 // first is always the vtable
1103 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); 1103 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
1132 ClassDeclaration* base = Type::typeinfotypelist; 1132 ClassDeclaration* base = Type::typeinfotypelist;
1133 assert(base); 1133 assert(base);
1134 DtoResolveClass(base); 1134 DtoResolveClass(base);
1135 1135
1136 // get type of typeinfo class 1136 // get type of typeinfo class
1137 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 1137 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
1138 1138
1139 // create the symbol 1139 // create the symbol
1140 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); 1140 gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
1141 } 1141 }
1142 1142
1149 ClassDeclaration* base = Type::typeinfotypelist; 1149 ClassDeclaration* base = Type::typeinfotypelist;
1150 assert(base); 1150 assert(base);
1151 DtoForceConstInitDsymbol(base); 1151 DtoForceConstInitDsymbol(base);
1152 1152
1153 // get type of typeinfo class 1153 // get type of typeinfo class
1154 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 1154 const llvm::StructType* stype = isaStruct(gIR->irType[base->type].type->get());
1155 1155
1156 // initializer vector 1156 // initializer vector
1157 std::vector<llvm::Constant*> sinits; 1157 std::vector<llvm::Constant*> sinits;
1158 // first is always the vtable 1158 // first is always the vtable
1159 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); 1159 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
1166 TypeTuple *tu = (TypeTuple *)tinfo; 1166 TypeTuple *tu = (TypeTuple *)tinfo;
1167 1167
1168 size_t dim = tu->arguments->dim; 1168 size_t dim = tu->arguments->dim;
1169 std::vector<llvm::Constant*> arrInits; 1169 std::vector<llvm::Constant*> arrInits;
1170 1170
1171 const llvm::Type* tiTy = Type::typeinfo->type->llvmType->get(); 1171 const llvm::Type* tiTy = gIR->irType[Type::typeinfo->type].type->get();
1172 tiTy = getPtrToType(tiTy); 1172 tiTy = getPtrToType(tiTy);
1173 1173
1174 for (size_t i = 0; i < dim; i++) 1174 for (size_t i = 0; i < dim; i++)
1175 { 1175 {
1176 Argument *arg = (Argument *)tu->arguments->data[i]; 1176 Argument *arg = (Argument *)tu->arguments->data[i];