mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-11-25 02:13:51 +01:00
[svn r93] a few fixes, some phobos additions.
some very rough groundwork for moduleinfo and classinfo support
This commit is contained in:
@@ -64,6 +64,8 @@ bool DtoIsTemplateInstance(Dsymbol* s);
|
||||
|
||||
void DtoLazyStaticInit(bool istempl, llvm::Value* gvar, Initializer* init, Type* t);
|
||||
|
||||
void DtoClassInfo(ClassDeclaration* cd);
|
||||
|
||||
// llvm wrappers
|
||||
void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes);
|
||||
bool DtoCanLoad(llvm::Value* ptr);
|
||||
|
||||
+152
@@ -91,6 +91,9 @@ Module::genobjfile()
|
||||
dsym->toObjFile();
|
||||
}
|
||||
|
||||
// generate ModuleInfo
|
||||
genmoduleinfo();
|
||||
|
||||
gTargetData = 0;
|
||||
|
||||
// emit the llvm main function if necessary
|
||||
@@ -139,6 +142,152 @@ Module::genobjfile()
|
||||
|
||||
void Module::genmoduleinfo()
|
||||
{
|
||||
// The layout is:
|
||||
// {
|
||||
// void **vptr;
|
||||
// monitor_t monitor;
|
||||
// char[] name; // class name
|
||||
// ModuleInfo importedModules[];
|
||||
// ClassInfo localClasses[];
|
||||
// uint flags; // initialization state
|
||||
// void *ctor;
|
||||
// void *dtor;
|
||||
// void *unitTest;
|
||||
// }
|
||||
|
||||
if (moduleinfo) {
|
||||
Logger::println("moduleinfo");
|
||||
}
|
||||
if (vmoduleinfo) {
|
||||
Logger::println("vmoduleinfo");
|
||||
}
|
||||
if (needModuleInfo()) {
|
||||
Logger::println("**** ATTENTION: module info is needed but skipped");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Symbol *msym = toSymbol();
|
||||
unsigned offset;
|
||||
unsigned sizeof_ModuleInfo = 12 * PTRSIZE;
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
||||
csym->Sclass = SCglobal;
|
||||
csym->Sfl = FLdata;
|
||||
|
||||
// The layout is:
|
||||
// {
|
||||
// void **vptr;
|
||||
// monitor_t monitor;
|
||||
// char[] name; // class name
|
||||
// ModuleInfo importedModules[];
|
||||
// ClassInfo localClasses[];
|
||||
// uint flags; // initialization state
|
||||
// void *ctor;
|
||||
// void *dtor;
|
||||
// void *unitTest;
|
||||
// }
|
||||
dt_t *dt = NULL;
|
||||
|
||||
if (moduleinfo)
|
||||
dtxoff(&dt, moduleinfo->toVtblSymbol(), 0, TYnptr); // vtbl for ModuleInfo
|
||||
else
|
||||
dtdword(&dt, 0); // BUG: should be an assert()
|
||||
dtdword(&dt, 0); // monitor
|
||||
|
||||
// name[]
|
||||
char *name = toPrettyChars();
|
||||
size_t namelen = strlen(name);
|
||||
dtdword(&dt, namelen);
|
||||
dtabytes(&dt, TYnptr, 0, namelen + 1, name);
|
||||
|
||||
ClassDeclarations aclasses;
|
||||
int i;
|
||||
|
||||
//printf("members->dim = %d\n", members->dim);
|
||||
for (i = 0; i < members->dim; i++)
|
||||
{
|
||||
Dsymbol *member;
|
||||
|
||||
member = (Dsymbol *)members->data[i];
|
||||
//printf("\tmember '%s'\n", member->toChars());
|
||||
member->addLocalClass(&aclasses);
|
||||
}
|
||||
|
||||
// importedModules[]
|
||||
int aimports_dim = aimports.dim;
|
||||
for (i = 0; i < aimports.dim; i++)
|
||||
{ Module *m = (Module *)aimports.data[i];
|
||||
if (!m->needModuleInfo())
|
||||
aimports_dim--;
|
||||
}
|
||||
dtdword(&dt, aimports_dim);
|
||||
if (aimports.dim)
|
||||
dtxoff(&dt, csym, sizeof_ModuleInfo, TYnptr);
|
||||
else
|
||||
dtdword(&dt, 0);
|
||||
|
||||
// localClasses[]
|
||||
dtdword(&dt, aclasses.dim);
|
||||
if (aclasses.dim)
|
||||
dtxoff(&dt, csym, sizeof_ModuleInfo + aimports_dim * PTRSIZE, TYnptr);
|
||||
else
|
||||
dtdword(&dt, 0);
|
||||
|
||||
if (needmoduleinfo)
|
||||
dtdword(&dt, 0); // flags (4 means MIstandalone)
|
||||
else
|
||||
dtdword(&dt, 4); // flags (4 means MIstandalone)
|
||||
|
||||
if (sctor)
|
||||
dtxoff(&dt, sctor, 0, TYnptr);
|
||||
else
|
||||
dtdword(&dt, 0);
|
||||
|
||||
if (sdtor)
|
||||
dtxoff(&dt, sdtor, 0, TYnptr);
|
||||
else
|
||||
dtdword(&dt, 0);
|
||||
|
||||
if (stest)
|
||||
dtxoff(&dt, stest, 0, TYnptr);
|
||||
else
|
||||
dtdword(&dt, 0);
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
||||
for (i = 0; i < aimports.dim; i++)
|
||||
{
|
||||
Module *m;
|
||||
|
||||
m = (Module *)aimports.data[i];
|
||||
if (m->needModuleInfo())
|
||||
{ Symbol *s = m->toSymbol();
|
||||
s->Sflags |= SFLweak;
|
||||
dtxoff(&dt, s, 0, TYnptr);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < aclasses.dim; i++)
|
||||
{
|
||||
ClassDeclaration *cd;
|
||||
|
||||
cd = (ClassDeclaration *)aclasses.data[i];
|
||||
dtxoff(&dt, cd->toSymbol(), 0, TYnptr);
|
||||
}
|
||||
|
||||
csym->Sdt = dt;
|
||||
#if ELFOBJ
|
||||
// Cannot be CONST because the startup code sets flag bits in it
|
||||
csym->Sseg = DATA;
|
||||
#endif
|
||||
outdata(csym);
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
||||
obj_moduleinfo(msym);
|
||||
*/
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
@@ -553,6 +702,9 @@ void ClassDeclaration::toObjFile()
|
||||
gIR->structs.pop_back();
|
||||
|
||||
llvmInProgress = false;
|
||||
|
||||
// if (ClassDeclaration::classinfo != this)
|
||||
// DtoClassInfo(this);
|
||||
}
|
||||
|
||||
/******************************************
|
||||
|
||||
+129
@@ -533,6 +533,7 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
|
||||
assert(tinfo->ty == Tstruct);
|
||||
TypeStruct *tc = (TypeStruct *)tinfo;
|
||||
StructDeclaration *sd = tc->sym;
|
||||
sd->toObjFile();
|
||||
|
||||
ClassDeclaration* base = Type::typeinfostruct;
|
||||
base->toObjFile();
|
||||
@@ -773,3 +774,131 @@ void TypeInfoTupleDeclaration::toDt(dt_t **pdt)
|
||||
dtxoff(pdt, s, 0, TYnptr); // elements.ptr
|
||||
*/
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/* ========================================================================= */
|
||||
/* CLASS INFO STUFF */
|
||||
/* ========================================================================= */
|
||||
/* ========================================================================= */
|
||||
|
||||
void DtoClassInfo(ClassDeclaration* cd)
|
||||
{
|
||||
// The layout is:
|
||||
// {
|
||||
// void **vptr;
|
||||
// monitor_t monitor;
|
||||
// byte[] initializer; // static initialization data
|
||||
// char[] name; // class name
|
||||
// void *[] vtbl;
|
||||
// Interface[] interfaces;
|
||||
// ClassInfo *base; // base class
|
||||
// void *destructor;
|
||||
// void *invariant; // class invariant
|
||||
// uint flags;
|
||||
// void *deallocator;
|
||||
// OffsetTypeInfo[] offTi;
|
||||
// void *defaultConstructor;
|
||||
// }
|
||||
|
||||
// holds the list of initializers for llvm
|
||||
std::vector<llvm::Constant*> inits;
|
||||
|
||||
ClassDeclaration* cinfo = ClassDeclaration::classinfo;
|
||||
assert(cinfo);
|
||||
Logger::println("cinfo toObj");
|
||||
cinfo->toObjFile();
|
||||
|
||||
Logger::println("cinfo toObj done");
|
||||
assert(cinfo->type->ty == Tclass);
|
||||
TypeClass* tc = (TypeClass*)cinfo->type;
|
||||
//assert(tc->llvmInit);
|
||||
//assert(cinfo->llvmInitZ);
|
||||
|
||||
cinfo = ClassDeclaration::classinfo;
|
||||
assert(cinfo->llvmInitZ);
|
||||
|
||||
/*
|
||||
llvm::Constant* c;
|
||||
|
||||
// own vtable
|
||||
c = cinfo->llvmInitZ->getOperand(0);
|
||||
assert(c);
|
||||
inits.push_back(c);
|
||||
|
||||
// monitor
|
||||
// TODO no monitors yet
|
||||
|
||||
// initializer
|
||||
c = cinfo->llvmInitZ->getOperand(1);
|
||||
inits.push_back(c);
|
||||
|
||||
// class name
|
||||
// from dmd
|
||||
char *name = cd->ident->toChars();
|
||||
size_t namelen = strlen(name);
|
||||
if (!(namelen > 9 && memcmp(name, "TypeInfo_", 9) == 0))
|
||||
{
|
||||
name = cd->toPrettyChars();
|
||||
namelen = strlen(name);
|
||||
}
|
||||
c = DtoConstString(name);
|
||||
inits.push_back(c);
|
||||
|
||||
// vtbl array
|
||||
c = cinfo->llvmInitZ->getOperand(3);
|
||||
inits.push_back(c);
|
||||
|
||||
// interfaces array
|
||||
c = cinfo->llvmInitZ->getOperand(4);
|
||||
inits.push_back(c);
|
||||
|
||||
// base classinfo
|
||||
c = cinfo->llvmInitZ->getOperand(5);
|
||||
inits.push_back(c);
|
||||
|
||||
// destructor
|
||||
c = cinfo->llvmInitZ->getOperand(5);
|
||||
inits.push_back(c);
|
||||
|
||||
// invariant
|
||||
c = cinfo->llvmInitZ->getOperand(6);
|
||||
inits.push_back(c);
|
||||
|
||||
// flags
|
||||
c = cinfo->llvmInitZ->getOperand(7);
|
||||
inits.push_back(c);
|
||||
|
||||
// allocator
|
||||
c = cinfo->llvmInitZ->getOperand(8);
|
||||
inits.push_back(c);
|
||||
|
||||
// offset typeinfo
|
||||
c = cinfo->llvmInitZ->getOperand(9);
|
||||
inits.push_back(c);
|
||||
|
||||
// default constructor
|
||||
c = cinfo->llvmInitZ->getOperand(10);
|
||||
inits.push_back(c);
|
||||
|
||||
// build the initializer
|
||||
const llvm::StructType* st = llvm::cast<llvm::StructType>(cinfo->llvmInitZ->getType());
|
||||
llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits);
|
||||
Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n';
|
||||
|
||||
assert(0);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user