# HG changeset patch # User Tomas Lindquist Olsen # Date 1242529671 -7200 # Node ID a5d0e04298a82860bcabbaa9625324770713dff3 # Parent 63f4afd010360c9afa68ac0d37011234ac0a4df0 Cleaned up TypeInfo_Tuple generation. diff -r 63f4afd01036 -r a5d0e04298a8 gen/rttibuilder.cpp --- a/gen/rttibuilder.cpp Sun May 17 04:41:10 2009 +0200 +++ b/gen/rttibuilder.cpp Sun May 17 05:07:51 2009 +0200 @@ -60,26 +60,46 @@ inits.push_back(getNullValue(T)); } -void TypeInfoBuilder::push_void_array(size_t dim, llvm::Constant* ptr) +void TypeInfoBuilder::push_void_array(uint64_t dim, llvm::Constant* ptr) { inits.push_back(DtoConstSlice( DtoConstSize_t(dim), - DtoBitCast(ptr, getVoidPtrType()))); + DtoBitCast(ptr, getVoidPtrType()) + )); } -void TypeInfoBuilder::push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* sym) +void TypeInfoBuilder::push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* mangle_sym) { - std::string initname(sym->mangle()); - initname.append("13__defaultInitZ"); + std::string initname(mangle_sym->mangle()); + initname.append(".rtti.void[].data"); LLGlobalVariable* G = new llvm::GlobalVariable( CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module); G->setAlignment(valtype->alignsize()); size_t dim = getTypePaddedSize(CI->getType()); + LLConstant* ptr = DtoBitCast(CI, DtoType(valtype->pointerTo())); + push_void_array(dim, G); } +void TypeInfoBuilder::push_array(llvm::Constant * CI, uint64_t dim, Type* valtype, Dsymbol * mangle_sym) +{ + std::string initname(mangle_sym?mangle_sym->mangle():".ldc"); + initname.append(".rtti."); + initname.append(valtype->arrayOf()->toChars()); + initname.append(".data"); + + LLGlobalVariable* G = new llvm::GlobalVariable( + CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module); + G->setAlignment(valtype->alignsize()); + + inits.push_back(DtoConstSlice( + DtoConstSize_t(dim), + DtoBitCast(CI, DtoType(valtype->pointerTo())) + )); +} + void TypeInfoBuilder::push_uint(unsigned u) { inits.push_back(DtoConstUint(u)); diff -r 63f4afd01036 -r a5d0e04298a8 gen/rttibuilder.h --- a/gen/rttibuilder.h Sun May 17 04:41:10 2009 +0200 +++ b/gen/rttibuilder.h Sun May 17 05:07:51 2009 +0200 @@ -6,6 +6,7 @@ struct ClassDeclaration; struct TypeClass; +struct Type; struct IrStruct; @@ -29,8 +30,9 @@ void push_typeinfo(Type* t); void push_classinfo(ClassDeclaration* cd); void push_funcptr(FuncDeclaration* fd); - void push_void_array(size_t dim, llvm::Constant* ptr); - void push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* sym); + void push_void_array(uint64_t dim, llvm::Constant* ptr); + void push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* mangle_sym); + void push_array(llvm::Constant* CI, uint64_t dim, Type* valtype, Dsymbol* mangle_sym); /// Creates the initializer constant and assigns it to the global. void finalize(IrGlobal* tid); diff -r 63f4afd01036 -r a5d0e04298a8 gen/typinf.cpp --- a/gen/typinf.cpp Sun May 17 04:41:10 2009 +0200 +++ b/gen/typinf.cpp Sun May 17 05:07:51 2009 +0200 @@ -707,65 +707,33 @@ Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars()); LOG_SCOPE; - // init typeinfo class - ClassDeclaration* base = Type::typeinfotypelist; - assert(base); - base->codegen(Type::sir); - - // get type of typeinfo class - const LLStructType* stype = isaStruct(base->type->irtype->getPA()); - - // initializer vector - std::vector sinits; - // first is always the vtable - sinits.push_back(base->ir.irStruct->getVtblSymbol()); - - // monitor - sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); - // create elements array assert(tinfo->ty == Ttuple); TypeTuple *tu = (TypeTuple *)tinfo; size_t dim = tu->arguments->dim; std::vector arrInits; + arrInits.reserve(dim); - const LLType* tiTy = Type::typeinfo->type->irtype->getPA(); - tiTy = getPtrToType(tiTy); + const LLType* tiTy = DtoType(Type::typeinfo->type); for (size_t i = 0; i < dim; i++) { Argument *arg = (Argument *)tu->arguments->data[i]; - LLConstant* castbase = DtoTypeInfoOf(arg->type, true); - assert(castbase->getType() == tiTy); - arrInits.push_back(castbase); + arrInits.push_back(DtoTypeInfoOf(arg->type, true)); } - // build array type + // build array const LLArrayType* arrTy = LLArrayType::get(tiTy, dim); LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits); - // need the pointer to the first element of arrC, so create a global for it - llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage; - llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrTy,true,_linkage,arrC,".tupleelements",gIR->module); - - // get pointer to first element - llvm::ConstantInt* zero = DtoConstSize_t(0); - LLConstant* idxs[2] = { zero, zero }; - LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar, idxs, 2); + TypeInfoBuilder b(Type::typeinfotypelist); - // build the slice - LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrptr); - sinits.push_back(slice); + // push TypeInfo[] + b.push_array(arrC, dim, Type::typeinfo->type, NULL); - // create the inititalizer - LLConstant* tiInit = llvm::ConstantStruct::get(sinits); - - // refine global type - llvm::cast(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); - - // set the initializer - isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); + // finish + b.finalize(ir.irGlobal); } /* ========================================================================= */