mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 07:30:43 +03:00
Removed KDevelop3 project files, CMake can generate them just fine!
Fixed function literals in static initializers. Changed alignment of delegates from 2*PTRSIZE to just PTRSIZE. Changed errors to go to stderr instead of stdout. Fairly major rewriting of struct/union/class handling, STILL A BIT BUGGY !!!
This commit is contained in:
parent
049e24cef8
commit
f46f865375
47 changed files with 2103 additions and 2398 deletions
|
@ -208,6 +208,9 @@ void DtoSetArray(LLValue* arr, LLValue* dim, LLValue* ptr)
|
|||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// FIXME: this looks like it could use a cleanup
|
||||
|
||||
LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
{
|
||||
Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars());
|
||||
|
@ -241,6 +244,9 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
|||
Type* arrnext = arrinittype->nextOf();
|
||||
const LLType* elemty = DtoType(arrinittype->nextOf());
|
||||
|
||||
// true if there is a mismatch with one of the initializers
|
||||
bool mismatch = false;
|
||||
|
||||
assert(arrinit->index.dim == arrinit->value.dim);
|
||||
for (unsigned i=0,j=0; i < tdim; ++i)
|
||||
{
|
||||
|
@ -292,23 +298,51 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
|||
v = DtoConstInitializer(arrinit->loc, t->nextOf(), init);
|
||||
assert(v);
|
||||
|
||||
// global arrays of unions might have type mismatch for each element
|
||||
// if there is any mismatch at all, we need to use a struct instead :/
|
||||
if (v->getType() != elemty)
|
||||
mismatch = true;
|
||||
|
||||
inits[i] = v;
|
||||
if (Logger::enabled())
|
||||
Logger::cout() << "llval: " << *v << '\n';
|
||||
}
|
||||
|
||||
Logger::println("building constant array");
|
||||
|
||||
LLConstant* constarr;
|
||||
const LLArrayType* arrty = LLArrayType::get(elemty,tdim);
|
||||
LLConstant* constarr = LLConstantArray::get(arrty, inits);
|
||||
|
||||
if (mismatch)
|
||||
{
|
||||
constarr = LLConstantStruct::get(inits);
|
||||
}
|
||||
else
|
||||
{
|
||||
constarr = LLConstantArray::get(arrty, inits);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (Logger::enabled())
|
||||
{
|
||||
Logger::cout() << "array type: " << *arrty << '\n';
|
||||
size_t n = inits.size();
|
||||
for (size_t i=0; i<n; i++)
|
||||
Logger::cout() << " init " << i << " = " << *inits[i] << '\n';
|
||||
}
|
||||
#endif
|
||||
|
||||
if (arrinittype->ty == Tsarray)
|
||||
return constarr;
|
||||
else
|
||||
assert(arrinittype->ty == Tarray);
|
||||
|
||||
LLGlobalVariable* gvar = new LLGlobalVariable(arrty,true,LLGlobalValue::InternalLinkage,constarr,".constarray",gIR->module);
|
||||
LLGlobalVariable* gvar = new LLGlobalVariable(constarr->getType(),true,LLGlobalValue::InternalLinkage,constarr,".constarray",gIR->module);
|
||||
LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
|
||||
|
||||
LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
|
||||
gep = llvm::ConstantExpr::getBitCast(gvar, getPtrToType(elemty));
|
||||
|
||||
return DtoConstSlice(DtoConstSize_t(tdim),gep);
|
||||
}
|
||||
|
||||
|
@ -794,24 +828,6 @@ LLValue* DtoDynArrayIs(TOK op, DValue* l, DValue* r)
|
|||
return (op == TOKnotidentity) ? gIR->ir->CreateNot(res) : res;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
LLConstant* DtoConstStaticArray(const LLType* t, LLConstant* c)
|
||||
{
|
||||
const LLArrayType* at = isaArray(t);
|
||||
assert(at);
|
||||
|
||||
if (isaArray(at->getElementType()))
|
||||
{
|
||||
c = DtoConstStaticArray(at->getElementType(), c);
|
||||
}
|
||||
else {
|
||||
assert(at->getElementType() == c->getType());
|
||||
}
|
||||
std::vector<LLConstant*> initvals;
|
||||
initvals.resize(at->getNumElements(), c);
|
||||
return llvm::ConstantArray::get(at, initvals);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
LLValue* DtoArrayLen(DValue* v)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue