Mercurial > projects > ldc
diff gen/typinf.cpp @ 797:340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Fixed function literals in static initializers.
Changed alignment of delegates from 2*PTRSIZE to just PTRSIZE.
Changed errors to go to stderr instead of stdout.
Fairly major rewriting of struct/union/class handling, STILL A BIT BUGGY !!!
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sat, 29 Nov 2008 21:25:43 +0100 |
parents | 6e7a4c3b64d2 |
children | 2dfd05525e2e |
line wrap: on
line diff
--- a/gen/typinf.cpp Sat Nov 29 12:28:10 2008 +0100 +++ b/gen/typinf.cpp Sat Nov 29 21:25:43 2008 +0100 @@ -379,7 +379,7 @@ const LLStructType* stype = isaStruct(base->type->ir.type->get()); // create the symbol - this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoTypedefDeclaration::llvmDefine() @@ -390,10 +390,6 @@ ClassDeclaration* base = Type::typeinfotypedef; DtoForceConstInitDsymbol(base); - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - if (Logger::enabled()) - Logger::cout() << "got stype: " << *stype << '\n'; - // vtbl std::vector<LLConstant*> sinits; sinits.push_back(base->ir.irStruct->vtbl); @@ -408,13 +404,11 @@ // TypeInfo base sd->basetype = sd->basetype->merge(); // DMD does this! LLConstant* castbase = DtoTypeInfoOf(sd->basetype, true); - assert(castbase->getType() == stype->getElementType(2)); sinits.push_back(castbase); // char[] name char *name = sd->toPrettyChars(); sinits.push_back(DtoConstString(name)); - assert(sinits.back()->getType() == stype->getElementType(3)); // void[] init const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); @@ -433,9 +427,14 @@ sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); } - // create the symbol - LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); + // create the inititalizer + LLConstant* tiInit = llvm::ConstantStruct::get(sinits); + + // refine global type + llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); + + // set the initializer + isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); } void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) @@ -453,10 +452,8 @@ ClassDeclaration* base = Type::typeinfoenum; DtoResolveClass(base); - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // create the symbol - this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoEnumDeclaration::llvmDefine() @@ -467,8 +464,6 @@ ClassDeclaration* base = Type::typeinfoenum; DtoForceConstInitDsymbol(base); - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // vtbl std::vector<LLConstant*> sinits; sinits.push_back(base->ir.irStruct->vtbl); @@ -482,13 +477,11 @@ // TypeInfo base LLConstant* castbase = DtoTypeInfoOf(sd->memtype, true); - assert(castbase->getType() == stype->getElementType(2)); sinits.push_back(castbase); // char[] name char *name = sd->toPrettyChars(); sinits.push_back(DtoConstString(name)); - assert(sinits.back()->getType() == stype->getElementType(3)); // void[] init const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); @@ -512,9 +505,14 @@ #endif } - // create the symbol - LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); + // create the inititalizer + LLConstant* tiInit = llvm::ConstantStruct::get(sinits); + + // refine global type + llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); + + // set the initializer + isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); } void TypeInfoEnumDeclaration::toDt(dt_t **pdt) @@ -529,10 +527,8 @@ ClassDeclaration* base = cd; DtoResolveClass(base); - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // create the symbol - tid->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); + tid->ir.irGlobal->value = new llvm::GlobalVariable(tid->ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); } static LLConstant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) @@ -540,8 +536,6 @@ ClassDeclaration* base = cd; DtoForceConstInitDsymbol(base); - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // vtbl std::vector<LLConstant*> sinits; sinits.push_back(base->ir.irStruct->vtbl); @@ -551,11 +545,15 @@ // TypeInfo base LLConstant* castbase = DtoTypeInfoOf(basetype, true); - assert(castbase->getType() == stype->getElementType(2)); sinits.push_back(castbase); - // create the symbol - LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); + // create the inititalizer + LLConstant* tiInit = llvm::ConstantStruct::get(sinits); + + // refine global type + llvm::cast<llvm::OpaqueType>(tid->ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); + + // set the initializer isaGlobalVar(tid->ir.irGlobal->value)->setInitializer(tiInit); } @@ -628,11 +626,8 @@ ClassDeclaration* base = Type::typeinfostaticarray; DtoResolveClass(base); - // get type of typeinfo class - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // create the symbol - this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoStaticArrayDeclaration::llvmDefine() @@ -665,9 +660,14 @@ // length sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); - // create the symbol - LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); + // create the inititalizer + LLConstant* tiInit = llvm::ConstantStruct::get(sinits); + + // refine global type + llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); + + // set the initializer + isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); } void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) @@ -686,11 +686,8 @@ ClassDeclaration* base = Type::typeinfoassociativearray; DtoResolveClass(base); - // get type of typeinfo class - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // create the symbol - this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoAssociativeArrayDeclaration::llvmDefine() @@ -702,9 +699,6 @@ ClassDeclaration* base = Type::typeinfoassociativearray; DtoForceConstInitDsymbol(base); - // get type of typeinfo class - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // initializer vector std::vector<LLConstant*> sinits; // first is always the vtable @@ -719,17 +713,20 @@ // value typeinfo LLConstant* castbase = DtoTypeInfoOf(tc->next, true); - assert(castbase->getType() == stype->getElementType(2)); sinits.push_back(castbase); // key typeinfo castbase = DtoTypeInfoOf(tc->index, true); - assert(castbase->getType() == stype->getElementType(3)); sinits.push_back(castbase); - // create the symbol - LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); + // create the inititalizer + LLConstant* tiInit = llvm::ConstantStruct::get(sinits); + + // refine global type + llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); + + // set the initializer + isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); } void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) @@ -810,10 +807,8 @@ ClassDeclaration* base = Type::typeinfostruct; DtoResolveClass(base); - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // create the symbol - this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoStructDeclaration::llvmDefine() @@ -1001,9 +996,14 @@ #endif - // create the symbol - LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); + // create the inititalizer + LLConstant* tiInit = llvm::ConstantStruct::get(sinits); + + // refine global type + llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); + + // set the initializer + isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); } void TypeInfoStructDeclaration::toDt(dt_t **pdt) @@ -1023,11 +1023,8 @@ assert(base); DtoResolveClass(base); - // get type of typeinfo class - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // create the symbol - this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, llvm::GlobalValue::WeakLinkage, NULL, toChars(), gIR->module); } void TypeInfoClassDeclaration::llvmDefine() @@ -1040,9 +1037,6 @@ assert(base); DtoForceConstInitDsymbol(base); - // get type of typeinfo class - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // initializer vector std::vector<LLConstant*> sinits; // first is always the vtable @@ -1058,9 +1052,14 @@ assert(tc->sym->ir.irStruct->classInfo); sinits.push_back(tc->sym->ir.irStruct->classInfo); - // create the symbol - LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); + // create the inititalizer + LLConstant* tiInit = llvm::ConstantStruct::get(sinits); + + // refine global type + llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); + + // set the initializer + isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); } void TypeInfoClassDeclaration::toDt(dt_t **pdt) @@ -1080,11 +1079,8 @@ assert(base); DtoResolveClass(base); - // get type of typeinfo class - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // create the symbol - this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoInterfaceDeclaration::llvmDefine() @@ -1114,9 +1110,14 @@ assert(tc->sym->ir.irStruct->classInfo); sinits.push_back(tc->sym->ir.irStruct->classInfo); - // create the symbol - LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); + // create the inititalizer + LLConstant* tiInit = llvm::ConstantStruct::get(sinits); + + // refine global type + llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); + + // set the initializer + isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); } void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) @@ -1136,11 +1137,8 @@ assert(base); DtoResolveClass(base); - // get type of typeinfo class - const LLStructType* stype = isaStruct(base->type->ir.type->get()); - // create the symbol - this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoTupleDeclaration::llvmDefine() @@ -1199,9 +1197,14 @@ LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrptr); sinits.push_back(slice); - // create the symbol - LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); + // create the inititalizer + LLConstant* tiInit = llvm::ConstantStruct::get(sinits); + + // refine global type + llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType()); + + // set the initializer + isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit); } void TypeInfoTupleDeclaration::toDt(dt_t **pdt)