mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-18 05:43:14 +01:00
Merge pull request #349 from klickverbot/fix-moduleinfo
Fixed ModuleInfo module name emission
This commit is contained in:
@@ -220,4 +220,17 @@ void printLabelName(std::ostream& target, const char* func_mangle, const char* l
|
||||
|
||||
void AppendFunctionToLLVMGlobalCtorsDtors(llvm::Function* func, const uint32_t priority, const bool isCtor);
|
||||
|
||||
template <typename T>
|
||||
LLConstant* toConstantArray(LLType* ct, LLArrayType* at, T* str, size_t len, bool nullterm = true)
|
||||
{
|
||||
std::vector<LLConstant*> vals;
|
||||
vals.reserve(len+1);
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
vals.push_back(LLConstantInt::get(ct, str[i], false));
|
||||
}
|
||||
if (nullterm)
|
||||
vals.push_back(LLConstantInt::get(ct, 0, false));
|
||||
return LLConstantArray::get(at, vals);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
128
gen/module.cpp
128
gen/module.cpp
@@ -38,9 +38,6 @@
|
||||
#include "ir/irdsymbol.h"
|
||||
#include "ir/irmodule.h"
|
||||
#include "ir/irtype.h"
|
||||
#if !MODULEINFO_IS_STRUCT
|
||||
#include "ir/irtypeclass.h"
|
||||
#endif
|
||||
#include "ir/irvar.h"
|
||||
#include "llvm/Analysis/Verifier.h"
|
||||
#include "llvm/LinkAllPasses.h"
|
||||
@@ -56,8 +53,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define NEW_MODULEINFO_LAYOUT 1
|
||||
|
||||
static llvm::Function* build_module_function(const std::string &name, const std::list<FuncDeclaration*> &funcs,
|
||||
const std::list<VarDeclaration*> &gates = std::list<VarDeclaration*>())
|
||||
{
|
||||
@@ -356,7 +351,7 @@ void Module::genmoduleinfo()
|
||||
// resolve ModuleInfo
|
||||
if (!moduleinfo)
|
||||
{
|
||||
error("object.d is missing the ModuleInfo class");
|
||||
error("object.d is missing the ModuleInfo struct");
|
||||
fatal();
|
||||
}
|
||||
// check for patch
|
||||
@@ -374,11 +369,7 @@ void Module::genmoduleinfo()
|
||||
RTTIBuilder b(moduleinfo);
|
||||
|
||||
// some types
|
||||
#if MODULEINFO_IS_STRUCT
|
||||
LLType* moduleinfoTy = moduleinfo->type->irtype->getLLType();
|
||||
#else
|
||||
LLType* moduleinfoTy = moduleinfo->type->irtype->isClass()->getMemoryLLType();
|
||||
#endif
|
||||
LLType* classinfoTy = ClassDeclaration::classinfo->type->irtype->getLLType();
|
||||
|
||||
// importedModules[]
|
||||
@@ -447,8 +438,6 @@ void Module::genmoduleinfo()
|
||||
localClasses = LLConstantArray::get(localClassesTy, classInits);
|
||||
}
|
||||
|
||||
#if NEW_MODULEINFO_LAYOUT
|
||||
|
||||
// These must match the values in druntime/src/object_.d
|
||||
#define MIstandalone 4
|
||||
#define MItlsctor 8
|
||||
@@ -521,115 +510,12 @@ void Module::genmoduleinfo()
|
||||
b.push(localClasses);
|
||||
}
|
||||
|
||||
// Put out module name as a 0-terminated string, to save bytes
|
||||
b.push(DtoConstStringPtr(toPrettyChars()));
|
||||
|
||||
#else
|
||||
// The layout is:
|
||||
// char[] name;
|
||||
// ModuleInfo[] importedModules;
|
||||
// ClassInfo[] localClasses;
|
||||
// uint flags;
|
||||
//
|
||||
// void function() ctor;
|
||||
// void function() dtor;
|
||||
// void function() unitTest;
|
||||
//
|
||||
// void* xgetMembers;
|
||||
// void function() ictor;
|
||||
//
|
||||
// version(D_Version2) {
|
||||
// void *sharedctor;
|
||||
// void *shareddtor;
|
||||
// uint index;
|
||||
// void*[1] reserved;
|
||||
// }
|
||||
|
||||
LLConstant *c = 0;
|
||||
|
||||
// name
|
||||
b.push_string(toPrettyChars());
|
||||
|
||||
// importedModules
|
||||
if (importedModules)
|
||||
{
|
||||
std::string m_name("_D");
|
||||
m_name.append(mangle());
|
||||
m_name.append("9__importsZ");
|
||||
llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
|
||||
if (!m_gvar) m_gvar = new llvm::GlobalVariable(*gIR->module, importedModulesTy, true, llvm::GlobalValue::InternalLinkage, importedModules, m_name);
|
||||
c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importedModulesTy->getElementType()));
|
||||
c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
|
||||
}
|
||||
else
|
||||
{
|
||||
c = DtoConstSlice(DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)));
|
||||
}
|
||||
b.push(c);
|
||||
|
||||
// localClasses
|
||||
if (localClasses)
|
||||
{
|
||||
std::string m_name("_D");
|
||||
m_name.append(mangle());
|
||||
m_name.append("9__classesZ");
|
||||
assert(gIR->module->getGlobalVariable(m_name) == NULL);
|
||||
llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(*gIR->module, localClassesTy, true, llvm::GlobalValue::InternalLinkage, localClasses, m_name);
|
||||
c = DtoGEPi(m_gvar, 0, 0);
|
||||
c = DtoConstSlice(DtoConstSize_t(classInits.size()), c);
|
||||
}
|
||||
else
|
||||
{
|
||||
c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(getPtrToType(classinfoTy))) );
|
||||
}
|
||||
b.push(c);
|
||||
|
||||
// flags (4 means MIstandalone)
|
||||
unsigned mi_flags = needmoduleinfo ? 0 : 4;
|
||||
b.push_uint(mi_flags);
|
||||
|
||||
// function pointer type for next three fields
|
||||
LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::getVoidTy(gIR->context()), std::vector<LLType*>(), false));
|
||||
|
||||
// ctor
|
||||
llvm::Function* fctor = build_module_shared_ctor();
|
||||
c = fctor ? fctor : getNullValue(fnptrTy);
|
||||
b.push(c);
|
||||
|
||||
// dtor
|
||||
llvm::Function* fdtor = build_module_shared_dtor();
|
||||
c = fdtor ? fdtor : getNullValue(fnptrTy);
|
||||
b.push(c);
|
||||
|
||||
// unitTest
|
||||
llvm::Function* unittest = build_module_unittest();
|
||||
c = unittest ? unittest : getNullValue(fnptrTy);
|
||||
b.push(c);
|
||||
|
||||
// xgetMembers
|
||||
c = getNullValue(getVoidPtrType());
|
||||
b.push(c);
|
||||
|
||||
// ictor
|
||||
c = getNullValue(fnptrTy);
|
||||
b.push(c);
|
||||
|
||||
// tls ctor
|
||||
fctor = build_module_ctor();
|
||||
c = fctor ? fctor : getNullValue(fnptrTy);
|
||||
b.push(c);
|
||||
|
||||
// tls dtor
|
||||
fdtor = build_module_dtor();
|
||||
c = fdtor ? fdtor : getNullValue(fnptrTy);
|
||||
b.push(c);
|
||||
|
||||
// index + reserved void*[1]
|
||||
LLType* AT = llvm::ArrayType::get(getVoidPtrType(), 2);
|
||||
c = getNullValue(AT);
|
||||
b.push(c);
|
||||
|
||||
#endif
|
||||
// Put out module name as a 0-terminated string.
|
||||
const char *name = toPrettyChars();
|
||||
const size_t len = strlen(name) + 1;
|
||||
llvm::IntegerType *it = llvm::IntegerType::getInt8Ty(gIR->context());
|
||||
llvm::ArrayType *at = llvm::ArrayType::get(it, len);
|
||||
b.push(toConstantArray(it, at, name, len, false));
|
||||
|
||||
// create and set initializer
|
||||
b.finalize(moduleInfoType, moduleInfoSymbol());
|
||||
|
||||
15
gen/toir.cpp
15
gen/toir.cpp
@@ -423,21 +423,6 @@ LLConstant* ComplexExp::toConstElem(IRState* p)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename T>
|
||||
static inline LLConstant* toConstantArray(LLType* ct, LLArrayType* at, T* str, size_t len, bool nullterm = true)
|
||||
{
|
||||
std::vector<LLConstant*> vals;
|
||||
vals.reserve(len+1);
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
vals.push_back(LLConstantInt::get(ct, str[i], false));
|
||||
}
|
||||
if (nullterm)
|
||||
vals.push_back(LLConstantInt::get(ct, 0, false));
|
||||
return LLConstantArray::get(at, vals);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue* StringExp::toElem(IRState* p)
|
||||
{
|
||||
Logger::print("StringExp::toElem: %s @ %s\n", toChars(), type->toChars());
|
||||
|
||||
Reference in New Issue
Block a user