# HG changeset patch # User Tomas Lindquist Olsen # Date 1239971909 -7200 # Node ID 465a77c904d4bd223ab103ee26c23fe21797d433 # Parent e1b0c5c74c58433cad2821e9721ad76bafa6f172 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'. diff -r e1b0c5c74c58 -r 465a77c904d4 dmd/mtype.c --- a/dmd/mtype.c Fri Apr 17 03:01:43 2009 +0200 +++ b/dmd/mtype.c Fri Apr 17 14:38:29 2009 +0200 @@ -109,6 +109,10 @@ unsigned char Type::mangleChar[TMAX]; StringTable Type::stringtable; +#if IN_LLVM +StringTable Type::deco_stringtable; +#endif + Type::Type(TY ty, Type *next) { @@ -444,11 +448,23 @@ else { sv->ptrvalue = this; - + + // we still need deco strings to be unique + // or Type::equals fails, which breaks a bunch of stuff, + // like covariant member function overloads. OutBuffer mangle; toDecoBuffer(&mangle, true); - mangle.writeByte(0); - deco = mem.strdup((char *)mangle.data); + StringValue* sv2 = deco_stringtable.update((char *)mangle.data, mangle.offset); + if (sv2->ptrvalue) + { Type* t2 = (Type *) sv2->ptrvalue; + assert(t2->deco); + deco = t2->deco; + } + else + { + sv2->ptrvalue = this; + deco = (char *)sv2->lstring.string; + } //printf("new value, deco = '%s' %p\n", t->deco, t->deco); } } diff -r e1b0c5c74c58 -r 465a77c904d4 dmd/mtype.h --- a/dmd/mtype.h Fri Apr 17 03:01:43 2009 +0200 +++ b/dmd/mtype.h Fri Apr 17 14:38:29 2009 +0200 @@ -193,6 +193,9 @@ static Type *basic[TMAX]; static unsigned char mangleChar[TMAX]; static StringTable stringtable; +#if IN_LLVM + static StringTable deco_stringtable; +#endif // These tables are for implicit conversion of binary ops; // the indices are the type of operand one, followed by operand two. diff -r e1b0c5c74c58 -r 465a77c904d4 gen/toir.cpp --- a/gen/toir.cpp Fri Apr 17 03:01:43 2009 +0200 +++ b/gen/toir.cpp Fri Apr 17 14:38:29 2009 +0200 @@ -2390,6 +2390,9 @@ Logger::print("StructLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars()); LOG_SCOPE; + // make sure the struct is resolved + sd->codegen(Type::sir); + // get inits std::vector inits(sd->fields.dim, NULL); @@ -2448,6 +2451,9 @@ Logger::print("StructLiteralExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); LOG_SCOPE; + // make sure the struct is resolved + sd->codegen(Type::sir); + // get inits std::vector inits(sd->fields.dim, NULL); diff -r e1b0c5c74c58 -r 465a77c904d4 gen/typinf.cpp --- a/gen/typinf.cpp Fri Apr 17 03:01:43 2009 +0200 +++ b/gen/typinf.cpp Fri Apr 17 14:38:29 2009 +0200 @@ -638,6 +638,7 @@ Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); LOG_SCOPE; + // make sure struct is resolved assert(tinfo->ty == Tstruct); TypeStruct *tc = (TypeStruct *)tinfo; StructDeclaration *sd = tc->sym; @@ -835,6 +836,11 @@ Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); LOG_SCOPE; + // make sure class is resolved + assert(tinfo->ty == Tclass); + TypeClass *tc = (TypeClass *)tinfo; + tc->sym->codegen(Type::sir); + // init typeinfo class ClassDeclaration* base = Type::typeinfoclass; assert(base); @@ -849,11 +855,6 @@ sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); // get classinfo - assert(tinfo->ty == Tclass); - TypeClass *tc = (TypeClass *)tinfo; - - tc->sym->codegen(Type::sir); - sinits.push_back(tc->sym->ir.irStruct->getClassInfoSymbol()); // create the inititalizer @@ -873,6 +874,11 @@ Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars()); LOG_SCOPE; + // make sure interface is resolved + assert(tinfo->ty == Tclass); + TypeClass *tc = (TypeClass *)tinfo; + tc->sym->codegen(Type::sir); + // init typeinfo class ClassDeclaration* base = Type::typeinfointerface; assert(base); @@ -890,9 +896,6 @@ sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); // get classinfo - assert(tinfo->ty == Tclass); - TypeClass *tc = (TypeClass *)tinfo; - sinits.push_back(tc->sym->ir.irStruct->getClassInfoSymbol()); // create the inititalizer diff -r e1b0c5c74c58 -r 465a77c904d4 ir/irstruct.cpp --- a/ir/irstruct.cpp Fri Apr 17 03:01:43 2009 +0200 +++ b/ir/irstruct.cpp Fri Apr 17 14:38:29 2009 +0200 @@ -191,7 +191,9 @@ // build constant struct llvm::Constant* definit = llvm::ConstantStruct::get(constants, packed); +#if 0 IF_LOG Logger::cout() << "final default initializer: " << *definit << std::endl; +#endif // sanity check if (definit->getType() != type->irtype->get()) diff -r e1b0c5c74c58 -r 465a77c904d4 ir/irtypeclass.cpp --- a/ir/irtypeclass.cpp Fri Apr 17 03:01:43 2009 +0200 +++ b/ir/irtypeclass.cpp Fri Apr 17 14:38:29 2009 +0200 @@ -109,9 +109,7 @@ offset += PTRSIZE; // add to the interface map - // FIXME: and all it's baseinterfaces - if (interfaceMap.find(b->base) == interfaceMap.end()) - interfaceMap.insert(std::make_pair(b->base, field_index)); + addInterfaceToMap(b->base, field_index); field_index++; // inc count @@ -252,3 +250,22 @@ } ////////////////////////////////////////////////////////////////////////////// + +void IrTypeClass::addInterfaceToMap(ClassDeclaration * inter, size_t index) +{ + // don't duplicate work or overwrite indices + if (interfaceMap.find(inter) != interfaceMap.end()) + return; + + // add this interface + interfaceMap.insert(std::make_pair(inter, index)); + + // add all its base interfaces recursively + for (size_t i = 0; i < inter->interfaces_dim; i++) + { + BaseClass* b = inter->interfaces[i]; + addInterfaceToMap(b->base, index); + } +} + +////////////////////////////////////////////////////////////////////////////// diff -r e1b0c5c74c58 -r 465a77c904d4 ir/irtypeclass.h --- a/ir/irtypeclass.h Fri Apr 17 03:01:43 2009 +0200 +++ b/ir/irtypeclass.h Fri Apr 17 14:38:29 2009 +0200 @@ -68,6 +68,10 @@ ClassDeclaration* base, size_t& offset, size_t& field_index); + + /// Adds the interface and all it's base interface to the interface + /// to index map. + void addInterfaceToMap(ClassDeclaration* inter, size_t index); }; #endif diff -r e1b0c5c74c58 -r 465a77c904d4 ir/irtypestruct.cpp --- a/ir/irtypestruct.cpp Fri Apr 17 03:01:43 2009 +0200 +++ b/ir/irtypestruct.cpp Fri Apr 17 14:38:29 2009 +0200 @@ -86,14 +86,16 @@ for (; !it.done(); it.next()) { VarDeclaration* vd = it.get(); + //Logger::println("vd: %s", vd->toPrettyChars()); - assert(vd->ir.irField == NULL && "struct inheritance is not allowed, how can this happen?"); + //assert(vd->ir.irField == NULL && "struct inheritance is not allowed, how can this happen?"); // skip if offset moved backwards if (vd->offset < offset) { IF_LOG Logger::println("Skipping field %s %s (+%u) for default", vd->type->toChars(), vd->toChars(), vd->offset); - new IrField(vd, 0, vd->offset); + if (vd->ir.irField == NULL) + new IrField(vd, 0, vd->offset); continue; } @@ -123,7 +125,8 @@ // the IrField creation doesn't really belong here, but it's a trivial operation // and it save yet another of these loops. IF_LOG Logger::println("Field index: %zu", field_index); - new IrField(vd, field_index); + if (vd->ir.irField == NULL) + new IrField(vd, field_index); field_index++; } @@ -142,7 +145,7 @@ // name types Type::sir->getState()->module->addTypeName(sd->toPrettyChars(), pa.get()); -#if 1 +#if 0 IF_LOG Logger::cout() << "final struct type: " << *pa.get() << std::endl; #endif