Mercurial > projects > ldc
comparison gen/typinf.cpp @ 106:5b5194b25f33 trunk
[svn r110] Fixed typeinfo for classes.
author | lindquist |
---|---|
date | Mon, 19 Nov 2007 06:01:48 +0100 |
parents | 182b41f56b7f |
children | 5ab8e92611f9 |
comparison
equal
deleted
inserted
replaced
105:182b41f56b7f | 106:5b5194b25f33 |
---|---|
35 #include "gen/logger.h" | 35 #include "gen/logger.h" |
36 #include "gen/runtime.h" | 36 #include "gen/runtime.h" |
37 #include "gen/tollvm.h" | 37 #include "gen/tollvm.h" |
38 #include "gen/arrays.h" | 38 #include "gen/arrays.h" |
39 #include "gen/structs.h" | 39 #include "gen/structs.h" |
40 #include "gen/classes.h" | |
40 | 41 |
41 /******************************************* | 42 /******************************************* |
42 * Get a canonicalized form of the TypeInfo for use with the internal | 43 * Get a canonicalized form of the TypeInfo for use with the internal |
43 * runtime library routines. Canonicalized in that static arrays are | 44 * runtime library routines. Canonicalized in that static arrays are |
44 * represented as dynamic arrays, enums are represented by their | 45 * represented as dynamic arrays, enums are represented by their |
281 tid->llvmInitialized = true; | 282 tid->llvmInitialized = true; |
282 tid->llvmDefined = true; | 283 tid->llvmDefined = true; |
283 } | 284 } |
284 // custom typedef | 285 // custom typedef |
285 else { | 286 else { |
287 tid->llvmDeclare(); | |
286 gIR->constInitList.push_back(tid); | 288 gIR->constInitList.push_back(tid); |
287 } | 289 } |
288 } | 290 } |
289 | 291 |
290 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid) | 292 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid) |
293 tid->llvmInitialized = true; | 295 tid->llvmInitialized = true; |
294 | 296 |
295 Logger::println("* DtoConstInitTypeInfo(%s)", tid->toChars()); | 297 Logger::println("* DtoConstInitTypeInfo(%s)", tid->toChars()); |
296 LOG_SCOPE; | 298 LOG_SCOPE; |
297 | 299 |
298 tid->toDt(NULL); | 300 gIR->defineList.push_back(tid); |
299 | |
300 tid->llvmDefined = true; | |
301 //gIR->defineList.push_back(tid); | |
302 } | 301 } |
303 | 302 |
304 void DtoDefineTypeInfo(TypeInfoDeclaration* tid) | 303 void DtoDefineTypeInfo(TypeInfoDeclaration* tid) |
305 { | 304 { |
306 if (tid->llvmDefined) return; | 305 if (tid->llvmDefined) return; |
307 tid->llvmDefined = true; | 306 tid->llvmDefined = true; |
308 | 307 |
309 Logger::println("* DtoDefineTypeInfo(%s)", tid->toChars()); | 308 Logger::println("* DtoDefineTypeInfo(%s)", tid->toChars()); |
310 LOG_SCOPE; | 309 LOG_SCOPE; |
311 | 310 |
312 assert(0); | 311 tid->llvmDefine(); |
313 } | 312 } |
314 | 313 |
315 /* ========================================================================= */ | 314 /* ========================================================================= */ |
316 | 315 |
317 void TypeInfoDeclaration::toDt(dt_t **pdt) | 316 void TypeInfoDeclaration::toDt(dt_t **pdt) |
318 { | 317 { |
319 assert(0 && "TypeInfoDeclaration"); | 318 assert(0 && "TypeInfoDeclaration::toDt"); |
320 } | 319 } |
321 | 320 |
322 /* ========================================================================= */ | 321 void TypeInfoDeclaration::llvmDeclare() |
323 | 322 { |
324 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) | 323 assert(0 && "TypeInfoDeclaration::llvmDeclare"); |
325 { | 324 } |
326 Logger::println("TypeInfoTypedefDeclaration::toDt() %s", toChars()); | 325 |
326 void TypeInfoDeclaration::llvmDefine() | |
327 { | |
328 assert(0 && "TypeInfoDeclaration::llvmDeclare"); | |
329 } | |
330 | |
331 /* ========================================================================= */ | |
332 | |
333 void TypeInfoTypedefDeclaration::llvmDeclare() | |
334 { | |
335 Logger::println("TypeInfoTypedefDeclaration::llvmDeclare() %s", toChars()); | |
336 LOG_SCOPE; | |
337 | |
338 ClassDeclaration* base = Type::typeinfotypedef; | |
339 DtoResolveClass(base); | |
340 | |
341 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
342 | |
343 // create the symbol | |
344 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
345 } | |
346 | |
347 void TypeInfoTypedefDeclaration::llvmDefine() | |
348 { | |
349 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars()); | |
327 LOG_SCOPE; | 350 LOG_SCOPE; |
328 | 351 |
329 ClassDeclaration* base = Type::typeinfotypedef; | 352 ClassDeclaration* base = Type::typeinfotypedef; |
330 DtoForceConstInitDsymbol(base); | 353 DtoForceConstInitDsymbol(base); |
331 | 354 |
346 //sd->basetype = sd->basetype->merge(); | 369 //sd->basetype = sd->basetype->merge(); |
347 | 370 |
348 sd->basetype->getTypeInfo(NULL); // generate vtinfo | 371 sd->basetype->getTypeInfo(NULL); // generate vtinfo |
349 assert(sd->basetype->vtinfo); | 372 assert(sd->basetype->vtinfo); |
350 if (!sd->basetype->vtinfo->llvmValue) | 373 if (!sd->basetype->vtinfo->llvmValue) |
351 DtoForceConstInitDsymbol(sd->basetype->vtinfo); | 374 DtoForceDeclareDsymbol(sd->basetype->vtinfo); |
352 | 375 |
353 assert(sd->basetype->vtinfo->llvmValue); | 376 assert(sd->basetype->vtinfo->llvmValue); |
354 assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->llvmValue)); | 377 assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->llvmValue)); |
355 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->llvmValue); | 378 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->llvmValue); |
356 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); | 379 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
378 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); | 401 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
379 } | 402 } |
380 | 403 |
381 // create the symbol | 404 // create the symbol |
382 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 405 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
383 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); | 406 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
384 | 407 } |
385 llvmValue = gvar; | 408 |
386 } | 409 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) |
387 | 410 { |
388 /* ========================================================================= */ | 411 assert(0); |
389 | 412 } |
390 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) | 413 |
391 { | 414 /* ========================================================================= */ |
392 Logger::println("TypeInfoTypedefDeclaration::toDt() %s", toChars()); | 415 |
416 void TypeInfoEnumDeclaration::llvmDeclare() | |
417 { | |
418 Logger::println("TypeInfoEnumDeclaration::llvmDeclare() %s", toChars()); | |
419 LOG_SCOPE; | |
420 | |
421 ClassDeclaration* base = Type::typeinfoenum; | |
422 DtoResolveClass(base); | |
423 | |
424 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
425 | |
426 // create the symbol | |
427 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
428 } | |
429 | |
430 void TypeInfoEnumDeclaration::llvmDefine() | |
431 { | |
432 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars()); | |
393 LOG_SCOPE; | 433 LOG_SCOPE; |
394 | 434 |
395 ClassDeclaration* base = Type::typeinfoenum; | 435 ClassDeclaration* base = Type::typeinfoenum; |
396 DtoForceConstInitDsymbol(base); | 436 DtoForceConstInitDsymbol(base); |
397 | 437 |
411 //sd->basetype = sd->basetype->merge(); | 451 //sd->basetype = sd->basetype->merge(); |
412 | 452 |
413 sd->memtype->getTypeInfo(NULL); // generate vtinfo | 453 sd->memtype->getTypeInfo(NULL); // generate vtinfo |
414 assert(sd->memtype->vtinfo); | 454 assert(sd->memtype->vtinfo); |
415 if (!sd->memtype->vtinfo->llvmValue) | 455 if (!sd->memtype->vtinfo->llvmValue) |
416 DtoForceConstInitDsymbol(sd->memtype->vtinfo); | 456 DtoForceDeclareDsymbol(sd->memtype->vtinfo); |
417 | 457 |
418 assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->llvmValue)); | 458 assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->llvmValue)); |
419 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->llvmValue); | 459 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->llvmValue); |
420 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); | 460 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
421 sinits.push_back(castbase); | 461 sinits.push_back(castbase); |
443 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); | 483 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
444 } | 484 } |
445 | 485 |
446 // create the symbol | 486 // create the symbol |
447 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 487 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
448 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); | 488 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
449 | 489 } |
450 llvmValue = gvar; | 490 |
451 } | 491 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) |
452 | 492 { |
453 /* ========================================================================= */ | 493 assert(0); |
454 | 494 } |
455 static llvm::Constant* LLVM_D_Create_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) | 495 |
496 /* ========================================================================= */ | |
497 | |
498 static llvm::Constant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) | |
499 { | |
500 ClassDeclaration* base = cd; | |
501 DtoResolveClass(base); | |
502 | |
503 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
504 | |
505 // create the symbol | |
506 tid->llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); | |
507 } | |
508 | |
509 static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) | |
456 { | 510 { |
457 ClassDeclaration* base = cd; | 511 ClassDeclaration* base = cd; |
458 DtoForceConstInitDsymbol(base); | 512 DtoForceConstInitDsymbol(base); |
459 | 513 |
460 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | 514 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
465 // TypeInfo base | 519 // TypeInfo base |
466 Logger::println("generating base typeinfo"); | 520 Logger::println("generating base typeinfo"); |
467 basetype->getTypeInfo(NULL); | 521 basetype->getTypeInfo(NULL); |
468 assert(basetype->vtinfo); | 522 assert(basetype->vtinfo); |
469 if (!basetype->vtinfo->llvmValue) | 523 if (!basetype->vtinfo->llvmValue) |
470 DtoForceConstInitDsymbol(basetype->vtinfo); | 524 DtoForceDeclareDsymbol(basetype->vtinfo); |
471 assert(llvm::isa<llvm::Constant>(basetype->vtinfo->llvmValue)); | 525 assert(llvm::isa<llvm::Constant>(basetype->vtinfo->llvmValue)); |
472 llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->llvmValue); | 526 llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->llvmValue); |
473 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); | 527 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
474 sinits.push_back(castbase); | 528 sinits.push_back(castbase); |
475 | 529 |
476 // create the symbol | 530 // create the symbol |
477 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 531 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
478 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,tid->toChars(),gIR->module); | 532 isaGlobalVar(tid->llvmValue)->setInitializer(tiInit); |
479 | 533 } |
480 tid->llvmValue = gvar; | 534 |
481 } | 535 /* ========================================================================= */ |
482 | 536 |
483 /* ========================================================================= */ | 537 void TypeInfoPointerDeclaration::llvmDeclare() |
484 | 538 { |
485 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) | 539 Logger::println("TypeInfoPointerDeclaration::llvmDeclare() %s", toChars()); |
486 { | |
487 Logger::println("TypeInfoPointerDeclaration::toDt() %s", toChars()); | |
488 LOG_SCOPE; | 540 LOG_SCOPE; |
489 | 541 |
490 assert(tinfo->ty == Tpointer); | 542 assert(tinfo->ty == Tpointer); |
491 TypePointer *tc = (TypePointer *)tinfo; | 543 TypePointer *tc = (TypePointer *)tinfo; |
492 | 544 |
493 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfopointer); | 545 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfopointer); |
494 } | 546 } |
495 | 547 |
496 /* ========================================================================= */ | 548 void TypeInfoPointerDeclaration::llvmDefine() |
497 | 549 { |
498 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) | 550 Logger::println("TypeInfoPointerDeclaration::llvmDefine() %s", toChars()); |
499 { | 551 LOG_SCOPE; |
500 Logger::println("TypeInfoArrayDeclaration::toDt() %s", toChars()); | 552 |
553 assert(tinfo->ty == Tpointer); | |
554 TypePointer *tc = (TypePointer *)tinfo; | |
555 | |
556 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfopointer); | |
557 } | |
558 | |
559 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) | |
560 { | |
561 assert(0); | |
562 } | |
563 | |
564 /* ========================================================================= */ | |
565 | |
566 void TypeInfoArrayDeclaration::llvmDeclare() | |
567 { | |
568 Logger::println("TypeInfoArrayDeclaration::llvmDeclare() %s", toChars()); | |
501 LOG_SCOPE; | 569 LOG_SCOPE; |
502 | 570 |
503 assert(tinfo->ty == Tarray); | 571 assert(tinfo->ty == Tarray); |
504 TypeDArray *tc = (TypeDArray *)tinfo; | 572 TypeDArray *tc = (TypeDArray *)tinfo; |
505 | 573 |
506 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfoarray); | 574 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoarray); |
507 } | 575 } |
508 | 576 |
509 /* ========================================================================= */ | 577 void TypeInfoArrayDeclaration::llvmDefine() |
510 | 578 { |
511 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) | 579 Logger::println("TypeInfoArrayDeclaration::llvmDefine() %s", toChars()); |
580 LOG_SCOPE; | |
581 | |
582 assert(tinfo->ty == Tarray); | |
583 TypeDArray *tc = (TypeDArray *)tinfo; | |
584 | |
585 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfoarray); | |
586 } | |
587 | |
588 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) | |
589 { | |
590 assert(0); | |
591 } | |
592 | |
593 /* ========================================================================= */ | |
594 | |
595 void TypeInfoStaticArrayDeclaration::llvmDeclare() | |
596 { | |
597 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); | |
598 LOG_SCOPE; | |
599 | |
600 // init typeinfo class | |
601 ClassDeclaration* base = Type::typeinfostaticarray; | |
602 DtoResolveClass(base); | |
603 | |
604 // get type of typeinfo class | |
605 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
606 | |
607 // create the symbol | |
608 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
609 } | |
610 | |
611 void TypeInfoStaticArrayDeclaration::llvmDefine() | |
512 { | 612 { |
513 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); | 613 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); |
514 LOG_SCOPE; | 614 LOG_SCOPE; |
515 | 615 |
516 // init typeinfo class | 616 // init typeinfo class |
530 TypeSArray *tc = (TypeSArray *)tinfo; | 630 TypeSArray *tc = (TypeSArray *)tinfo; |
531 tc->next->getTypeInfo(NULL); | 631 tc->next->getTypeInfo(NULL); |
532 | 632 |
533 // get symbol | 633 // get symbol |
534 assert(tc->next->vtinfo); | 634 assert(tc->next->vtinfo); |
535 DtoForceConstInitDsymbol(tc->next->vtinfo); | 635 DtoForceDeclareDsymbol(tc->next->vtinfo); |
536 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); | 636 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); |
537 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); | 637 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
538 sinits.push_back(castbase); | 638 sinits.push_back(castbase); |
539 | 639 |
540 // length | 640 // length |
541 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); | 641 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); |
542 | 642 |
543 // create the symbol | 643 // create the symbol |
544 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 644 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
545 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); | 645 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
546 | 646 } |
547 llvmValue = gvar; | 647 |
548 } | 648 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) |
549 | 649 { |
550 /* ========================================================================= */ | 650 assert(0); |
651 } | |
652 | |
653 /* ========================================================================= */ | |
654 | |
655 void TypeInfoAssociativeArrayDeclaration::llvmDeclare() | |
656 { | |
657 assert(0 && "TypeInfoAssociativeArrayDeclaration"); | |
658 } | |
659 | |
660 void TypeInfoAssociativeArrayDeclaration::llvmDefine() | |
661 { | |
662 assert(0 && "TypeInfoAssociativeArrayDeclaration"); | |
663 } | |
551 | 664 |
552 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) | 665 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
553 { | 666 { |
554 assert(0 && "TypeInfoAssociativeArrayDeclaration"); | 667 assert(0 && "TypeInfoAssociativeArrayDeclaration"); |
555 | 668 |
570 */ | 683 */ |
571 } | 684 } |
572 | 685 |
573 /* ========================================================================= */ | 686 /* ========================================================================= */ |
574 | 687 |
575 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) | 688 void TypeInfoFunctionDeclaration::llvmDeclare() |
576 { | 689 { |
577 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); | 690 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
578 LOG_SCOPE; | 691 LOG_SCOPE; |
579 | 692 |
580 assert(tinfo->ty == Tfunction); | 693 assert(tinfo->ty == Tfunction); |
581 TypeFunction *tc = (TypeFunction *)tinfo; | 694 TypeFunction *tc = (TypeFunction *)tinfo; |
582 | 695 |
583 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfofunction); | 696 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfofunction); |
584 } | 697 } |
585 | 698 |
586 /* ========================================================================= */ | 699 void TypeInfoFunctionDeclaration::llvmDefine() |
587 | 700 { |
588 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) | 701 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
702 LOG_SCOPE; | |
703 | |
704 assert(tinfo->ty == Tfunction); | |
705 TypeFunction *tc = (TypeFunction *)tinfo; | |
706 | |
707 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfofunction); | |
708 } | |
709 | |
710 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) | |
711 { | |
712 assert(0); | |
713 } | |
714 | |
715 /* ========================================================================= */ | |
716 | |
717 void TypeInfoDelegateDeclaration::llvmDeclare() | |
589 { | 718 { |
590 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); | 719 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
591 LOG_SCOPE; | 720 LOG_SCOPE; |
592 | 721 |
593 assert(tinfo->ty == Tdelegate); | 722 assert(tinfo->ty == Tdelegate); |
594 TypeDelegate *tc = (TypeDelegate *)tinfo; | 723 TypeDelegate *tc = (TypeDelegate *)tinfo; |
595 | 724 |
596 LLVM_D_Create_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); | 725 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfodelegate); |
597 } | 726 } |
598 | 727 |
599 /* ========================================================================= */ | 728 void TypeInfoDelegateDeclaration::llvmDefine() |
600 | 729 { |
601 void TypeInfoStructDeclaration::toDt(dt_t **pdt) | 730 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
602 { | 731 LOG_SCOPE; |
603 Logger::println("TypeInfoStructDeclaration::toDt() %s", toChars()); | 732 |
733 assert(tinfo->ty == Tdelegate); | |
734 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
735 | |
736 LLVM_D_Define_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); | |
737 } | |
738 | |
739 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) | |
740 { | |
741 assert(0); | |
742 } | |
743 | |
744 /* ========================================================================= */ | |
745 | |
746 void TypeInfoStructDeclaration::llvmDeclare() | |
747 { | |
748 Logger::println("TypeInfoStructDeclaration::llvmDeclare() %s", toChars()); | |
749 LOG_SCOPE; | |
750 | |
751 assert(tinfo->ty == Tstruct); | |
752 TypeStruct *tc = (TypeStruct *)tinfo; | |
753 StructDeclaration *sd = tc->sym; | |
754 DtoResolveDsymbol(sd); | |
755 | |
756 ClassDeclaration* base = Type::typeinfostruct; | |
757 DtoResolveClass(base); | |
758 | |
759 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); | |
760 | |
761 // create the symbol | |
762 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
763 } | |
764 | |
765 void TypeInfoStructDeclaration::llvmDefine() | |
766 { | |
767 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); | |
604 LOG_SCOPE; | 768 LOG_SCOPE; |
605 | 769 |
606 assert(tinfo->ty == Tstruct); | 770 assert(tinfo->ty == Tstruct); |
607 TypeStruct *tc = (TypeStruct *)tinfo; | 771 TypeStruct *tc = (TypeStruct *)tinfo; |
608 StructDeclaration *sd = tc->sym; | 772 StructDeclaration *sd = tc->sym; |
762 | 926 |
763 // create the symbol | 927 // create the symbol |
764 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 928 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
765 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); | 929 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
766 | 930 |
767 llvmValue = gvar; | 931 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
768 } | 932 } |
769 | 933 |
770 /* ========================================================================= */ | 934 void TypeInfoStructDeclaration::toDt(dt_t **pdt) |
935 { | |
936 assert(0); | |
937 } | |
938 | |
939 /* ========================================================================= */ | |
940 | |
941 void TypeInfoClassDeclaration::llvmDeclare() | |
942 { | |
943 Logger::println("TypeInfoClassDeclaration::llvmDeclare() %s", toChars()); | |
944 LOG_SCOPE; | |
945 | |
946 // init typeinfo class | |
947 ClassDeclaration* base = Type::typeinfoclass; | |
948 assert(base); | |
949 DtoResolveClass(base); | |
950 | |
951 // get type of typeinfo class | |
952 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
953 | |
954 // create the symbol | |
955 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
956 } | |
957 | |
958 void TypeInfoClassDeclaration::llvmDefine() | |
959 { | |
960 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); | |
961 LOG_SCOPE; | |
962 | |
963 // init typeinfo class | |
964 ClassDeclaration* base = Type::typeinfoclass; | |
965 assert(base); | |
966 DtoForceConstInitDsymbol(base); | |
967 | |
968 // get type of typeinfo class | |
969 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
970 | |
971 // initializer vector | |
972 std::vector<llvm::Constant*> sinits; | |
973 // first is always the vtable | |
974 sinits.push_back(base->llvmVtbl); | |
975 | |
976 // get classinfo | |
977 assert(tinfo->ty == Tclass); | |
978 TypeClass *tc = (TypeClass *)tinfo; | |
979 assert(tc->sym->llvmClass); | |
980 sinits.push_back(tc->sym->llvmClass); | |
981 | |
982 // create the symbol | |
983 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
984 isaGlobalVar(llvmValue)->setInitializer(tiInit); | |
985 } | |
771 | 986 |
772 void TypeInfoClassDeclaration::toDt(dt_t **pdt) | 987 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |
773 { | 988 { |
774 assert(0 && "TypeInfoClassDeclaration"); | 989 assert(0); |
990 } | |
991 | |
992 /* ========================================================================= */ | |
993 | |
994 void TypeInfoInterfaceDeclaration::llvmDeclare() | |
995 { | |
996 assert(0 && "TypeInfoTupleDeclaration"); | |
997 } | |
998 | |
999 void TypeInfoInterfaceDeclaration::llvmDefine() | |
1000 { | |
1001 assert(0 && "TypeInfoTupleDeclaration"); | |
1002 } | |
1003 | |
1004 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) | |
1005 { | |
1006 assert(0 && "TypeInfoInterfaceDeclaration"); | |
775 | 1007 |
776 /* | 1008 /* |
777 //printf("TypeInfoClassDeclaration::toDt() %s\n", tinfo->toChars()); | 1009 //printf("TypeInfoInterfaceDeclaration::toDt() %s\n", tinfo->toChars()); |
778 dtxoff(pdt, Type::typeinfoclass->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoClass | 1010 dtxoff(pdt, Type::typeinfointerface->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface |
779 dtdword(pdt, 0); // monitor | 1011 dtdword(pdt, 0); // monitor |
780 | 1012 |
781 assert(tinfo->ty == Tclass); | 1013 assert(tinfo->ty == Tclass); |
782 | 1014 |
783 TypeClass *tc = (TypeClass *)tinfo; | 1015 TypeClass *tc = (TypeClass *)tinfo; |
790 */ | 1022 */ |
791 } | 1023 } |
792 | 1024 |
793 /* ========================================================================= */ | 1025 /* ========================================================================= */ |
794 | 1026 |
795 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) | 1027 void TypeInfoTupleDeclaration::llvmDeclare() |
796 { | 1028 { |
797 assert(0 && "TypeInfoInterfaceDeclaration"); | 1029 assert(0 && "TypeInfoTupleDeclaration"); |
798 | 1030 } |
799 /* | 1031 |
800 //printf("TypeInfoInterfaceDeclaration::toDt() %s\n", tinfo->toChars()); | 1032 void TypeInfoTupleDeclaration::llvmDefine() |
801 dtxoff(pdt, Type::typeinfointerface->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface | 1033 { |
802 dtdword(pdt, 0); // monitor | 1034 assert(0 && "TypeInfoTupleDeclaration"); |
803 | 1035 } |
804 assert(tinfo->ty == Tclass); | |
805 | |
806 TypeClass *tc = (TypeClass *)tinfo; | |
807 Symbol *s; | |
808 | |
809 if (!tc->sym->vclassinfo) | |
810 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym); | |
811 s = tc->sym->vclassinfo->toSymbol(); | |
812 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo | |
813 */ | |
814 } | |
815 | |
816 /* ========================================================================= */ | |
817 | 1036 |
818 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) | 1037 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
819 { | 1038 { |
820 assert(0 && "TypeInfoTupleDeclaration"); | 1039 assert(0 && "TypeInfoTupleDeclaration"); |
821 | 1040 |