Mercurial > projects > ldc
comparison gen/toobj.c @ 28:1c80c18f3c82 trunk
[svn r32] * Fixed problems with arrays members of aggregates
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 12:49:37 +0200 |
parents | 99737f94abfb |
children | 2841234d2aea |
comparison
equal
deleted
inserted
replaced
27:92408a3a2bac | 28:1c80c18f3c82 |
---|---|
572 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); | 572 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); |
573 | 573 |
574 const llvm::Type* _type = LLVM_DtoType(type); | 574 const llvm::Type* _type = LLVM_DtoType(type); |
575 gIR->topstruct().fields.push_back(_type); | 575 gIR->topstruct().fields.push_back(_type); |
576 | 576 |
577 llvm::Constant* _init = LLVM_DtoInitializer(type, init); | 577 llvm::Constant*_init = LLVM_DtoInitializer(type, init); |
578 if (_type != _init->getType()) | 578 assert(_init); |
579 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n'; | |
580 if (!_init || _type != _init->getType()) | |
579 { | 581 { |
580 if (llvm::isa<llvm::ArrayType>(_type)) | 582 if (type->ty == Tsarray) |
581 { | 583 { |
582 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(_type); | 584 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(_type); |
583 uint64_t n = arrty->getNumElements(); | 585 uint64_t n = arrty->getNumElements(); |
584 std::vector<llvm::Constant*> vals(n,_init); | 586 std::vector<llvm::Constant*> vals(n,_init); |
585 _init = llvm::ConstantArray::get(arrty, vals); | 587 _init = llvm::ConstantArray::get(arrty, vals); |
586 } | 588 } |
587 else if (llvm::isa<llvm::StructType>(_type)) { | 589 else if (type->ty == Tarray) |
590 { | |
591 assert(llvm::isa<llvm::StructType>(_type)); | |
592 _init = llvm::ConstantAggregateZero::get(_type); | |
593 } | |
594 else if (type->ty == Tstruct) | |
595 { | |
588 const llvm::StructType* structty = llvm::cast<llvm::StructType>(_type); | 596 const llvm::StructType* structty = llvm::cast<llvm::StructType>(_type); |
589 TypeStruct* ts = (TypeStruct*)type; | 597 TypeStruct* ts = (TypeStruct*)type; |
590 assert(ts); | 598 assert(ts); |
591 assert(ts->sym); | 599 assert(ts->sym); |
592 assert(ts->sym->llvmInitZ); | 600 assert(ts->sym->llvmInitZ); |
593 _init = ts->sym->llvmInitZ; | 601 _init = ts->sym->llvmInitZ; |
594 } | 602 } |
595 else | 603 else if (type->ty == Tclass) |
596 assert(0); | 604 { |
605 _init = llvm::Constant::getNullValue(_type); | |
606 } | |
607 else { | |
608 Logger::println("failed for type %s", type->toChars()); | |
609 assert(0); | |
610 } | |
597 } | 611 } |
598 gIR->topstruct().inits.push_back(_init); | 612 gIR->topstruct().inits.push_back(_init); |
599 } | 613 } |
600 | 614 |
601 Logger::println("VarDeclaration::toObjFile is done"); | 615 Logger::println("VarDeclaration::toObjFile is done"); |