changeset 1376:a5d0e04298a8

Cleaned up TypeInfo_Tuple generation.
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Sun, 17 May 2009 05:07:51 +0200
parents 63f4afd01036
children 3fb15be5ab6d
files gen/rttibuilder.cpp gen/rttibuilder.h gen/typinf.cpp
diffstat 3 files changed, 38 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/gen/rttibuilder.cpp	Sun May 17 04:41:10 2009 +0200
+++ b/gen/rttibuilder.cpp	Sun May 17 05:07:51 2009 +0200
@@ -60,26 +60,46 @@
     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));
--- a/gen/rttibuilder.h	Sun May 17 04:41:10 2009 +0200
+++ b/gen/rttibuilder.h	Sun May 17 05:07:51 2009 +0200
@@ -6,6 +6,7 @@
 
 struct ClassDeclaration;
 struct TypeClass;
+struct Type;
 
 struct IrStruct;
 
@@ -29,8 +30,9 @@
     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);
--- a/gen/typinf.cpp	Sun May 17 04:41:10 2009 +0200
+++ b/gen/typinf.cpp	Sun May 17 05:07:51 2009 +0200
@@ -707,65 +707,33 @@
     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);
-
-    // get pointer to first element
-    llvm::ConstantInt* zero = DtoConstSize_t(0);
-    LLConstant* idxs[2] = { zero, zero };
-    LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar, idxs, 2);
+    TypeInfoBuilder b(Type::typeinfotypelist);
 
-    // build the slice
-    LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrptr);
-    sinits.push_back(slice);
+    // push TypeInfo[]
+    b.push_array(arrC, dim, Type::typeinfo->type, NULL);
 
-    // 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);
 }
 
 /* ========================================================================= */