# HG changeset patch # User Tomas Lindquist Olsen # Date 1242572687 -7200 # Node ID 402bffb1b356f6701ad2d9b358936d2849847b7f # Parent 1609490c123f11a67f13dd75204da42898a8177e Use RTTIBuilder to build !ModuleInfo, still needs some work. diff -r 1609490c123f -r 402bffb1b356 gen/toobj.cpp --- a/gen/toobj.cpp Sun May 17 16:31:23 2009 +0200 +++ b/gen/toobj.cpp Sun May 17 17:04:47 2009 +0200 @@ -36,21 +36,22 @@ #include "template.h" #include "scope.h" -#include "gen/irstate.h" -#include "gen/logger.h" -#include "gen/tollvm.h" -#include "gen/llvmhelpers.h" +#include "gen/abi.h" #include "gen/arrays.h" -#include "gen/structs.h" #include "gen/classes.h" +#include "gen/cl_options.h" #include "gen/functions.h" -#include "gen/todebug.h" +#include "gen/irstate.h" +#include "gen/llvmhelpers.h" +#include "gen/llvm-version.h" +#include "gen/logger.h" +#include "gen/optimizer.h" +#include "gen/programs.h" +#include "gen/rttibuilder.h" #include "gen/runtime.h" -#include "gen/abi.h" -#include "gen/cl_options.h" -#include "gen/optimizer.h" -#include "gen/llvm-version.h" -#include "gen/programs.h" +#include "gen/structs.h" +#include "gen/todebug.h" +#include "gen/tollvm.h" #include "ir/irvar.h" #include "ir/irmodule.h" @@ -618,41 +619,27 @@ error("object.d is missing the ModuleInfo class"); fatal(); } - - moduleinfo->codegen(Type::sir); - // check for patch - if (moduleinfo->fields.dim != 9) + else if (moduleinfo->fields.dim != 9) { error("object.d ModuleInfo class is incorrect"); fatal(); } - // moduleinfo llvm struct type - const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->irtype->getPA()); - // classinfo llvm struct type - const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->irtype->getPA()); + // use the RTTIBuilder + RTTIBuilder b(moduleinfo); - // initializer vector - std::vector initVec; - LLConstant* c = 0; - - // vtable - c = moduleinfo->ir.irStruct->getVtblSymbol(); - initVec.push_back(c); - - // monitor - c = getNullPtr(getPtrToType(LLType::Int8Ty)); - initVec.push_back(c); + // some types + const LLType* moduleinfoTy = moduleinfo->type->irtype->getPA(); + const LLType* classinfoTy = ClassDeclaration::classinfo->type->irtype->getPA(); // name - char *name = toPrettyChars(); - c = DtoConstString(name); - initVec.push_back(c); + b.push_string(toPrettyChars()); // importedModules[] int aimports_dim = aimports.dim; std::vector importInits; + LLConstant* c = 0; for (size_t i = 0; i < aimports.dim; i++) { Module *m = (Module *)aimports.data[i]; @@ -681,8 +668,10 @@ c = DtoConstSlice(DtoConstSize_t(importInits.size()), c); } else + { c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) ); - initVec.push_back(c); + } + b.push(c); // localClasses[] ClassDeclarations aclasses; @@ -731,13 +720,11 @@ } else c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(classinfoTy)) ); - initVec.push_back(c); + b.push(c); - // flags - c = DtoConstUint(0); - if (!needmoduleinfo) - c = DtoConstUint(4); // flags (4 means MIstandalone) - initVec.push_back(c); + // flags (4 means MIstandalone) + unsigned mi_flags = needmoduleinfo ? 0 : 4; + b.push_uint(mi_flags); // function pointer type for next three fields const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::VoidTy, std::vector(), false)); @@ -745,25 +732,25 @@ // ctor llvm::Function* fctor = build_module_ctor(); c = fctor ? fctor : getNullValue(fnptrTy); - initVec.push_back(c); + b.push(c); // dtor llvm::Function* fdtor = build_module_dtor(); c = fdtor ? fdtor : getNullValue(fnptrTy); - initVec.push_back(c); + b.push(c); // unitTest llvm::Function* unittest = build_module_unittest(); c = unittest ? unittest : getNullValue(fnptrTy); - initVec.push_back(c); + b.push(c); // xgetMembers c = getNullValue(getVoidPtrType()); - initVec.push_back(c); + b.push(c); // ictor c = getNullValue(fnptrTy); - initVec.push_back(c); + b.push(c); /*Logger::println("MODULE INFO INITIALIZERS"); for (size_t i=0; i