Permalink
Browse files

Emit new TypeInfo layout.

Includes untested support for RTInfo.
  • Loading branch information...
1 parent 8ebd2ce commit 4ae14449ea8e2f911554051390bb36aa961c5ad1 @klickverbot klickverbot committed Sep 2, 2012
Showing with 32 additions and 13 deletions.
  1. +14 −10 gen/classes.cpp
  2. +5 −0 gen/rttibuilder.cpp
  3. +1 −0 gen/rttibuilder.h
  4. +12 −3 gen/typinf.cpp
View
@@ -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<VarDeclaration*>(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();
View
@@ -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)
View
@@ -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);
View
@@ -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

0 comments on commit 4ae1444

Please sign in to comment.