mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-02 08:01:11 +03:00
Slightly refactor RTTIBuilder
This commit is contained in:
parent
9ff736bf0f
commit
e337cec78a
8 changed files with 44 additions and 61 deletions
|
@ -613,8 +613,8 @@ LLConstant *DtoDefineClassInfo(ClassDeclaration *cd) {
|
|||
assert(cd->type->ty == Tclass);
|
||||
|
||||
IrAggr *ir = getIrAggr(cd);
|
||||
getClassInfoType(); // check declaration in object.d
|
||||
ClassDeclaration *cinfo = Type::typeinfoclass;
|
||||
Type *const cinfoType = getClassInfoType(); // check declaration in object.d
|
||||
ClassDeclaration *const cinfo = Type::typeinfoclass;
|
||||
|
||||
if (cinfo->fields.dim != 12) {
|
||||
error(Loc(), "Unexpected number of fields in `object.ClassInfo`; "
|
||||
|
@ -623,7 +623,7 @@ LLConstant *DtoDefineClassInfo(ClassDeclaration *cd) {
|
|||
}
|
||||
|
||||
// use the rtti builder
|
||||
RTTIBuilder b(cinfo);
|
||||
RTTIBuilder b(cinfoType);
|
||||
|
||||
LLConstant *c;
|
||||
|
||||
|
@ -664,7 +664,7 @@ LLConstant *DtoDefineClassInfo(ClassDeclaration *cd) {
|
|||
if (cd->baseClass && !cd->isInterfaceDeclaration()) {
|
||||
b.push_classinfo(cd->baseClass);
|
||||
} else {
|
||||
b.push_null(cinfo->type);
|
||||
b.push_null(cinfoType);
|
||||
}
|
||||
|
||||
// destructor
|
||||
|
|
|
@ -194,8 +194,9 @@ llvm::Constant *buildLocalClasses(Module *m, size_t &count) {
|
|||
}
|
||||
|
||||
llvm::GlobalVariable *genModuleInfo(Module *m) {
|
||||
getModuleInfoType(); // check declaration in object.d
|
||||
auto moduleInfoDecl = Module::moduleinfo;
|
||||
// check declaration in object.d
|
||||
const auto moduleInfoType = getModuleInfoType();
|
||||
const auto moduleInfoDecl = Module::moduleinfo;
|
||||
|
||||
// The "new-style" ModuleInfo records are variable-length, with the presence
|
||||
// of the various fields indicated by a certain flag bit. The base struct
|
||||
|
@ -261,7 +262,7 @@ llvm::GlobalVariable *genModuleInfo(Module *m) {
|
|||
}
|
||||
|
||||
// Now, start building the initialiser for the ModuleInfo instance.
|
||||
RTTIBuilder b(moduleInfoDecl);
|
||||
RTTIBuilder b(moduleInfoType);
|
||||
|
||||
b.push_uint(flags);
|
||||
b.push_uint(0); // index
|
||||
|
|
|
@ -20,18 +20,16 @@
|
|||
#include "ir/iraggr.h"
|
||||
#include "ir/irfunction.h"
|
||||
|
||||
RTTIBuilder::RTTIBuilder(AggregateDeclaration *base_class) {
|
||||
DtoResolveDsymbol(base_class);
|
||||
RTTIBuilder::RTTIBuilder(Type *baseType) {
|
||||
const auto ad = isAggregate(baseType);
|
||||
assert(ad && "not an aggregate type");
|
||||
|
||||
base = base_class;
|
||||
basetype = static_cast<TypeClass *>(base->type);
|
||||
DtoResolveDsymbol(ad);
|
||||
|
||||
baseir = getIrAggr(base);
|
||||
assert(baseir && "no IrStruct for TypeInfo base class");
|
||||
if (ad->isClassDeclaration()) {
|
||||
const auto baseir = getIrAggr(ad);
|
||||
assert(baseir && "no IrAggr for TypeInfo base class");
|
||||
|
||||
prevFieldEnd = 0;
|
||||
|
||||
if (base->isClassDeclaration()) {
|
||||
// just start with adding the vtbl
|
||||
push(baseir->getVtblSymbol());
|
||||
// and monitor
|
||||
|
|
|
@ -18,33 +18,25 @@
|
|||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/IR/Constant.h"
|
||||
|
||||
class AggregateDeclaration;
|
||||
class ClassDeclaration;
|
||||
class Dsymbol;
|
||||
class FuncDeclaration;
|
||||
struct IrGlobal;
|
||||
struct IrAggr;
|
||||
class Type;
|
||||
class TypeClass;
|
||||
namespace llvm {
|
||||
class StructType;
|
||||
class GlobalVariable;
|
||||
}
|
||||
|
||||
class RTTIBuilder {
|
||||
AggregateDeclaration *base;
|
||||
TypeClass *basetype;
|
||||
IrAggr *baseir;
|
||||
|
||||
/// The offset (in bytes) at which the previously pushed field ended.
|
||||
uint64_t prevFieldEnd;
|
||||
uint64_t prevFieldEnd = 0;
|
||||
|
||||
public:
|
||||
// 15 is enough for any D2 ClassInfo including 64 bit pointer alignment
|
||||
// padding
|
||||
llvm::SmallVector<llvm::Constant *, 15> inits;
|
||||
|
||||
explicit RTTIBuilder(AggregateDeclaration *base_class);
|
||||
explicit RTTIBuilder(Type *baseType);
|
||||
|
||||
void push(llvm::Constant *C);
|
||||
void push_null(Type *T);
|
||||
|
|
|
@ -183,6 +183,8 @@ LazyClassType invariantTypeInfoTy(Type::typeinfoinvariant,
|
|||
LazyClassType sharedTypeInfoTy(Type::typeinfoshared, "TypeInfo_Shared");
|
||||
LazyClassType inoutTypeInfoTy(Type::typeinfowild, "TypeInfo_Inout");
|
||||
LazyClassType throwableTy(ClassDeclaration::throwable, "Throwable");
|
||||
LazyClassType cppTypeInfoPtrTy(ClassDeclaration::cpp_type_info_ptr,
|
||||
"__cpp_type_info_ptr");
|
||||
|
||||
using LazyAggregateType = LazyType<AggregateDeclaration>;
|
||||
template <> const char *LazyAggregateType::getKind() { return "struct"; }
|
||||
|
@ -429,6 +431,7 @@ Type *getInvariantTypeInfoType() { return invariantTypeInfoTy.get(); }
|
|||
Type *getSharedTypeInfoType() { return sharedTypeInfoTy.get(); }
|
||||
Type *getInoutTypeInfoType() { return inoutTypeInfoTy.get(); }
|
||||
Type *getThrowableType() { return throwableTy.get(); }
|
||||
Type *getCppTypeInfoPtrType() { return cppTypeInfoPtrTy.get(); }
|
||||
Type *getModuleInfoType() { return moduleInfoTy.get(); }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -57,6 +57,7 @@ Type *getInvariantTypeInfoType();
|
|||
Type *getSharedTypeInfoType();
|
||||
Type *getInoutTypeInfoType();
|
||||
Type *getThrowableType();
|
||||
Type *getCppTypeInfoPtrType();
|
||||
Type *getModuleInfoType();
|
||||
|
||||
#endif // LDC_GEN_RUNTIME_H
|
||||
|
|
|
@ -174,11 +174,13 @@ void TryCatchScope::emitCatchBodies(IRState &irs, llvm::Value *ehPtrSlot) {
|
|||
mangleBuf.printf("%d%s", 18, "_cpp_type_info_ptr");
|
||||
const auto wrapperMangle = getIRMangledVarName(mangleBuf.peekString(), LINKd);
|
||||
|
||||
RTTIBuilder b(ClassDeclaration::cpp_type_info_ptr);
|
||||
const auto cppTypeInfoPtrType = getCppTypeInfoPtrType();
|
||||
RTTIBuilder b(cppTypeInfoPtrType);
|
||||
b.push(cpp_ti);
|
||||
|
||||
auto wrapperType = llvm::cast<llvm::StructType>(
|
||||
static_cast<IrTypeClass*>(ClassDeclaration::cpp_type_info_ptr->type->ctype)->getMemoryLLType());
|
||||
static_cast<IrTypeClass *>(cppTypeInfoPtrType->ctype)
|
||||
->getMemoryLLType());
|
||||
auto wrapperInit = b.get_constant(wrapperType);
|
||||
|
||||
ci = getOrCreateGlobal(
|
||||
|
|
|
@ -144,8 +144,7 @@ public:
|
|||
decl->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
getTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::dtypeinfo);
|
||||
RTTIBuilder b(getTypeInfoType());
|
||||
b.finalize(gvar);
|
||||
}
|
||||
|
||||
|
@ -156,8 +155,7 @@ public:
|
|||
decl->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
getEnumTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfoenum);
|
||||
RTTIBuilder b(getEnumTypeInfoType());
|
||||
|
||||
assert(decl->tinfo->ty == Tenum);
|
||||
TypeEnum *tc = static_cast<TypeEnum *>(decl->tinfo);
|
||||
|
@ -192,8 +190,7 @@ public:
|
|||
decl->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
getPointerTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfopointer);
|
||||
RTTIBuilder b(getPointerTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(decl->tinfo->nextOf());
|
||||
// finish
|
||||
|
@ -207,8 +204,7 @@ public:
|
|||
decl->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
getArrayTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfoarray);
|
||||
RTTIBuilder b(getArrayTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(decl->tinfo->nextOf());
|
||||
// finish
|
||||
|
@ -225,8 +221,7 @@ public:
|
|||
assert(decl->tinfo->ty == Tsarray);
|
||||
TypeSArray *tc = static_cast<TypeSArray *>(decl->tinfo);
|
||||
|
||||
getStaticArrayTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfostaticarray);
|
||||
RTTIBuilder b(getStaticArrayTypeInfoType());
|
||||
|
||||
// value typeinfo
|
||||
b.push_typeinfo(tc->nextOf());
|
||||
|
@ -249,8 +244,7 @@ public:
|
|||
assert(decl->tinfo->ty == Taarray);
|
||||
TypeAArray *tc = static_cast<TypeAArray *>(decl->tinfo);
|
||||
|
||||
getAssociativeArrayTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfoassociativearray);
|
||||
RTTIBuilder b(getAssociativeArrayTypeInfoType());
|
||||
|
||||
// value typeinfo
|
||||
b.push_typeinfo(tc->nextOf());
|
||||
|
@ -269,8 +263,7 @@ public:
|
|||
decl->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
getFunctionTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfofunction);
|
||||
RTTIBuilder b(getFunctionTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(decl->tinfo->nextOf());
|
||||
// string deco
|
||||
|
@ -289,8 +282,7 @@ public:
|
|||
assert(decl->tinfo->ty == Tdelegate);
|
||||
Type *ret_type = decl->tinfo->nextOf()->nextOf();
|
||||
|
||||
getDelegateTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfodelegate);
|
||||
RTTIBuilder b(getDelegateTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(ret_type);
|
||||
// string deco
|
||||
|
@ -311,8 +303,9 @@ public:
|
|||
TypeStruct *tc = static_cast<TypeStruct *>(decl->tinfo);
|
||||
StructDeclaration *sd = tc->sym;
|
||||
|
||||
getStructTypeInfoType(); // check declaration in object.d
|
||||
auto structTypeInfoDecl = Type::typeinfostruct;
|
||||
// check declaration in object.d
|
||||
const auto structTypeInfoType = getStructTypeInfoType();
|
||||
const auto structTypeInfoDecl = Type::typeinfostruct;
|
||||
|
||||
// On x86_64, class TypeInfo_Struct contains 2 additional fields
|
||||
// (m_arg1/m_arg2) which are used for the X86_64 System V ABI varargs
|
||||
|
@ -329,7 +322,7 @@ public:
|
|||
fatal();
|
||||
}
|
||||
|
||||
RTTIBuilder b(structTypeInfoDecl);
|
||||
RTTIBuilder b(structTypeInfoType);
|
||||
|
||||
// handle opaque structs
|
||||
if (!sd->members) {
|
||||
|
@ -492,8 +485,7 @@ public:
|
|||
TypeClass *tc = static_cast<TypeClass *>(decl->tinfo);
|
||||
DtoResolveClass(tc->sym);
|
||||
|
||||
getInterfaceTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfointerface);
|
||||
RTTIBuilder b(getInterfaceTypeInfoType());
|
||||
|
||||
// TypeInfo base
|
||||
b.push_classinfo(tc->sym);
|
||||
|
@ -527,8 +519,7 @@ public:
|
|||
LLArrayType *arrTy = LLArrayType::get(tiTy, dim);
|
||||
LLConstant *arrC = LLConstantArray::get(arrTy, arrInits);
|
||||
|
||||
getTupleTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfotypelist);
|
||||
RTTIBuilder b(getTupleTypeInfoType());
|
||||
|
||||
// push TypeInfo[]
|
||||
b.push_array(arrC, dim, getTypeInfoType(), nullptr);
|
||||
|
@ -544,8 +535,7 @@ public:
|
|||
decl->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
getConstTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfoconst);
|
||||
RTTIBuilder b(getConstTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(merge(decl->tinfo->mutableOf()));
|
||||
// finish
|
||||
|
@ -559,8 +549,7 @@ public:
|
|||
decl->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
getInvariantTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfoinvariant);
|
||||
RTTIBuilder b(getInvariantTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(merge(decl->tinfo->mutableOf()));
|
||||
// finish
|
||||
|
@ -574,8 +563,7 @@ public:
|
|||
decl->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
getSharedTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfoshared);
|
||||
RTTIBuilder b(getSharedTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(merge(decl->tinfo->unSharedOf()));
|
||||
// finish
|
||||
|
@ -589,8 +577,7 @@ public:
|
|||
decl->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
getInoutTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfowild);
|
||||
RTTIBuilder b(getInoutTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(merge(decl->tinfo->mutableOf()));
|
||||
// finish
|
||||
|
@ -607,8 +594,7 @@ public:
|
|||
assert(decl->tinfo->ty == Tvector);
|
||||
TypeVector *tv = static_cast<TypeVector *>(decl->tinfo);
|
||||
|
||||
getVectorTypeInfoType(); // check declaration in object.d
|
||||
RTTIBuilder b(Type::typeinfovector);
|
||||
RTTIBuilder b(getVectorTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(tv->basetype);
|
||||
// finish
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue