mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Cleaned up TypeInfo_Tuple generation.
This commit is contained in:
@@ -60,26 +60,46 @@ void TypeInfoBuilder::push_null_void_array()
|
||||
inits.push_back(getNullValue(T));
|
||||
}
|
||||
|
||||
void TypeInfoBuilder::push_void_array(size_t dim, llvm::Constant* ptr)
|
||||
void TypeInfoBuilder::push_void_array(uint64_t dim, llvm::Constant* ptr)
|
||||
{
|
||||
inits.push_back(DtoConstSlice(
|
||||
DtoConstSize_t(dim),
|
||||
DtoBitCast(ptr, getVoidPtrType())));
|
||||
DtoBitCast(ptr, getVoidPtrType())
|
||||
));
|
||||
}
|
||||
|
||||
void TypeInfoBuilder::push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* sym)
|
||||
void TypeInfoBuilder::push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* mangle_sym)
|
||||
{
|
||||
std::string initname(sym->mangle());
|
||||
initname.append("13__defaultInitZ");
|
||||
std::string initname(mangle_sym->mangle());
|
||||
initname.append(".rtti.void[].data");
|
||||
|
||||
LLGlobalVariable* G = new llvm::GlobalVariable(
|
||||
CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module);
|
||||
G->setAlignment(valtype->alignsize());
|
||||
|
||||
size_t dim = getTypePaddedSize(CI->getType());
|
||||
LLConstant* ptr = DtoBitCast(CI, DtoType(valtype->pointerTo()));
|
||||
|
||||
push_void_array(dim, G);
|
||||
}
|
||||
|
||||
void TypeInfoBuilder::push_array(llvm::Constant * CI, uint64_t dim, Type* valtype, Dsymbol * mangle_sym)
|
||||
{
|
||||
std::string initname(mangle_sym?mangle_sym->mangle():".ldc");
|
||||
initname.append(".rtti.");
|
||||
initname.append(valtype->arrayOf()->toChars());
|
||||
initname.append(".data");
|
||||
|
||||
LLGlobalVariable* G = new llvm::GlobalVariable(
|
||||
CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module);
|
||||
G->setAlignment(valtype->alignsize());
|
||||
|
||||
inits.push_back(DtoConstSlice(
|
||||
DtoConstSize_t(dim),
|
||||
DtoBitCast(CI, DtoType(valtype->pointerTo()))
|
||||
));
|
||||
}
|
||||
|
||||
void TypeInfoBuilder::push_uint(unsigned u)
|
||||
{
|
||||
inits.push_back(DtoConstUint(u));
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
struct ClassDeclaration;
|
||||
struct TypeClass;
|
||||
struct Type;
|
||||
|
||||
struct IrStruct;
|
||||
|
||||
@@ -29,8 +30,9 @@ struct TypeInfoBuilder
|
||||
void push_typeinfo(Type* t);
|
||||
void push_classinfo(ClassDeclaration* cd);
|
||||
void push_funcptr(FuncDeclaration* fd);
|
||||
void push_void_array(size_t dim, llvm::Constant* ptr);
|
||||
void push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* sym);
|
||||
void push_void_array(uint64_t dim, llvm::Constant* ptr);
|
||||
void push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* mangle_sym);
|
||||
void push_array(llvm::Constant* CI, uint64_t dim, Type* valtype, Dsymbol* mangle_sym);
|
||||
|
||||
/// Creates the initializer constant and assigns it to the global.
|
||||
void finalize(IrGlobal* tid);
|
||||
|
||||
@@ -707,65 +707,33 @@ void TypeInfoTupleDeclaration::llvmDefine()
|
||||
Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
// init typeinfo class
|
||||
ClassDeclaration* base = Type::typeinfotypelist;
|
||||
assert(base);
|
||||
base->codegen(Type::sir);
|
||||
|
||||
// get type of typeinfo class
|
||||
const LLStructType* stype = isaStruct(base->type->irtype->getPA());
|
||||
|
||||
// initializer vector
|
||||
std::vector<LLConstant*> sinits;
|
||||
// first is always the vtable
|
||||
sinits.push_back(base->ir.irStruct->getVtblSymbol());
|
||||
|
||||
// monitor
|
||||
sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty)));
|
||||
|
||||
// create elements array
|
||||
assert(tinfo->ty == Ttuple);
|
||||
TypeTuple *tu = (TypeTuple *)tinfo;
|
||||
|
||||
size_t dim = tu->arguments->dim;
|
||||
std::vector<LLConstant*> arrInits;
|
||||
arrInits.reserve(dim);
|
||||
|
||||
const LLType* tiTy = Type::typeinfo->type->irtype->getPA();
|
||||
tiTy = getPtrToType(tiTy);
|
||||
const LLType* tiTy = DtoType(Type::typeinfo->type);
|
||||
|
||||
for (size_t i = 0; i < dim; i++)
|
||||
{
|
||||
Argument *arg = (Argument *)tu->arguments->data[i];
|
||||
LLConstant* castbase = DtoTypeInfoOf(arg->type, true);
|
||||
assert(castbase->getType() == tiTy);
|
||||
arrInits.push_back(castbase);
|
||||
arrInits.push_back(DtoTypeInfoOf(arg->type, true));
|
||||
}
|
||||
|
||||
// build array type
|
||||
// build array
|
||||
const LLArrayType* arrTy = LLArrayType::get(tiTy, dim);
|
||||
LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits);
|
||||
|
||||
// need the pointer to the first element of arrC, so create a global for it
|
||||
llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;
|
||||
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrTy,true,_linkage,arrC,".tupleelements",gIR->module);
|
||||
TypeInfoBuilder b(Type::typeinfotypelist);
|
||||
|
||||
// get pointer to first element
|
||||
llvm::ConstantInt* zero = DtoConstSize_t(0);
|
||||
LLConstant* idxs[2] = { zero, zero };
|
||||
LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar, idxs, 2);
|
||||
// push TypeInfo[]
|
||||
b.push_array(arrC, dim, Type::typeinfo->type, NULL);
|
||||
|
||||
// build the slice
|
||||
LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrptr);
|
||||
sinits.push_back(slice);
|
||||
|
||||
// create the inititalizer
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(sinits);
|
||||
|
||||
// refine global type
|
||||
llvm::cast<llvm::OpaqueType>(ir.irGlobal->type.get())->refineAbstractTypeTo(tiInit->getType());
|
||||
|
||||
// set the initializer
|
||||
isaGlobalVar(ir.irGlobal->value)->setInitializer(tiInit);
|
||||
// finish
|
||||
b.finalize(ir.irGlobal);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
Reference in New Issue
Block a user