mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-09 20:37:25 +03:00
Use RTTIBuilder to build !ModuleInfo, still needs some work.
This commit is contained in:
parent
3e4ade93ba
commit
b64ad3299e
1 changed files with 33 additions and 46 deletions
|
@ -36,21 +36,22 @@
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
#include "scope.h"
|
#include "scope.h"
|
||||||
|
|
||||||
#include "gen/irstate.h"
|
|
||||||
#include "gen/logger.h"
|
|
||||||
#include "gen/tollvm.h"
|
|
||||||
#include "gen/llvmhelpers.h"
|
|
||||||
#include "gen/arrays.h"
|
|
||||||
#include "gen/structs.h"
|
|
||||||
#include "gen/classes.h"
|
|
||||||
#include "gen/functions.h"
|
|
||||||
#include "gen/todebug.h"
|
|
||||||
#include "gen/runtime.h"
|
|
||||||
#include "gen/abi.h"
|
#include "gen/abi.h"
|
||||||
|
#include "gen/arrays.h"
|
||||||
|
#include "gen/classes.h"
|
||||||
#include "gen/cl_options.h"
|
#include "gen/cl_options.h"
|
||||||
#include "gen/optimizer.h"
|
#include "gen/functions.h"
|
||||||
|
#include "gen/irstate.h"
|
||||||
|
#include "gen/llvmhelpers.h"
|
||||||
#include "gen/llvm-version.h"
|
#include "gen/llvm-version.h"
|
||||||
|
#include "gen/logger.h"
|
||||||
|
#include "gen/optimizer.h"
|
||||||
#include "gen/programs.h"
|
#include "gen/programs.h"
|
||||||
|
#include "gen/rttibuilder.h"
|
||||||
|
#include "gen/runtime.h"
|
||||||
|
#include "gen/structs.h"
|
||||||
|
#include "gen/todebug.h"
|
||||||
|
#include "gen/tollvm.h"
|
||||||
|
|
||||||
#include "ir/irvar.h"
|
#include "ir/irvar.h"
|
||||||
#include "ir/irmodule.h"
|
#include "ir/irmodule.h"
|
||||||
|
@ -618,41 +619,27 @@ void Module::genmoduleinfo()
|
||||||
error("object.d is missing the ModuleInfo class");
|
error("object.d is missing the ModuleInfo class");
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleinfo->codegen(Type::sir);
|
|
||||||
|
|
||||||
// check for patch
|
// check for patch
|
||||||
if (moduleinfo->fields.dim != 9)
|
else if (moduleinfo->fields.dim != 9)
|
||||||
{
|
{
|
||||||
error("object.d ModuleInfo class is incorrect");
|
error("object.d ModuleInfo class is incorrect");
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
|
|
||||||
// moduleinfo llvm struct type
|
// use the RTTIBuilder
|
||||||
const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->irtype->getPA());
|
RTTIBuilder b(moduleinfo);
|
||||||
// classinfo llvm struct type
|
|
||||||
const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->irtype->getPA());
|
|
||||||
|
|
||||||
// initializer vector
|
// some types
|
||||||
std::vector<LLConstant*> initVec;
|
const LLType* moduleinfoTy = moduleinfo->type->irtype->getPA();
|
||||||
LLConstant* c = 0;
|
const LLType* classinfoTy = ClassDeclaration::classinfo->type->irtype->getPA();
|
||||||
|
|
||||||
// vtable
|
|
||||||
c = moduleinfo->ir.irStruct->getVtblSymbol();
|
|
||||||
initVec.push_back(c);
|
|
||||||
|
|
||||||
// monitor
|
|
||||||
c = getNullPtr(getPtrToType(LLType::Int8Ty));
|
|
||||||
initVec.push_back(c);
|
|
||||||
|
|
||||||
// name
|
// name
|
||||||
char *name = toPrettyChars();
|
b.push_string(toPrettyChars());
|
||||||
c = DtoConstString(name);
|
|
||||||
initVec.push_back(c);
|
|
||||||
|
|
||||||
// importedModules[]
|
// importedModules[]
|
||||||
int aimports_dim = aimports.dim;
|
int aimports_dim = aimports.dim;
|
||||||
std::vector<LLConstant*> importInits;
|
std::vector<LLConstant*> importInits;
|
||||||
|
LLConstant* c = 0;
|
||||||
for (size_t i = 0; i < aimports.dim; i++)
|
for (size_t i = 0; i < aimports.dim; i++)
|
||||||
{
|
{
|
||||||
Module *m = (Module *)aimports.data[i];
|
Module *m = (Module *)aimports.data[i];
|
||||||
|
@ -681,8 +668,10 @@ void Module::genmoduleinfo()
|
||||||
c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
|
c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) );
|
c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) );
|
||||||
initVec.push_back(c);
|
}
|
||||||
|
b.push(c);
|
||||||
|
|
||||||
// localClasses[]
|
// localClasses[]
|
||||||
ClassDeclarations aclasses;
|
ClassDeclarations aclasses;
|
||||||
|
@ -731,13 +720,11 @@ void Module::genmoduleinfo()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(classinfoTy)) );
|
c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(classinfoTy)) );
|
||||||
initVec.push_back(c);
|
b.push(c);
|
||||||
|
|
||||||
// flags
|
// flags (4 means MIstandalone)
|
||||||
c = DtoConstUint(0);
|
unsigned mi_flags = needmoduleinfo ? 0 : 4;
|
||||||
if (!needmoduleinfo)
|
b.push_uint(mi_flags);
|
||||||
c = DtoConstUint(4); // flags (4 means MIstandalone)
|
|
||||||
initVec.push_back(c);
|
|
||||||
|
|
||||||
// function pointer type for next three fields
|
// function pointer type for next three fields
|
||||||
const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false));
|
const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false));
|
||||||
|
@ -745,25 +732,25 @@ void Module::genmoduleinfo()
|
||||||
// ctor
|
// ctor
|
||||||
llvm::Function* fctor = build_module_ctor();
|
llvm::Function* fctor = build_module_ctor();
|
||||||
c = fctor ? fctor : getNullValue(fnptrTy);
|
c = fctor ? fctor : getNullValue(fnptrTy);
|
||||||
initVec.push_back(c);
|
b.push(c);
|
||||||
|
|
||||||
// dtor
|
// dtor
|
||||||
llvm::Function* fdtor = build_module_dtor();
|
llvm::Function* fdtor = build_module_dtor();
|
||||||
c = fdtor ? fdtor : getNullValue(fnptrTy);
|
c = fdtor ? fdtor : getNullValue(fnptrTy);
|
||||||
initVec.push_back(c);
|
b.push(c);
|
||||||
|
|
||||||
// unitTest
|
// unitTest
|
||||||
llvm::Function* unittest = build_module_unittest();
|
llvm::Function* unittest = build_module_unittest();
|
||||||
c = unittest ? unittest : getNullValue(fnptrTy);
|
c = unittest ? unittest : getNullValue(fnptrTy);
|
||||||
initVec.push_back(c);
|
b.push(c);
|
||||||
|
|
||||||
// xgetMembers
|
// xgetMembers
|
||||||
c = getNullValue(getVoidPtrType());
|
c = getNullValue(getVoidPtrType());
|
||||||
initVec.push_back(c);
|
b.push(c);
|
||||||
|
|
||||||
// ictor
|
// ictor
|
||||||
c = getNullValue(fnptrTy);
|
c = getNullValue(fnptrTy);
|
||||||
initVec.push_back(c);
|
b.push(c);
|
||||||
|
|
||||||
/*Logger::println("MODULE INFO INITIALIZERS");
|
/*Logger::println("MODULE INFO INITIALIZERS");
|
||||||
for (size_t i=0; i<initVec.size(); ++i)
|
for (size_t i=0; i<initVec.size(); ++i)
|
||||||
|
@ -774,7 +761,7 @@ void Module::genmoduleinfo()
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// create initializer
|
// create initializer
|
||||||
LLConstant* constMI = llvm::ConstantStruct::get(initVec);
|
LLConstant* constMI = b.get_constant();
|
||||||
|
|
||||||
// create name
|
// create name
|
||||||
std::string MIname("_D");
|
std::string MIname("_D");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue