Mercurial > projects > ldc
comparison gen/structs.cpp @ 1148:3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Fri, 27 Mar 2009 21:50:32 +0100 |
parents | dbe4af57b240 |
children | 5ebe8224988b |
comparison
equal
deleted
inserted
replaced
1147:dbe4af57b240 | 1148:3d1b16dabd25 |
---|---|
95 // get TypeStruct | 95 // get TypeStruct |
96 assert(si->ad); | 96 assert(si->ad); |
97 TypeStruct* ts = (TypeStruct*)si->ad->type; | 97 TypeStruct* ts = (TypeStruct*)si->ad->type; |
98 | 98 |
99 // force constant initialization of the symbol | 99 // force constant initialization of the symbol |
100 DtoForceConstInitDsymbol(si->ad); | 100 si->ad->codegen(Type::sir);; |
101 | 101 |
102 // get formal type | 102 // get formal type |
103 const llvm::StructType* structtype = isaStruct(ts->ir.type->get()); | 103 const llvm::StructType* structtype = isaStruct(ts->ir.type->get()); |
104 | 104 |
105 #if 0 | 105 #if 0 |
515 sd->ir.irStruct = irstruct; | 515 sd->ir.irStruct = irstruct; |
516 | 516 |
517 // create the type | 517 // create the type |
518 ts->ir.type = new LLPATypeHolder(llvm::OpaqueType::get()); | 518 ts->ir.type = new LLPATypeHolder(llvm::OpaqueType::get()); |
519 | 519 |
520 // create symbols we're going to need | |
521 // avoids chicken egg problems | |
522 std::string initname("_D"); | |
523 initname.append(sd->mangle()); | |
524 initname.append("6__initZ"); | |
525 | |
526 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd); | |
527 sd->ir.irStruct->init = new llvm::GlobalVariable(sd->ir.irStruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module); | |
528 | |
520 // handle forward declaration structs (opaques) | 529 // handle forward declaration structs (opaques) |
521 // didn't even know D had those ... | 530 // didn't even know D had those ... |
522 if (sd->sizeok != 1) | 531 if (sd->sizeok != 1) |
523 { | 532 { |
524 // nothing more to do | 533 // nothing more to do |
577 gIR->module->addTypeName(sd->mangle(),ST); | 586 gIR->module->addTypeName(sd->mangle(),ST); |
578 } | 587 } |
579 | 588 |
580 gIR->structs.pop_back(); | 589 gIR->structs.pop_back(); |
581 | 590 |
582 gIR->declareList.push_back(sd); | 591 DtoDeclareStruct(sd); |
583 } | 592 } |
584 | 593 |
585 ////////////////////////////////////////////////////////////////////////////////////////// | 594 ////////////////////////////////////////////////////////////////////////////////////////// |
586 | 595 |
587 void DtoDeclareStruct(StructDeclaration* sd) | 596 void DtoDeclareStruct(StructDeclaration* sd) |
588 { | 597 { |
598 DtoResolveStruct(sd); | |
599 | |
589 if (sd->ir.declared) return; | 600 if (sd->ir.declared) return; |
590 sd->ir.declared = true; | 601 sd->ir.declared = true; |
591 | 602 |
592 Logger::println("DtoDeclareStruct(%s): %s", sd->toChars(), sd->loc.toChars()); | 603 Logger::println("DtoDeclareStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
593 LOG_SCOPE; | 604 LOG_SCOPE; |
594 | 605 |
595 TypeStruct* ts = (TypeStruct*)sd->type->toBasetype(); | 606 TypeStruct* ts = (TypeStruct*)sd->type->toBasetype(); |
596 | 607 |
597 std::string initname("_D"); | 608 DtoConstInitStruct(sd); |
598 initname.append(sd->mangle()); | |
599 initname.append("6__initZ"); | |
600 | |
601 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd); | |
602 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(sd->ir.irStruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module); | |
603 sd->ir.irStruct->init = initvar; | |
604 | |
605 gIR->constInitList.push_back(sd); | |
606 if (mustDefineSymbol(sd)) | 609 if (mustDefineSymbol(sd)) |
607 gIR->defineList.push_back(sd); | 610 DtoDefineStruct(sd); |
608 } | 611 } |
609 | 612 |
610 ////////////////////////////////////////////////////////////////////////////////////////// | 613 ////////////////////////////////////////////////////////////////////////////////////////// |
611 | 614 |
612 void DtoConstInitStruct(StructDeclaration* sd) | 615 void DtoConstInitStruct(StructDeclaration* sd) |
613 { | 616 { |
617 DtoDeclareStruct(sd); | |
618 | |
614 if (sd->ir.initialized) return; | 619 if (sd->ir.initialized) return; |
615 sd->ir.initialized = true; | 620 sd->ir.initialized = true; |
616 | 621 |
617 Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars()); | 622 Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
618 LOG_SCOPE; | 623 LOG_SCOPE; |
649 | 654 |
650 ////////////////////////////////////////////////////////////////////////////////////////// | 655 ////////////////////////////////////////////////////////////////////////////////////////// |
651 | 656 |
652 void DtoDefineStruct(StructDeclaration* sd) | 657 void DtoDefineStruct(StructDeclaration* sd) |
653 { | 658 { |
659 DtoConstInitStruct(sd); | |
660 | |
654 if (sd->ir.defined) return; | 661 if (sd->ir.defined) return; |
655 sd->ir.defined = true; | 662 sd->ir.defined = true; |
656 | 663 |
657 Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars()); | 664 Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
658 LOG_SCOPE; | 665 LOG_SCOPE; |