Mercurial > projects > ldc
comparison gen/typinf.cpp @ 1376:a5d0e04298a8
Cleaned up TypeInfo_Tuple generation.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Sun, 17 May 2009 05:07:51 +0200 |
parents | 63f4afd01036 |
children | a0a4d4dac1a4 |
comparison
equal
deleted
inserted
replaced
1375:63f4afd01036 | 1376:a5d0e04298a8 |
---|---|
705 void TypeInfoTupleDeclaration::llvmDefine() | 705 void TypeInfoTupleDeclaration::llvmDefine() |
706 { | 706 { |
707 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars()); | 707 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars()); |
708 LOG_SCOPE; | 708 LOG_SCOPE; |
709 | 709 |
710 // init typeinfo class | |
711 ClassDeclaration* base = Type::typeinfotypelist; | |
712 assert(base); | |
713 base->codegen(Type::sir); | |
714 | |
715 // get type of typeinfo class | |
716 const LLStructType* stype = isaStruct(base->type->irtype->getPA()); | |
717 | |
718 // initializer vector | |
719 std::vector<LLConstant*> sinits; | |
720 // first is always the vtable | |
721 sinits.push_back(base->ir.irStruct->getVtblSymbol()); | |
722 | |
723 // monitor | |
724 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); | |
725 | |
726 // create elements array | 710 // create elements array |
727 assert(tinfo->ty == Ttuple); | 711 assert(tinfo->ty == Ttuple); |
728 TypeTuple *tu = (TypeTuple *)tinfo; | 712 TypeTuple *tu = (TypeTuple *)tinfo; |
729 | 713 |
730 size_t dim = tu->arguments->dim; | 714 size_t dim = tu->arguments->dim; |
731 std::vector<LLConstant*> arrInits; | 715 std::vector<LLConstant*> arrInits; |
732 | 716 arrInits.reserve(dim); |
733 const LLType* tiTy = Type::typeinfo->type->irtype->getPA(); | 717 |
734 tiTy = getPtrToType(tiTy); | 718 const LLType* tiTy = DtoType(Type::typeinfo->type); |
735 | 719 |
736 for (size_t i = 0; i < dim; i++) | 720 for (size_t i = 0; i < dim; i++) |
737 { | 721 { |
738 Argument *arg = (Argument *)tu->arguments->data[i]; | 722 Argument *arg = (Argument *)tu->arguments->data[i]; |
739 LLConstant* castbase = DtoTypeInfoOf(arg->type, true); | 723 arrInits.push_back(DtoTypeInfoOf(arg->type, true)); |
740 assert(castbase->getType() == tiTy); | 724 } |
741 arrInits.push_back(castbase); | 725 |
742 } | 726 // build array |
743 | |
744 // build array type | |
745 const LLArrayType* arrTy = LLArrayType::get(tiTy, dim); | 727 const LLArrayType* arrTy = LLArrayType::get(tiTy, dim); |
746 LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits); | 728 LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits); |
747 | 729 |
748 // need the pointer to the first element of arrC, so create a global for it | 730 TypeInfoBuilder b(Type::typeinfotypelist); |
749 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage; | 731 |
750 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrTy,true,_linkage,arrC,".tupleelements",gIR->module); | 732 // push TypeInfo[] |
751 | 733 b.push_array(arrC, dim, Type::typeinfo->type, NULL); |
752 // get pointer to first element | 734 |
753 llvm::ConstantInt* zero = DtoConstSize_t(0); | 735 // finish |
754 LLConstant* idxs[2] = { zero, zero }; | 736 b.finalize(ir.irGlobal); |
755 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar, idxs, 2); | |
756 | |
757 // build the slice | |
758 LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrptr); | |
759 sinits.push_back(slice); | |
760 | |
761 // create the inititalizer | |
762 LLConstant* tiInit = llvm::ConstantStruct::get(sinits); | |
763 | |
764 // refine global type | |
765 llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); | |
766 | |
767 // set the initializer | |
768 isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); | |
769 } | 737 } |
770 | 738 |
771 /* ========================================================================= */ | 739 /* ========================================================================= */ |
772 | 740 |
773 #if DMDV2 | 741 #if DMDV2 |