mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-04 09:00:33 +03:00
Get rid of special 'typeid(...)' LL types for TypeInfos
Use the real LL type representing the TypeInfo (sub)class directly and from the beginning, i.e., already for the declaration, instead of building an extra LL struct type (firstly opaque, then finalized when defining the TypeInfo via RTTIBuilder). To get this to work in all cases, the dummy TypeInfo for opaque structs is now a complete TypeInfo_Struct, with all 11/13 fields zero- initialized. Previously, it was a special TypeInfo (no extra TypeInfo_Struct fields) with TypeInfo_Struct vtable, something which DMD also emits. Also refactor the RTTIBuilder finalize() interface - e.g., don't set the linkage there (had to be reverted for ModuleInfos) and only take the global variable to be defined. Cast the field initializers if required, e.g., null pointers to appropriately typed function pointers for TypeInfo_Struct etc.
This commit is contained in:
parent
3d0a127d96
commit
3f38f9715a
5 changed files with 97 additions and 76 deletions
|
@ -150,36 +150,35 @@ void RTTIBuilder::push_funcptr(FuncDeclaration *fd, Type *castto) {
|
|||
}
|
||||
}
|
||||
|
||||
void RTTIBuilder::finalize(IrGlobal *tid) {
|
||||
finalize(tid->getType(), tid->value);
|
||||
}
|
||||
|
||||
void RTTIBuilder::finalize(LLType *type, LLValue *value) {
|
||||
llvm::ArrayRef<LLConstant *> inits = llvm::makeArrayRef(this->inits);
|
||||
LLStructType *st = isaStruct(type);
|
||||
void RTTIBuilder::finalize(LLGlobalVariable *gvar) {
|
||||
LLStructType *st = isaStruct(gvar->getType()->getPointerElementType());
|
||||
assert(st);
|
||||
|
||||
// set struct body
|
||||
// finalize the type if opaque (e.g., for ModuleInfos)
|
||||
if (st->isOpaque()) {
|
||||
const int n = inits.size();
|
||||
std::vector<LLType *> types;
|
||||
types.reserve(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
types.push_back(inits[i]->getType());
|
||||
std::vector<LLType *> fieldTypes;
|
||||
fieldTypes.reserve(inits.size());
|
||||
for (auto c : inits) {
|
||||
fieldTypes.push_back(c->getType());
|
||||
}
|
||||
st->setBody(types);
|
||||
st->setBody(fieldTypes);
|
||||
}
|
||||
|
||||
// create the inititalizer
|
||||
LLConstant *tiInit = LLConstantStruct::get(st, inits);
|
||||
// create the initializer
|
||||
LLConstant *tiInit = get_constant(st);
|
||||
|
||||
// set the initializer
|
||||
llvm::GlobalVariable *gvar = llvm::cast<llvm::GlobalVariable>(value);
|
||||
gvar->setInitializer(tiInit);
|
||||
setLinkage({TYPEINFO_LINKAGE_TYPE, supportsCOMDAT()}, gvar);
|
||||
}
|
||||
|
||||
LLConstant *RTTIBuilder::get_constant(LLStructType *initType) {
|
||||
// just return the inititalizer
|
||||
return LLConstantStruct::get(initType, inits);
|
||||
assert(initType->getNumElements() == inits.size());
|
||||
|
||||
std::vector<LLConstant *> castInits;
|
||||
castInits.reserve(inits.size());
|
||||
for (unsigned i = 0; i < inits.size(); ++i) {
|
||||
castInits.push_back(DtoBitCast(inits[i], initType->getElementType(i)));
|
||||
}
|
||||
|
||||
return LLConstantStruct::get(initType, castInits);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue