comparison gen/typinf.c @ 58:2c3cd3596187 trunk

[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum Added initial support for CatExp aka 'a ~ b' Fixed global constant static arrays initialized with string literals Fixed casting any dynamic array to void* Fixed new expression with temporary storage Fixed alias declarations in function scope Fixed relational comparisons of pointers
author lindquist
date Thu, 25 Oct 2007 09:02:55 +0200
parents a9d29e9f1fed
children d4a678905d5e
comparison
equal deleted inserted replaced
57:a9d29e9f1fed 58:2c3cd3596187
244 LOG_SCOPE; 244 LOG_SCOPE;
245 Logger::println("type = '%s'", tinfo->toChars()); 245 Logger::println("type = '%s'", tinfo->toChars());
246 246
247 Logger::println("typeinfo mangle: %s", mangle()); 247 Logger::println("typeinfo mangle: %s", mangle());
248 248
249 // this is a declaration of a builtin __initZ var
249 if (tinfo->builtinTypeInfo()) { 250 if (tinfo->builtinTypeInfo()) {
250 // this is a declaration of a builtin __initZ var
251 llvmValue = LLVM_D_GetRuntimeGlobal(gIR->module, mangle()); 251 llvmValue = LLVM_D_GetRuntimeGlobal(gIR->module, mangle());
252 assert(llvmValue); 252 assert(llvmValue);
253 Logger::cout() << "Got typeinfo var:" << '\n' << *llvmValue << '\n'; 253 Logger::cout() << "Got typeinfo var:" << '\n' << *llvmValue << '\n';
254 } 254 }
255 // custom typedef
255 else { 256 else {
256 toDt(NULL); 257 toDt(NULL);
257 // this is a specialized typeinfo 258 // this is a specialized typeinfo
258 //std::vector<const llvm::Type*> stypes; 259 //std::vector<const llvm::Type*> stypes;
259 //stypes.push_back( 260 //stypes.push_back(
263 /* ========================================================================= */ 264 /* ========================================================================= */
264 265
265 void TypeInfoDeclaration::toDt(dt_t **pdt) 266 void TypeInfoDeclaration::toDt(dt_t **pdt)
266 { 267 {
267 assert(0 && "TypeInfoDeclaration"); 268 assert(0 && "TypeInfoDeclaration");
268 } 269
270 /*
271 //printf("TypeInfoDeclaration::toDt() %s\n", toChars());
272 dtxoff(pdt, Type::typeinfo->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo
273 dtdword(pdt, 0); // monitor
274 */
275 }
276
277 /* ========================================================================= */
269 278
270 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) 279 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt)
271 { 280 {
272 Logger::println("TypeInfoTypedefDeclaration::toDt() %s", toChars()); 281 Logger::println("TypeInfoTypedefDeclaration::toDt() %s", toChars());
273 LOG_SCOPE; 282 LOG_SCOPE;
352 dtdword(pdt, sd->type->size()); // init.length 361 dtdword(pdt, sd->type->size()); // init.length
353 dtxoff(pdt, sd->toInitializer(), 0, TYnptr); // init.ptr 362 dtxoff(pdt, sd->toInitializer(), 0, TYnptr); // init.ptr
354 */ 363 */
355 } 364 }
356 365
366 /* ========================================================================= */
367
357 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) 368 void TypeInfoEnumDeclaration::toDt(dt_t **pdt)
358 { 369 {
359 assert(0 && "TypeInfoEnumDeclaration"); 370 Logger::println("TypeInfoTypedefDeclaration::toDt() %s", toChars());
360 } 371 LOG_SCOPE;
361 372
362 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) 373 ClassDeclaration* base = Type::typeinfoenum;
363 { 374 base->toObjFile();
364 assert(0 && "TypeInfoPointerDeclaration"); 375
365 } 376 llvm::Constant* initZ = base->llvmInitZ;
366 377 assert(initZ);
367 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) 378 const llvm::StructType* stype = llvm::cast<llvm::StructType>(initZ->getType());
368 { 379
369 assert(0 && "TypeInfoArrayDeclaration"); 380 std::vector<llvm::Constant*> sinits;
370 } 381 sinits.push_back(initZ->getOperand(0));
371 382
372 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) 383 assert(tinfo->ty == Tenum);
373 { 384 TypeEnum *tc = (TypeEnum *)tinfo;
374 assert(0 && "TypeInfoStaticArrayDeclaration"); 385 EnumDeclaration *sd = tc->sym;
375 } 386
376 387 // TypeInfo base
377 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) 388 //const llvm::PointerType* basept = llvm::cast<llvm::PointerType>(initZ->getOperand(1)->getType());
378 { 389 //sinits.push_back(llvm::ConstantPointerNull::get(basept));
379 assert(0 && "TypeInfoAssociativeArrayDeclaration"); 390 Logger::println("generating base typeinfo");
380 } 391 //sd->basetype = sd->basetype->merge();
381 392 sd->memtype->getTypeInfo(NULL); // generate vtinfo
382 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) 393 assert(sd->memtype->vtinfo);
383 { 394 if (!sd->memtype->vtinfo->llvmValue)
384 assert(0 && "TypeInfoFunctionDeclaration"); 395 sd->memtype->vtinfo->toObjFile();
385 } 396 assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->llvmValue));
386 397 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->llvmValue);
387 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) 398 castbase = llvm::ConstantExpr::getBitCast(castbase, initZ->getOperand(1)->getType());
388 { 399 sinits.push_back(castbase);
389 assert(0 && "TypeInfoDelegateDeclaration"); 400
390 } 401 // char[] name
391
392 void TypeInfoStructDeclaration::toDt(dt_t **pdt)
393 {
394 assert(0 && "TypeInfoStructDeclaration");
395 }
396
397 void TypeInfoClassDeclaration::toDt(dt_t **pdt)
398 {
399 assert(0 && "TypeInfoClassDeclaration");
400 }
401
402 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt)
403 {
404 assert(0 && "TypeInfoInterfaceDeclaration");
405 }
406
407 void TypeInfoTupleDeclaration::toDt(dt_t **pdt)
408 {
409 assert(0 && "TypeInfoTupleDeclaration");
410 }
411
412 // original dmdfe toDt code for reference
413
414 #if 0
415
416 void TypeInfoDeclaration::toDt(dt_t **pdt)
417 {
418 //printf("TypeInfoDeclaration::toDt() %s\n", toChars());
419 dtxoff(pdt, Type::typeinfo->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo
420 dtdword(pdt, 0); // monitor
421 }
422
423 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt)
424 {
425 //printf("TypeInfoTypedefDeclaration::toDt() %s\n", toChars());
426
427 dtxoff(pdt, Type::typeinfotypedef->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Typedef
428 dtdword(pdt, 0); // monitor
429
430 assert(tinfo->ty == Ttypedef);
431
432 TypeTypedef *tc = (TypeTypedef *)tinfo;
433 TypedefDeclaration *sd = tc->sym;
434 //printf("basetype = %s\n", sd->basetype->toChars());
435
436 /* Put out:
437 * TypeInfo base;
438 * char[] name;
439 * void[] m_init;
440 */
441
442 sd->basetype = sd->basetype->merge();
443 sd->basetype->getTypeInfo(NULL); // generate vtinfo
444 assert(sd->basetype->vtinfo);
445 dtxoff(pdt, sd->basetype->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for basetype
446
447 char *name = sd->toPrettyChars(); 402 char *name = sd->toPrettyChars();
448 size_t namelen = strlen(name); 403 sinits.push_back(LLVM_DtoConstString(name));
449 dtdword(pdt, namelen); 404 assert(sinits.back()->getType() == initZ->getOperand(2)->getType());
450 dtabytes(pdt, TYnptr, 0, namelen + 1, name); 405
451 406 // void[] init
452 // void[] init; 407 //const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty);
453 if (tinfo->isZeroInit() || !sd->init) 408 //sinits.push_back(LLVM_DtoConstantSlice(LLVM_DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
454 { // 0 initializer, or the same as the base type 409 sinits.push_back(initZ->getOperand(3));
455 dtdword(pdt, 0); // init.length 410
456 dtdword(pdt, 0); // init.ptr 411 // create the symbol
457 } 412 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
458 else 413 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::InternalLinkage,tiInit,toChars(),gIR->module);
459 { 414
460 dtdword(pdt, sd->type->size()); // init.length 415 llvmValue = gvar;
461 dtxoff(pdt, sd->toInitializer(), 0, TYnptr); // init.ptr 416
462 } 417 /*
463 } 418
464
465 void TypeInfoEnumDeclaration::toDt(dt_t **pdt)
466 {
467 //printf("TypeInfoEnumDeclaration::toDt()\n"); 419 //printf("TypeInfoEnumDeclaration::toDt()\n");
468 dtxoff(pdt, Type::typeinfoenum->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Enum 420 dtxoff(pdt, Type::typeinfoenum->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Enum
469 dtdword(pdt, 0); // monitor 421 dtdword(pdt, 0); // monitor
470 422
471 assert(tinfo->ty == Tenum); 423 assert(tinfo->ty == Tenum);
472 424
473 TypeEnum *tc = (TypeEnum *)tinfo; 425 TypeEnum *tc = (TypeEnum *)tinfo;
474 EnumDeclaration *sd = tc->sym; 426 EnumDeclaration *sd = tc->sym;
475 427
476 /* Put out: 428 // Put out:
477 * TypeInfo base; 429 // TypeInfo base;
478 * char[] name; 430 // char[] name;
479 * void[] m_init; 431 // void[] m_init;
480 */
481 432
482 sd->memtype->getTypeInfo(NULL); 433 sd->memtype->getTypeInfo(NULL);
483 dtxoff(pdt, sd->memtype->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for enum members 434 dtxoff(pdt, sd->memtype->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for enum members
484 435
485 char *name = sd->toPrettyChars(); 436 char *name = sd->toPrettyChars();
496 else 447 else
497 { 448 {
498 dtdword(pdt, sd->type->size()); // init.length 449 dtdword(pdt, sd->type->size()); // init.length
499 dtxoff(pdt, sd->toInitializer(), 0, TYnptr); // init.ptr 450 dtxoff(pdt, sd->toInitializer(), 0, TYnptr); // init.ptr
500 } 451 }
501 } 452
453 */
454 }
455
456 /* ========================================================================= */
457
458 static llvm::Constant* LLVM_D_Create_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd)
459 {
460 ClassDeclaration* base = cd;
461 base->toObjFile();
462
463 llvm::Constant* initZ = base->llvmInitZ;
464 assert(initZ);
465 const llvm::StructType* stype = llvm::cast<llvm::StructType>(initZ->getType());
466
467 std::vector<llvm::Constant*> sinits;
468 sinits.push_back(initZ->getOperand(0));
469
470 // TypeInfo base
471 Logger::println("generating base typeinfo");
472 basetype->getTypeInfo(NULL);
473 assert(basetype->vtinfo);
474 if (!basetype->vtinfo->llvmValue)
475 basetype->vtinfo->toObjFile();
476 assert(llvm::isa<llvm::Constant>(basetype->vtinfo->llvmValue));
477 llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->llvmValue);
478 castbase = llvm::ConstantExpr::getBitCast(castbase, initZ->getOperand(1)->getType());
479 sinits.push_back(castbase);
480
481 // create the symbol
482 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
483 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::InternalLinkage,tiInit,tid->toChars(),gIR->module);
484
485 tid->llvmValue = gvar;
486 }
487
488 /* ========================================================================= */
502 489
503 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) 490 void TypeInfoPointerDeclaration::toDt(dt_t **pdt)
504 { 491 {
505 //printf("TypeInfoPointerDeclaration::toDt()\n"); 492 Logger::println("TypeInfoPointerDeclaration::toDt() %s", toChars());
506 dtxoff(pdt, Type::typeinfopointer->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Pointer 493 LOG_SCOPE;
507 dtdword(pdt, 0); // monitor
508 494
509 assert(tinfo->ty == Tpointer); 495 assert(tinfo->ty == Tpointer);
510
511 TypePointer *tc = (TypePointer *)tinfo; 496 TypePointer *tc = (TypePointer *)tinfo;
512 497
513 tc->next->getTypeInfo(NULL); 498 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfopointer);
514 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for type being pointed to 499 }
515 } 500
501 /* ========================================================================= */
516 502
517 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) 503 void TypeInfoArrayDeclaration::toDt(dt_t **pdt)
518 { 504 {
519 //printf("TypeInfoArrayDeclaration::toDt()\n"); 505 Logger::println("TypeInfoArrayDeclaration::toDt() %s", toChars());
520 dtxoff(pdt, Type::typeinfoarray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Array 506 LOG_SCOPE;
521 dtdword(pdt, 0); // monitor
522 507
523 assert(tinfo->ty == Tarray); 508 assert(tinfo->ty == Tarray);
524
525 TypeDArray *tc = (TypeDArray *)tinfo; 509 TypeDArray *tc = (TypeDArray *)tinfo;
526 510
527 tc->next->getTypeInfo(NULL); 511 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfoarray);
528 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type 512 }
529 } 513
514 /* ========================================================================= */
530 515
531 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) 516 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt)
532 { 517 {
518 assert(0 && "TypeInfoStaticArrayDeclaration");
519
520 /*
533 //printf("TypeInfoStaticArrayDeclaration::toDt()\n"); 521 //printf("TypeInfoStaticArrayDeclaration::toDt()\n");
534 dtxoff(pdt, Type::typeinfostaticarray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_StaticArray 522 dtxoff(pdt, Type::typeinfostaticarray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_StaticArray
535 dtdword(pdt, 0); // monitor 523 dtdword(pdt, 0); // monitor
536 524
537 assert(tinfo->ty == Tsarray); 525 assert(tinfo->ty == Tsarray);
540 528
541 tc->next->getTypeInfo(NULL); 529 tc->next->getTypeInfo(NULL);
542 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type 530 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type
543 531
544 dtdword(pdt, tc->dim->toInteger()); // length 532 dtdword(pdt, tc->dim->toInteger()); // length
545 } 533 */
534 }
535
536 /* ========================================================================= */
546 537
547 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) 538 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt)
548 { 539 {
540 assert(0 && "TypeInfoAssociativeArrayDeclaration");
541
542 /*
549 //printf("TypeInfoAssociativeArrayDeclaration::toDt()\n"); 543 //printf("TypeInfoAssociativeArrayDeclaration::toDt()\n");
550 dtxoff(pdt, Type::typeinfoassociativearray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray 544 dtxoff(pdt, Type::typeinfoassociativearray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray
551 dtdword(pdt, 0); // monitor 545 dtdword(pdt, 0); // monitor
552 546
553 assert(tinfo->ty == Taarray); 547 assert(tinfo->ty == Taarray);
557 tc->next->getTypeInfo(NULL); 551 tc->next->getTypeInfo(NULL);
558 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type 552 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type
559 553
560 tc->index->getTypeInfo(NULL); 554 tc->index->getTypeInfo(NULL);
561 dtxoff(pdt, tc->index->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type 555 dtxoff(pdt, tc->index->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type
562 } 556 */
557 }
558
559 /* ========================================================================= */
563 560
564 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) 561 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt)
565 { 562 {
566 //printf("TypeInfoFunctionDeclaration::toDt()\n"); 563 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars());
567 dtxoff(pdt, Type::typeinfofunction->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Function 564 LOG_SCOPE;
568 dtdword(pdt, 0); // monitor
569 565
570 assert(tinfo->ty == Tfunction); 566 assert(tinfo->ty == Tfunction);
571
572 TypeFunction *tc = (TypeFunction *)tinfo; 567 TypeFunction *tc = (TypeFunction *)tinfo;
573 568
574 tc->next->getTypeInfo(NULL); 569 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfofunction);
575 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for function return value 570 }
576 } 571
572 /* ========================================================================= */
577 573
578 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) 574 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt)
579 { 575 {
580 //printf("TypeInfoDelegateDeclaration::toDt()\n"); 576 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars());
581 dtxoff(pdt, Type::typeinfodelegate->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Delegate 577 LOG_SCOPE;
582 dtdword(pdt, 0); // monitor
583 578
584 assert(tinfo->ty == Tdelegate); 579 assert(tinfo->ty == Tdelegate);
585
586 TypeDelegate *tc = (TypeDelegate *)tinfo; 580 TypeDelegate *tc = (TypeDelegate *)tinfo;
587 581
588 tc->next->next->getTypeInfo(NULL); 582 LLVM_D_Create_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate);
589 dtxoff(pdt, tc->next->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for delegate return value 583 }
590 } 584
585 /* ========================================================================= */
591 586
592 void TypeInfoStructDeclaration::toDt(dt_t **pdt) 587 void TypeInfoStructDeclaration::toDt(dt_t **pdt)
593 { 588 {
589 assert(0 && "TypeInfoStructDeclaration");
590
591 /*
594 //printf("TypeInfoStructDeclaration::toDt() '%s'\n", toChars()); 592 //printf("TypeInfoStructDeclaration::toDt() '%s'\n", toChars());
595 593
596 unsigned offset = Type::typeinfostruct->structsize; 594 unsigned offset = Type::typeinfostruct->structsize;
597 595
598 dtxoff(pdt, Type::typeinfostruct->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Struct 596 dtxoff(pdt, Type::typeinfostruct->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Struct
601 assert(tinfo->ty == Tstruct); 599 assert(tinfo->ty == Tstruct);
602 600
603 TypeStruct *tc = (TypeStruct *)tinfo; 601 TypeStruct *tc = (TypeStruct *)tinfo;
604 StructDeclaration *sd = tc->sym; 602 StructDeclaration *sd = tc->sym;
605 603
606 /* Put out: 604 // Put out:
607 * char[] name; 605 // char[] name;
608 * void[] init; 606 // void[] init;
609 * hash_t function(void*) xtoHash; 607 // hash_t function(void*) xtoHash;
610 * int function(void*,void*) xopEquals; 608 // int function(void*,void*) xopEquals;
611 * int function(void*,void*) xopCmp; 609 // int function(void*,void*) xopCmp;
612 * char[] function(void*) xtoString; 610 // char[] function(void*) xtoString;
613 * uint m_flags; 611 // uint m_flags;
614 * 612 //
615 * name[] 613 // name[]
616 */ 614 //
617 615
618 char *name = sd->toPrettyChars(); 616 char *name = sd->toPrettyChars();
619 size_t namelen = strlen(name); 617 size_t namelen = strlen(name);
620 dtdword(pdt, namelen); 618 dtdword(pdt, namelen);
621 //dtabytes(pdt, TYnptr, 0, namelen + 1, name); 619 //dtabytes(pdt, TYnptr, 0, namelen + 1, name);
721 // uint m_flags; 719 // uint m_flags;
722 dtdword(pdt, tc->hasPointers()); 720 dtdword(pdt, tc->hasPointers());
723 721
724 // name[] 722 // name[]
725 dtnbytes(pdt, namelen + 1, name); 723 dtnbytes(pdt, namelen + 1, name);
726 } 724 */
725 }
726
727 /* ========================================================================= */
727 728
728 void TypeInfoClassDeclaration::toDt(dt_t **pdt) 729 void TypeInfoClassDeclaration::toDt(dt_t **pdt)
729 { 730 {
731 assert(0 && "TypeInfoClassDeclaration");
732
733 /*
730 //printf("TypeInfoClassDeclaration::toDt() %s\n", tinfo->toChars()); 734 //printf("TypeInfoClassDeclaration::toDt() %s\n", tinfo->toChars());
731 dtxoff(pdt, Type::typeinfoclass->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoClass 735 dtxoff(pdt, Type::typeinfoclass->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoClass
732 dtdword(pdt, 0); // monitor 736 dtdword(pdt, 0); // monitor
733 737
734 assert(tinfo->ty == Tclass); 738 assert(tinfo->ty == Tclass);
738 742
739 if (!tc->sym->vclassinfo) 743 if (!tc->sym->vclassinfo)
740 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym); 744 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym);
741 s = tc->sym->vclassinfo->toSymbol(); 745 s = tc->sym->vclassinfo->toSymbol();
742 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo 746 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo
743 } 747 */
748 }
749
750 /* ========================================================================= */
744 751
745 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) 752 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt)
746 { 753 {
754 assert(0 && "TypeInfoInterfaceDeclaration");
755
756 /*
747 //printf("TypeInfoInterfaceDeclaration::toDt() %s\n", tinfo->toChars()); 757 //printf("TypeInfoInterfaceDeclaration::toDt() %s\n", tinfo->toChars());
748 dtxoff(pdt, Type::typeinfointerface->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface 758 dtxoff(pdt, Type::typeinfointerface->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface
749 dtdword(pdt, 0); // monitor 759 dtdword(pdt, 0); // monitor
750 760
751 assert(tinfo->ty == Tclass); 761 assert(tinfo->ty == Tclass);
755 765
756 if (!tc->sym->vclassinfo) 766 if (!tc->sym->vclassinfo)
757 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym); 767 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym);
758 s = tc->sym->vclassinfo->toSymbol(); 768 s = tc->sym->vclassinfo->toSymbol();
759 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo 769 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo
760 } 770 */
771 }
772
773 /* ========================================================================= */
761 774
762 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) 775 void TypeInfoTupleDeclaration::toDt(dt_t **pdt)
763 { 776 {
777 assert(0 && "TypeInfoTupleDeclaration");
778
779 /*
764 //printf("TypeInfoTupleDeclaration::toDt() %s\n", tinfo->toChars()); 780 //printf("TypeInfoTupleDeclaration::toDt() %s\n", tinfo->toChars());
765 dtxoff(pdt, Type::typeinfotypelist->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface 781 dtxoff(pdt, Type::typeinfotypelist->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface
766 dtdword(pdt, 0); // monitor 782 dtdword(pdt, 0); // monitor
767 783
768 assert(tinfo->ty == Ttuple); 784 assert(tinfo->ty == Ttuple);
784 s = static_sym(); 800 s = static_sym();
785 s->Sdt = d; 801 s->Sdt = d;
786 outdata(s); 802 outdata(s);
787 803
788 dtxoff(pdt, s, 0, TYnptr); // elements.ptr 804 dtxoff(pdt, s, 0, TYnptr); // elements.ptr
789 } 805 */
790 806 }
791 void TypeInfoDeclaration::toObjFile()
792 {
793 Symbol *s;
794 unsigned sz;
795 Dsymbol *parent;
796
797 //printf("TypeInfoDeclaration::toObjFile(%p '%s') protection %d\n", this, toChars(), protection);
798
799 s = toSymbol();
800 sz = type->size();
801
802 parent = this->toParent();
803 s->Sclass = SCcomdat;
804 s->Sfl = FLdata;
805
806 toDt(&s->Sdt);
807
808 dt_optimize(s->Sdt);
809
810 // See if we can convert a comdat to a comdef,
811 // which saves on exe file space.
812 if (s->Sclass == SCcomdat &&
813 s->Sdt->dt == DT_azeros &&
814 s->Sdt->DTnext == NULL)
815 {
816 s->Sclass = SCglobal;
817 s->Sdt->dt = DT_common;
818 }
819
820 #if ELFOBJ // Burton
821 if (s->Sdt && s->Sdt->dt == DT_azeros && s->Sdt->DTnext == NULL)
822 s->Sseg = UDATA;
823 else
824 s->Sseg = DATA;
825 #endif /* ELFOBJ */
826 outdata(s);
827 if (isExport())
828 obj_export(s,0);
829 }
830
831 #endif