From 4ae14449ea8e2f911554051390bb36aa961c5ad1 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 2 Sep 2012 02:09:14 +0200 Subject: [PATCH] Emit new TypeInfo layout. Includes untested support for RTInfo. --- gen/classes.cpp | 24 ++++++++++++++---------- gen/rttibuilder.cpp | 5 +++++ gen/rttibuilder.h | 1 + gen/typinf.cpp | 15 ++++++++++++--- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/gen/classes.cpp b/gen/classes.cpp index 1ac63ced..4db73d7f 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -676,7 +676,7 @@ LLConstant* DtoDefineClassInfo(ClassDeclaration* cd) // OffsetTypeInfo[] offTi; // void *defaultConstructor; // version(D_Version2) -// const(MemberInfo[]) function(string) xgetMembers; +// immutable(void)* m_RTInfo; // else // TypeInfo typeinfo; // since dmd 1.045 // } @@ -761,10 +761,12 @@ LLConstant* DtoDefineClassInfo(ClassDeclaration* cd) b.push_funcptr(cd->inv, invVar->type); // uint flags + unsigned flags; if (cd->isInterfaceDeclaration()) - b.push_uint(4 | cd->isCOMinterface() | 32); + flags = 4 | cd->isCOMinterface() | 32; else - b.push_uint(build_classinfo_flags(cd)); + flags = build_classinfo_flags(cd); + b.push_uint(flags); // deallocator b.push_funcptr(cd->aggDelete, Type::tvoid->pointerTo()); @@ -790,16 +792,18 @@ LLConstant* DtoDefineClassInfo(ClassDeclaration* cd) b.push_funcptr(cd->defaultCtor, defConstructorVar->type); #if DMDV2 - - // xgetMembers - VarDeclaration* xgetVar = static_cast(cinfo->fields.data[11]); - b.push_funcptr(cd->findGetMembers(), xgetVar->type); - + // immutable(void)* m_RTInfo; + // The cases where getRTInfo is null are not quite here, but the code is + // modelled after what DMD does. + if (cd->getRTInfo) + b.push(cd->getRTInfo->toConstElem(gIR)); + else if (flags & 2) + b.push_size_as_vp(0); // no pointers + else + b.push_size_as_vp(1); // has pointers #else - // typeinfo - since 1.045 b.push_typeinfo(cd->type); - #endif /*size_t n = inits.size(); diff --git a/gen/rttibuilder.cpp b/gen/rttibuilder.cpp index 6a8e3eeb..985dcc97 100644 --- a/gen/rttibuilder.cpp +++ b/gen/rttibuilder.cpp @@ -121,6 +121,11 @@ void RTTIBuilder::push_size(uint64_t s) inits.push_back(DtoConstSize_t(s)); } +void RTTIBuilder::push_size_as_vp(uint64_t s) +{ + inits.push_back(llvm::ConstantExpr::getIntToPtr(DtoConstSize_t(s), getVoidPtrType())); +} + void RTTIBuilder::push_funcptr(FuncDeclaration* fd, Type* castto) { if (fd) diff --git a/gen/rttibuilder.h b/gen/rttibuilder.h index d7f54540..98f2598b 100644 --- a/gen/rttibuilder.h +++ b/gen/rttibuilder.h @@ -29,6 +29,7 @@ struct RTTIBuilder void push_null_void_array(); void push_uint(unsigned u); void push_size(uint64_t s); + void push_size_as_vp(uint64_t s); void push_string(const char* str); void push_typeinfo(Type* t); void push_classinfo(ClassDeclaration* cd); diff --git a/gen/typinf.cpp b/gen/typinf.cpp index acd2264e..53d12585 100644 --- a/gen/typinf.cpp +++ b/gen/typinf.cpp @@ -710,9 +710,6 @@ void TypeInfoStructDeclaration::llvmDefine() assert((!global.params.is64bit && tscd->fields.dim == 11) || (global.params.is64bit && tscd->fields.dim == 13)); - // const(MemberInfo[]) function(in char[]) xgetMembers; - b.push_funcptr(sd->findGetMembers()); - //void function(void*) xdtor; b.push_funcptr(sd->dtor); @@ -727,6 +724,8 @@ void TypeInfoStructDeclaration::llvmDefine() if (global.params.is64bit) { + // TypeInfo m_arg1; + // TypeInfo m_arg2; TypeTuple *tup = tc->toArgTypes(); assert(tup->arguments->dim <= 2); for (unsigned i = 0; i < 2; i++) @@ -742,6 +741,16 @@ void TypeInfoStructDeclaration::llvmDefine() } } + // immutable(void)* m_RTInfo; + // The cases where getRTInfo is null are not quite here, but the code is + // modelled after what DMD does. + if (sd->getRTInfo) + b.push(sd->getRTInfo->toConstElem(gIR)); + else if (!tc->hasPointers()) + b.push_size_as_vp(0); // no pointers + else + b.push_size_as_vp(1); // has pointers + #endif // finish