comparison gen/typinf.cpp @ 156:ccd07d9f2ce9 trunk

[svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
author ChristianK
date Thu, 01 May 2008 13:05:53 +0200
parents 7f92f477ff53
children 5c17f81fc1c1
comparison
equal deleted inserted replaced
155:7f92f477ff53 156:ccd07d9f2ce9
248 gIR->resolveList.push_back(this); 248 gIR->resolveList.push_back(this);
249 } 249 }
250 250
251 void DtoResolveTypeInfo(TypeInfoDeclaration* tid) 251 void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
252 { 252 {
253 if (tid->llvmResolved) return; 253 if (gIR->irDsymbol[tid].resolved) return;
254 tid->llvmResolved = true; 254 gIR->irDsymbol[tid].resolved = true;
255 255
256 Logger::println("DtoResolveTypeInfo(%s)", tid->toChars()); 256 Logger::println("DtoResolveTypeInfo(%s)", tid->toChars());
257 LOG_SCOPE; 257 LOG_SCOPE;
258 258
259 tid->irGlobal = new IrGlobal(tid); 259 gIR->irDsymbol[tid].irGlobal = new IrGlobal(tid);
260 260
261 gIR->declareList.push_back(tid); 261 gIR->declareList.push_back(tid);
262 } 262 }
263 263
264 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid) 264 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
265 { 265 {
266 if (tid->llvmDeclared) return; 266 if (gIR->irDsymbol[tid].declared) return;
267 tid->llvmDeclared = true; 267 gIR->irDsymbol[tid].declared = true;
268 268
269 Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars()); 269 Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars());
270 LOG_SCOPE; 270 LOG_SCOPE;
271 271
272 std::string mangled(tid->mangle()); 272 std::string mangled(tid->mangle());
280 if (!found) 280 if (!found)
281 { 281 {
282 const llvm::Type* t = llvm::OpaqueType::get(); 282 const llvm::Type* 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->irGlobal) 285 /*if (!gIR->irDsymbol[tid].irGlobal)
286 tid->irGlobal = new IrGlobal(tid);*/ 286 gIR->irDsymbol[tid].irGlobal = new IrGlobal(tid);*/
287 tid->irGlobal->value = g; 287 gIR->irDsymbol[tid].irGlobal->value = g;
288 mangled.append("__TYPE"); 288 mangled.append("__TYPE");
289 gIR->module->addTypeName(mangled, tid->irGlobal->value->getType()->getContainedType(0)); 289 gIR->module->addTypeName(mangled, gIR->irDsymbol[tid].irGlobal->value->getType()->getContainedType(0));
290 Logger::println("Got typeinfo var: %s", tid->irGlobal->value->getName().c_str()); 290 Logger::println("Got typeinfo var: %s", gIR->irDsymbol[tid].irGlobal->value->getName().c_str());
291 tid->llvmInitialized = true; 291 gIR->irDsymbol[tid].initialized = true;
292 tid->llvmDefined = true; 292 gIR->irDsymbol[tid].defined = true;
293 } 293 }
294 else if (!tid->irGlobal->value) { 294 else if (!gIR->irDsymbol[tid].irGlobal->value) {
295 tid->irGlobal->value = found; 295 gIR->irDsymbol[tid].irGlobal->value = found;
296 tid->llvmInitialized = true; 296 gIR->irDsymbol[tid].initialized = true;
297 tid->llvmDefined = true; 297 gIR->irDsymbol[tid].defined = true;
298 } 298 }
299 } 299 }
300 // custom typedef 300 // custom typedef
301 else { 301 else {
302 tid->llvmDeclare(); 302 tid->llvmDeclare();
304 } 304 }
305 } 305 }
306 306
307 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid) 307 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid)
308 { 308 {
309 if (tid->llvmInitialized) return; 309 if (gIR->irDsymbol[tid].initialized) return;
310 tid->llvmInitialized = true; 310 gIR->irDsymbol[tid].initialized = true;
311 311
312 Logger::println("DtoConstInitTypeInfo(%s)", tid->toChars()); 312 Logger::println("DtoConstInitTypeInfo(%s)", tid->toChars());
313 LOG_SCOPE; 313 LOG_SCOPE;
314 314
315 gIR->defineList.push_back(tid); 315 gIR->defineList.push_back(tid);
316 } 316 }
317 317
318 void DtoDefineTypeInfo(TypeInfoDeclaration* tid) 318 void DtoDefineTypeInfo(TypeInfoDeclaration* tid)
319 { 319 {
320 if (tid->llvmDefined) return; 320 if (gIR->irDsymbol[tid].defined) return;
321 tid->llvmDefined = true; 321 gIR->irDsymbol[tid].defined = true;
322 322
323 Logger::println("DtoDefineTypeInfo(%s)", tid->toChars()); 323 Logger::println("DtoDefineTypeInfo(%s)", tid->toChars());
324 LOG_SCOPE; 324 LOG_SCOPE;
325 325
326 tid->llvmDefine(); 326 tid->llvmDefine();
354 DtoResolveClass(base); 354 DtoResolveClass(base);
355 355
356 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 356 const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
357 357
358 // create the symbol 358 // create the symbol
359 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
362 void TypeInfoTypedefDeclaration::llvmDefine() 362 void TypeInfoTypedefDeclaration::llvmDefine()
363 { 363 {
364 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars()); 364 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars());
370 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 370 const llvm::StructType* stype = isaStruct(base->type->llvmType->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(base->irStruct->vtbl); 375 sinits.push_back(gIR->irDsymbol[base].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
380 assert(tinfo->ty == Ttypedef); 380 assert(tinfo->ty == Ttypedef);
389 389
390 sd->basetype->getTypeInfo(NULL); // generate vtinfo 390 sd->basetype->getTypeInfo(NULL); // generate vtinfo
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->irGlobal->value); 394 assert(gIR->irDsymbol[sd->basetype->vtinfo].irGlobal->value);
395 assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->irGlobal->value)); 395 assert(llvm::isa<llvm::Constant>(gIR->irDsymbol[sd->basetype->vtinfo].irGlobal->value));
396 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->irGlobal->value); 396 llvm::Constant* castbase = llvm::cast<llvm::Constant>(gIR->irDsymbol[sd->basetype->vtinfo].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();
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 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
424 isaGlobalVar(irGlobal->value)->setInitializer(tiInit); 424 isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
425 } 425 }
426 426
427 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) 427 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt)
428 { 428 {
429 assert(0); 429 assert(0);
440 DtoResolveClass(base); 440 DtoResolveClass(base);
441 441
442 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 442 const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
443 443
444 // create the symbol 444 // create the symbol
445 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
448 void TypeInfoEnumDeclaration::llvmDefine() 448 void TypeInfoEnumDeclaration::llvmDefine()
449 { 449 {
450 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars()); 450 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars());
455 455
456 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 456 const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
457 457
458 // vtbl 458 // vtbl
459 std::vector<llvm::Constant*> sinits; 459 std::vector<llvm::Constant*> sinits;
460 sinits.push_back(base->irStruct->vtbl); 460 sinits.push_back(gIR->irDsymbol[base].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
465 assert(tinfo->ty == Tenum); 465 assert(tinfo->ty == Tenum);
474 474
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->irGlobal->value)); 479 assert(llvm::isa<llvm::Constant>(gIR->irDsymbol[sd->memtype->vtinfo].irGlobal->value));
480 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->irGlobal->value); 480 llvm::Constant* castbase = llvm::cast<llvm::Constant>(gIR->irDsymbol[sd->memtype->vtinfo].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();
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 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
509 isaGlobalVar(irGlobal->value)->setInitializer(tiInit); 509 isaGlobalVar(gIR->irDsymbol[this].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);
522 DtoResolveClass(base); 522 DtoResolveClass(base);
523 523
524 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 524 const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
525 525
526 // create the symbol 526 // create the symbol
527 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;
534 534
535 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 535 const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
536 536
537 // vtbl 537 // vtbl
538 std::vector<llvm::Constant*> sinits; 538 std::vector<llvm::Constant*> sinits;
539 sinits.push_back(base->irStruct->vtbl); 539 sinits.push_back(gIR->irDsymbol[base].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
544 // TypeInfo base 544 // TypeInfo base
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->irGlobal->value)); 549 assert(llvm::isa<llvm::Constant>(gIR->irDsymbol[basetype->vtinfo].irGlobal->value));
550 llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->irGlobal->value); 550 llvm::Constant* castbase = llvm::cast<llvm::Constant>(gIR->irDsymbol[basetype->vtinfo].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 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
556 isaGlobalVar(tid->irGlobal->value)->setInitializer(tiInit); 556 isaGlobalVar(gIR->irDsymbol[tid].irGlobal->value)->setInitializer(tiInit);
557 } 557 }
558 558
559 /* ========================================================================= */ 559 /* ========================================================================= */
560 560
561 void TypeInfoPointerDeclaration::llvmDeclare() 561 void TypeInfoPointerDeclaration::llvmDeclare()
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(base->type->llvmType->get());
630 630
631 // create the symbol 631 // create the symbol
632 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
635 void TypeInfoStaticArrayDeclaration::llvmDefine() 635 void TypeInfoStaticArrayDeclaration::llvmDefine()
636 { 636 {
637 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); 637 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars());
645 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 645 const llvm::StructType* stype = isaStruct(base->type->llvmType->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(base->irStruct->vtbl); 650 sinits.push_back(gIR->irDsymbol[base].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)));
654 654
655 // value typeinfo 655 // value typeinfo
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->irGlobal->value); 663 llvm::Constant* castbase = isaConstant(gIR->irDsymbol[tc->next->vtinfo].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 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
672 isaGlobalVar(irGlobal->value)->setInitializer(tiInit); 672 isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
673 } 673 }
674 674
675 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) 675 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt)
676 { 676 {
677 assert(0); 677 assert(0);
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(base->type->llvmType->get());
693 693
694 // create the symbol 694 // create the symbol
695 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
698 void TypeInfoAssociativeArrayDeclaration::llvmDefine() 698 void TypeInfoAssociativeArrayDeclaration::llvmDefine()
699 { 699 {
700 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); 700 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars());
708 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 708 const llvm::StructType* stype = isaStruct(base->type->llvmType->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(base->irStruct->vtbl); 713 sinits.push_back(gIR->irDsymbol[base].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)));
717 717
718 // get type 718 // get type
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->irGlobal->value); 728 llvm::Constant* castbase = isaConstant(gIR->irDsymbol[tc->next->vtinfo].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);
734 734
735 // get symbol 735 // get symbol
736 assert(tc->index->vtinfo); 736 assert(tc->index->vtinfo);
737 DtoForceDeclareDsymbol(tc->index->vtinfo); 737 DtoForceDeclareDsymbol(tc->index->vtinfo);
738 castbase = isaConstant(tc->index->vtinfo->irGlobal->value); 738 castbase = isaConstant(gIR->irDsymbol[tc->index->vtinfo].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 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
744 isaGlobalVar(irGlobal->value)->setInitializer(tiInit); 744 isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
745 } 745 }
746 746
747 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) 747 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt)
748 { 748 {
749 assert(0); 749 assert(0);
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(((TypeClass*)base->type)->llvmType->get());
826 826
827 // create the symbol 827 // create the symbol
828 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
831 void TypeInfoStructDeclaration::llvmDefine() 831 void TypeInfoStructDeclaration::llvmDefine()
832 { 832 {
833 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); 833 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars());
843 843
844 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); 844 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get());
845 845
846 // vtbl 846 // vtbl
847 std::vector<llvm::Constant*> sinits; 847 std::vector<llvm::Constant*> sinits;
848 sinits.push_back(base->irStruct->vtbl); 848 sinits.push_back(gIR->irDsymbol[base].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
853 // char[] name 853 // char[] name
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(tc->llvmType->get());
868 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(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
873 FuncDeclaration *fd; 873 FuncDeclaration *fd;
923 if (fdx) 923 if (fdx)
924 { 924 {
925 fd = fdx->overloadExactMatch(tftohash); 925 fd = fdx->overloadExactMatch(tftohash);
926 if (fd) { 926 if (fd) {
927 DtoForceDeclareDsymbol(fd); 927 DtoForceDeclareDsymbol(fd);
928 assert(gIR->irFunc[fd]->func != 0); 928 assert(gIR->irDsymbol[fd].irFunc->func != 0);
929 llvm::Constant* c = isaConstant(gIR->irFunc[fd]->func); 929 llvm::Constant* c = isaConstant(gIR->irDsymbol[fd].irFunc->func);
930 assert(c); 930 assert(c);
931 c = llvm::ConstantExpr::getBitCast(c, ptty); 931 c = llvm::ConstantExpr::getBitCast(c, ptty);
932 sinits.push_back(c); 932 sinits.push_back(c);
933 } 933 }
934 else { 934 else {
949 if (fdx) 949 if (fdx)
950 { 950 {
951 fd = fdx->overloadExactMatch(tfeqptr); 951 fd = fdx->overloadExactMatch(tfeqptr);
952 if (fd) { 952 if (fd) {
953 DtoForceDeclareDsymbol(fd); 953 DtoForceDeclareDsymbol(fd);
954 assert(gIR->irFunc[fd]->func != 0); 954 assert(gIR->irDsymbol[fd].irFunc->func != 0);
955 llvm::Constant* c = isaConstant(gIR->irFunc[fd]->func); 955 llvm::Constant* c = isaConstant(gIR->irDsymbol[fd].irFunc->func);
956 assert(c); 956 assert(c);
957 c = llvm::ConstantExpr::getBitCast(c, ptty); 957 c = llvm::ConstantExpr::getBitCast(c, ptty);
958 sinits.push_back(c); 958 sinits.push_back(c);
959 } 959 }
960 else { 960 else {
977 if (fdx) 977 if (fdx)
978 { 978 {
979 fd = fdx->overloadExactMatch(tftostring); 979 fd = fdx->overloadExactMatch(tftostring);
980 if (fd) { 980 if (fd) {
981 DtoForceDeclareDsymbol(fd); 981 DtoForceDeclareDsymbol(fd);
982 assert(gIR->irFunc[fd]->func != 0); 982 assert(gIR->irDsymbol[fd].irFunc->func != 0);
983 llvm::Constant* c = isaConstant(gIR->irFunc[fd]->func); 983 llvm::Constant* c = isaConstant(gIR->irDsymbol[fd].irFunc->func);
984 assert(c); 984 assert(c);
985 c = llvm::ConstantExpr::getBitCast(c, ptty); 985 c = llvm::ConstantExpr::getBitCast(c, ptty);
986 sinits.push_back(c); 986 sinits.push_back(c);
987 } 987 }
988 else { 988 else {
999 999
1000 // create the symbol 1000 // create the symbol
1001 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 1001 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
1002 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); 1002 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module);
1003 1003
1004 isaGlobalVar(irGlobal->value)->setInitializer(tiInit); 1004 isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
1005 } 1005 }
1006 1006
1007 void TypeInfoStructDeclaration::toDt(dt_t **pdt) 1007 void TypeInfoStructDeclaration::toDt(dt_t **pdt)
1008 { 1008 {
1009 assert(0); 1009 assert(0);
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(base->type->llvmType->get());
1026 1026
1027 // create the symbol 1027 // create the symbol
1028 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
1031 void TypeInfoClassDeclaration::llvmDefine() 1031 void TypeInfoClassDeclaration::llvmDefine()
1032 { 1032 {
1033 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); 1033 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars());
1042 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 1042 const llvm::StructType* stype = isaStruct(base->type->llvmType->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(base->irStruct->vtbl); 1047 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
1048 1048
1049 // monitor 1049 // monitor
1050 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 1050 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
1051 1051
1052 // get classinfo 1052 // get classinfo
1053 assert(tinfo->ty == Tclass); 1053 assert(tinfo->ty == Tclass);
1054 TypeClass *tc = (TypeClass *)tinfo; 1054 TypeClass *tc = (TypeClass *)tinfo;
1055 assert(tc->sym->irStruct->classInfo); 1055 assert(gIR->irDsymbol[tc->sym].irStruct->classInfo);
1056 sinits.push_back(tc->sym->irStruct->classInfo); 1056 sinits.push_back(gIR->irDsymbol[tc->sym].irStruct->classInfo);
1057 1057
1058 // create the symbol 1058 // create the symbol
1059 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 1059 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
1060 isaGlobalVar(irGlobal->value)->setInitializer(tiInit); 1060 isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
1061 } 1061 }
1062 1062
1063 void TypeInfoClassDeclaration::toDt(dt_t **pdt) 1063 void TypeInfoClassDeclaration::toDt(dt_t **pdt)
1064 { 1064 {
1065 assert(0); 1065 assert(0);
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(base->type->llvmType->get());
1082 1082
1083 // create the symbol 1083 // create the symbol
1084 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
1087 void TypeInfoInterfaceDeclaration::llvmDefine() 1087 void TypeInfoInterfaceDeclaration::llvmDefine()
1088 { 1088 {
1089 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars()); 1089 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars());
1098 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 1098 const llvm::StructType* stype = isaStruct(base->type->llvmType->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(base->irStruct->vtbl); 1103 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
1104 1104
1105 // monitor 1105 // monitor
1106 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 1106 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
1107 1107
1108 // get classinfo 1108 // get classinfo
1109 assert(tinfo->ty == Tclass); 1109 assert(tinfo->ty == Tclass);
1110 TypeClass *tc = (TypeClass *)tinfo; 1110 TypeClass *tc = (TypeClass *)tinfo;
1111 assert(tc->sym->irStruct->classInfo); 1111 assert(gIR->irDsymbol[tc->sym].irStruct->classInfo);
1112 sinits.push_back(tc->sym->irStruct->classInfo); 1112 sinits.push_back(gIR->irDsymbol[tc->sym].irStruct->classInfo);
1113 1113
1114 // create the symbol 1114 // create the symbol
1115 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 1115 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
1116 isaGlobalVar(irGlobal->value)->setInitializer(tiInit); 1116 isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
1117 } 1117 }
1118 1118
1119 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) 1119 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt)
1120 { 1120 {
1121 assert(0); 1121 assert(0);
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(base->type->llvmType->get());
1138 1138
1139 // create the symbol 1139 // create the symbol
1140 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
1143 void TypeInfoTupleDeclaration::llvmDefine() 1143 void TypeInfoTupleDeclaration::llvmDefine()
1144 { 1144 {
1145 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars()); 1145 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars());
1154 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); 1154 const llvm::StructType* stype = isaStruct(base->type->llvmType->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(base->irStruct->vtbl); 1159 sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
1160 1160
1161 // monitor 1161 // monitor
1162 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); 1162 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
1163 1163
1164 // create elements array 1164 // create elements array
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];
1177 arg->type->getTypeInfo(NULL); 1177 arg->type->getTypeInfo(NULL);
1178 DtoForceDeclareDsymbol(arg->type->vtinfo); 1178 DtoForceDeclareDsymbol(arg->type->vtinfo);
1179 assert(arg->type->vtinfo->irGlobal->value); 1179 assert(gIR->irDsymbol[arg->type->vtinfo].irGlobal->value);
1180 llvm::Constant* c = isaConstant(arg->type->vtinfo->irGlobal->value); 1180 llvm::Constant* c = isaConstant(gIR->irDsymbol[arg->type->vtinfo].irGlobal->value);
1181 c = llvm::ConstantExpr::getBitCast(c, tiTy); 1181 c = llvm::ConstantExpr::getBitCast(c, tiTy);
1182 arrInits.push_back(c); 1182 arrInits.push_back(c);
1183 } 1183 }
1184 1184
1185 // build array type 1185 // build array type
1190 llvm::Constant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC); 1190 llvm::Constant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC);
1191 sinits.push_back(slice); 1191 sinits.push_back(slice);
1192 1192
1193 // create the symbol 1193 // create the symbol
1194 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); 1194 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
1195 isaGlobalVar(irGlobal->value)->setInitializer(tiInit); 1195 isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
1196 } 1196 }
1197 1197
1198 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) 1198 void TypeInfoTupleDeclaration::toDt(dt_t **pdt)
1199 { 1199 {
1200 assert(0); 1200 assert(0);