mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-10-22 02:37:26 +02:00
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
This commit is contained in:
+5
-5
@@ -81,19 +81,19 @@ DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key)
|
||||
llvm::Value* keyti = to_keyti(key);
|
||||
keyti = DtoBitCast(keyti, funcTy->getParamType(1));
|
||||
|
||||
// pkey param
|
||||
llvm::Value* pkey = to_pkey(key);
|
||||
pkey = DtoBitCast(pkey, funcTy->getParamType(2));
|
||||
|
||||
// valuesize param
|
||||
llvm::Value* valsize = DtoConstSize_t(getABITypeSize(DtoType(type)));
|
||||
|
||||
// pkey param
|
||||
llvm::Value* pkey = to_pkey(key);
|
||||
pkey = DtoBitCast(pkey, funcTy->getParamType(3));
|
||||
|
||||
// build arg vector
|
||||
std::vector<llvm::Value*> args;
|
||||
args.push_back(aaval);
|
||||
args.push_back(keyti);
|
||||
args.push_back(pkey);
|
||||
args.push_back(valsize);
|
||||
args.push_back(pkey);
|
||||
|
||||
// call runtime
|
||||
llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.index");
|
||||
|
||||
+25
-8
@@ -615,20 +615,17 @@ void DtoCatArrayElement(llvm::Value* arr, Expression* exp1, Expression* exp2)
|
||||
exp2 = e;
|
||||
}
|
||||
|
||||
assert(t1->ty == Tarray);
|
||||
assert(t2 == DtoDType(t1->next));
|
||||
|
||||
DValue* e1 = exp1->toElem(gIR);
|
||||
DValue* e2 = exp2->toElem(gIR);
|
||||
|
||||
llvm::Value *len1, *src1, *res;
|
||||
llvm::Value* a = e1->getRVal();
|
||||
len1 = gIR->ir->CreateLoad(DtoGEPi(a,0,0,"tmp"),"tmp");
|
||||
|
||||
len1 = DtoArrayLen(e1);
|
||||
res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp");
|
||||
|
||||
llvm::Value* mem = DtoNewDynArray(arr, res, DtoDType(t1->next), false);
|
||||
|
||||
src1 = gIR->ir->CreateLoad(DtoGEPi(a,0,1,"tmp"),"tmp");
|
||||
src1 = DtoArrayPtr(e1);
|
||||
|
||||
DtoMemCpy(mem,src1,len1);
|
||||
|
||||
@@ -641,6 +638,7 @@ void DtoCatArrayElement(llvm::Value* arr, Expression* exp1, Expression* exp2)
|
||||
// helper for eq and cmp
|
||||
static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool useti)
|
||||
{
|
||||
Logger::println("comparing arrays");
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, func);
|
||||
assert(fn);
|
||||
|
||||
@@ -648,6 +646,7 @@ static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, b
|
||||
llvm::Value* rmem;
|
||||
|
||||
// cast static arrays to dynamic ones, this turns them into DSliceValues
|
||||
Logger::println("casting to dynamic arrays");
|
||||
Type* l_ty = DtoDType(l->getType());
|
||||
Type* r_ty = DtoDType(r->getType());
|
||||
assert(l_ty->next == r_ty->next);
|
||||
@@ -659,24 +658,43 @@ static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, b
|
||||
r = DtoCastArray(r, a_ty);
|
||||
}
|
||||
|
||||
Logger::println("giving storage");
|
||||
|
||||
// we need to give slices storage
|
||||
if (l->isSlice()) {
|
||||
lmem = new llvm::AllocaInst(DtoType(l->getType()), "tmpparam", gIR->topallocapoint());
|
||||
DtoSetArray(lmem, DtoArrayLen(l), DtoArrayPtr(l));
|
||||
}
|
||||
// also null
|
||||
else if (l->isNull())
|
||||
{
|
||||
lmem = new llvm::AllocaInst(DtoType(l->getType()), "tmpparam", gIR->topallocapoint());
|
||||
DtoSetArray(lmem, llvm::Constant::getNullValue(DtoSize_t()), llvm::Constant::getNullValue(DtoType(l->getType()->next->pointerTo())));
|
||||
}
|
||||
else
|
||||
lmem = l->getRVal();
|
||||
|
||||
// and for the rvalue ...
|
||||
// we need to give slices storage
|
||||
if (r->isSlice()) {
|
||||
rmem = new llvm::AllocaInst(DtoType(r->getType()), "tmpparam", gIR->topallocapoint());
|
||||
DtoSetArray(rmem, DtoArrayLen(r), DtoArrayPtr(r));
|
||||
}
|
||||
// also null
|
||||
else if (r->isNull())
|
||||
{
|
||||
rmem = new llvm::AllocaInst(DtoType(r->getType()), "tmpparam", gIR->topallocapoint());
|
||||
DtoSetArray(rmem, llvm::Constant::getNullValue(DtoSize_t()), llvm::Constant::getNullValue(DtoType(r->getType()->next->pointerTo())));
|
||||
}
|
||||
else
|
||||
rmem = r->getRVal();
|
||||
|
||||
const llvm::Type* pt = fn->getFunctionType()->getParamType(0);
|
||||
|
||||
std::vector<llvm::Value*> args;
|
||||
Logger::cout() << "bitcasting to " << *pt << '\n';
|
||||
Logger::cout() << *lmem << '\n';
|
||||
Logger::cout() << *rmem << '\n';
|
||||
args.push_back(DtoBitCast(lmem,pt));
|
||||
args.push_back(DtoBitCast(rmem,pt));
|
||||
|
||||
@@ -905,8 +923,7 @@ DValue* DtoCastArray(DValue* u, Type* to)
|
||||
if (totype->ty == Tpointer) {
|
||||
Logger::cout() << "to pointer" << '\n';
|
||||
assert(fromtype->next == totype->next || totype->next->ty == Tvoid);
|
||||
llvm::Value* ptr = DtoGEPi(u->getRVal(),0,1,"tmp",gIR->scopebb());
|
||||
rval = new llvm::LoadInst(ptr, "tmp", gIR->scopebb());
|
||||
rval = DtoArrayPtr(u);
|
||||
if (fromtype->next != totype->next)
|
||||
rval = gIR->ir->CreateBitCast(rval, getPtrToType(llvm::Type::Int8Ty), "tmp");
|
||||
}
|
||||
|
||||
+2
-2
@@ -1094,13 +1094,13 @@ llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsi
|
||||
if (idxs.empty())
|
||||
idxs.push_back(0);
|
||||
|
||||
const llvm::Type* llt = getPtrToType(DtoType(t));
|
||||
const llvm::Type* st = DtoType(cd->type);
|
||||
if (ptr->getType() != st) {
|
||||
assert(gIR->irDsymbol[cd].irStruct->hasUnions);
|
||||
//assert(gIR->irDsymbol[cd].irStruct->hasUnions);
|
||||
ptr = gIR->ir->CreateBitCast(ptr, st, "tmp");
|
||||
}
|
||||
|
||||
const llvm::Type* llt = getPtrToType(DtoType(t));
|
||||
unsigned dataoffset = 2;
|
||||
|
||||
IrStruct* irstruct = gIR->irDsymbol[cd].irStruct;
|
||||
|
||||
+2
-2
@@ -384,11 +384,11 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||
}
|
||||
|
||||
// static ctor
|
||||
if (fdecl->isStaticCtorDeclaration()) {
|
||||
if (fdecl->isStaticCtorDeclaration() && fdecl->getModule() == gIR->dmodule) {
|
||||
gIR->ctors.push_back(fdecl);
|
||||
}
|
||||
// static dtor
|
||||
else if (fdecl->isStaticDtorDeclaration()) {
|
||||
else if (fdecl->isStaticDtorDeclaration() && fdecl->getModule() == gIR->dmodule) {
|
||||
gIR->dtors.push_back(fdecl);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -535,14 +535,14 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
}
|
||||
|
||||
// void* _aaGet(AA* aa, TypeInfo keyti, void* pkey, size_t valuesize)
|
||||
// void* _aaGet(AA* aa, TypeInfo keyti, size_t valuesize, void* pkey)
|
||||
{
|
||||
std::string fname("_aaGet");
|
||||
std::vector<const llvm::Type*> types;
|
||||
types.push_back(aaTy);
|
||||
types.push_back(typeInfoTy);
|
||||
types.push_back(voidPtrTy);
|
||||
types.push_back(sizeTy);
|
||||
types.push_back(voidPtrTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false);
|
||||
new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
}
|
||||
|
||||
@@ -153,6 +153,13 @@ void IfStatement::toIR(IRState* p)
|
||||
Logger::println("IfStatement::toIR(): %s", loc.toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
if (match)
|
||||
{
|
||||
llvm::Value* allocainst = new llvm::AllocaInst(DtoType(match->type), "._tmp_if_var", p->topallocapoint());
|
||||
gIR->irDsymbol[match].irLocal = new IrLocal(match);
|
||||
gIR->irDsymbol[match].irLocal->value = allocainst;
|
||||
}
|
||||
|
||||
DValue* cond_e = condition->toElem(p);
|
||||
llvm::Value* cond_val = cond_e->getRVal();
|
||||
delete cond_e;
|
||||
|
||||
+4
-2
@@ -212,6 +212,7 @@ DValue* VarExp::toElem(IRState* p)
|
||||
else if (vd->isParameter()) {
|
||||
Logger::println("function param");
|
||||
if (!gIR->irDsymbol[vd].getIrValue()) {
|
||||
assert(0); // should be fixed now
|
||||
// TODO: determine this properly
|
||||
// this happens when the DMD frontend generates by pointer wrappers for struct opEquals(S) and opCmp(S)
|
||||
gIR->irDsymbol[vd].getIrValue() = &p->func()->func->getArgumentList().back();
|
||||
@@ -230,8 +231,9 @@ DValue* VarExp::toElem(IRState* p)
|
||||
vd->toObjFile();
|
||||
DtoConstInitGlobal(vd);
|
||||
}
|
||||
if (!gIR->irDsymbol[vd].getIrValue() || gIR->irDsymbol[vd].getIrValue()->getType()->isAbstract()) {
|
||||
if (!gIR->irDsymbol[vd].getIrValue() || DtoType(vd->type)->isAbstract()) {
|
||||
Logger::println("global variable not resolved :/ %s", vd->toChars());
|
||||
Logger::cout() << *DtoType(vd->type) << '\n';
|
||||
assert(0);
|
||||
}
|
||||
return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true);
|
||||
@@ -1503,7 +1505,7 @@ DValue* IndexExp::toElem(IRState* p)
|
||||
arrptr = DtoGEP(l->getRVal(), zero, r->getRVal(),"tmp",p->scopebb());
|
||||
}
|
||||
else if (e1type->ty == Tarray) {
|
||||
arrptr = DtoGEP(l->getLVal(),zero,one,"tmp",p->scopebb());
|
||||
arrptr = DtoGEP(l->getRVal(),zero,one,"tmp",p->scopebb());
|
||||
arrptr = new llvm::LoadInst(arrptr,"tmp",p->scopebb());
|
||||
arrptr = new llvm::GetElementPtrInst(arrptr,r->getRVal(),"tmp",p->scopebb());
|
||||
}
|
||||
|
||||
+1
-1
@@ -605,7 +605,7 @@ llvm::Value* DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const st
|
||||
std::vector<llvm::Value*> v(2);
|
||||
v[0] = i0;
|
||||
v[1] = i1;
|
||||
//Logger::cout() << "DtoGEP: " << *ptr << '\n';
|
||||
Logger::cout() << "DtoGEP: " << *ptr << ", " << *i0 << ", " << *i1 << '\n';
|
||||
return new llvm::GetElementPtrInst(ptr, v.begin(), v.end(), var, bb?bb:gIR->scopebb());
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -324,7 +324,8 @@ void Module::genmoduleinfo()
|
||||
std::string m_name("_D");
|
||||
m_name.append(m->mangle());
|
||||
m_name.append("8__ModuleZ");
|
||||
llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
|
||||
llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
|
||||
if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
|
||||
importInits.push_back(m_gvar);
|
||||
}
|
||||
}
|
||||
@@ -336,7 +337,8 @@ void Module::genmoduleinfo()
|
||||
std::string m_name("_D");
|
||||
m_name.append(mangle());
|
||||
m_name.append("9__importsZ");
|
||||
llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
|
||||
llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
|
||||
if (!m_gvar) m_gvar = new llvm::GlobalVariable(importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
|
||||
c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType()));
|
||||
c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
|
||||
}
|
||||
@@ -539,6 +541,8 @@ void VarDeclaration::toObjFile()
|
||||
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module);
|
||||
gIR->irDsymbol[this].irGlobal->value = gvar;
|
||||
|
||||
Logger::cout() << *gvar << '\n';
|
||||
|
||||
if (static_local)
|
||||
DtoConstInitGlobal(this);
|
||||
else
|
||||
|
||||
@@ -1052,6 +1052,7 @@ void TypeInfoClassDeclaration::llvmDefine()
|
||||
// get classinfo
|
||||
assert(tinfo->ty == Tclass);
|
||||
TypeClass *tc = (TypeClass *)tinfo;
|
||||
DtoForceDeclareDsymbol(tc->sym);
|
||||
assert(gIR->irDsymbol[tc->sym].irStruct->classInfo);
|
||||
sinits.push_back(gIR->irDsymbol[tc->sym].irStruct->classInfo);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user