mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
Changed: Renamed all the LLVM_Dto... helper function to just Dto...
This commit is contained in:
194
gen/arrays.c
194
gen/arrays.c
@@ -15,10 +15,10 @@
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::StructType* LLVM_DtoArrayType(Type* t)
|
||||
const llvm::StructType* DtoArrayType(Type* t)
|
||||
{
|
||||
assert(t->next);
|
||||
const llvm::Type* at = LLVM_DtoType(t->next);
|
||||
const llvm::Type* at = DtoType(t->next);
|
||||
const llvm::Type* arrty;
|
||||
|
||||
/*if (t->ty == Tsarray) {
|
||||
@@ -47,7 +47,7 @@ const llvm::StructType* LLVM_DtoArrayType(Type* t)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::ArrayType* LLVM_DtoStaticArrayType(Type* t)
|
||||
const llvm::ArrayType* DtoStaticArrayType(Type* t)
|
||||
{
|
||||
if (t->llvmType)
|
||||
return llvm::cast<llvm::ArrayType>(t->llvmType);
|
||||
@@ -55,7 +55,7 @@ const llvm::ArrayType* LLVM_DtoStaticArrayType(Type* t)
|
||||
assert(t->ty == Tsarray);
|
||||
assert(t->next);
|
||||
|
||||
const llvm::Type* at = LLVM_DtoType(t->next);
|
||||
const llvm::Type* at = DtoType(t->next);
|
||||
|
||||
TypeSArray* tsa = (TypeSArray*)t;
|
||||
assert(tsa->dim->type->isintegral());
|
||||
@@ -67,15 +67,15 @@ const llvm::ArrayType* LLVM_DtoStaticArrayType(Type* t)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoNullArray(llvm::Value* v)
|
||||
void DtoNullArray(llvm::Value* v)
|
||||
{
|
||||
assert(gIR);
|
||||
|
||||
llvm::Value* len = LLVM_DtoGEPi(v,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* len = DtoGEPi(v,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* zerolen = llvm::ConstantInt::get(len->getType()->getContainedType(0), 0, false);
|
||||
new llvm::StoreInst(zerolen, len, gIR->scopebb());
|
||||
|
||||
llvm::Value* ptr = LLVM_DtoGEPi(v,0,1,"tmp",gIR->scopebb());
|
||||
llvm::Value* ptr = DtoGEPi(v,0,1,"tmp",gIR->scopebb());
|
||||
const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(ptr->getType()->getContainedType(0));
|
||||
llvm::Value* nullptr = llvm::ConstantPointerNull::get(pty);
|
||||
new llvm::StoreInst(nullptr, ptr, gIR->scopebb());
|
||||
@@ -83,19 +83,19 @@ void LLVM_DtoNullArray(llvm::Value* v)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
|
||||
void DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
|
||||
{
|
||||
assert(gIR);
|
||||
if (dst->getType() == src->getType())
|
||||
{
|
||||
llvm::Value* ptr = LLVM_DtoGEPi(src,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* ptr = DtoGEPi(src,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
|
||||
ptr = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
ptr = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
new llvm::StoreInst(val, ptr, gIR->scopebb());
|
||||
|
||||
ptr = LLVM_DtoGEPi(src,0,1,"tmp",gIR->scopebb());
|
||||
ptr = DtoGEPi(src,0,1,"tmp",gIR->scopebb());
|
||||
val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
|
||||
ptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
|
||||
ptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
|
||||
new llvm::StoreInst(val, ptr, gIR->scopebb());
|
||||
}
|
||||
else
|
||||
@@ -109,11 +109,11 @@ void LLVM_DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
|
||||
const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(src->getType()->getContainedType(0));
|
||||
llvm::Type* dstty = llvm::PointerType::get(arrty->getElementType());
|
||||
|
||||
llvm::Value* dstlen = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* srclen = LLVM_DtoConstSize_t(arrty->getNumElements());
|
||||
llvm::Value* dstlen = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* srclen = DtoConstSize_t(arrty->getNumElements());
|
||||
new llvm::StoreInst(srclen, dstlen, gIR->scopebb());
|
||||
|
||||
llvm::Value* dstptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
|
||||
llvm::Value* dstptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
|
||||
llvm::Value* srcptr = new llvm::BitCastInst(src,dstty,"tmp",gIR->scopebb());
|
||||
new llvm::StoreInst(srcptr, dstptr, gIR->scopebb());
|
||||
}
|
||||
@@ -121,17 +121,17 @@ void LLVM_DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoArrayInit(llvm::Value* l, llvm::Value* r)
|
||||
void DtoArrayInit(llvm::Value* l, llvm::Value* r)
|
||||
{
|
||||
const llvm::PointerType* ptrty = llvm::cast<llvm::PointerType>(l->getType());
|
||||
const llvm::Type* t = ptrty->getContainedType(0);
|
||||
const llvm::ArrayType* arrty = llvm::cast_or_null<llvm::ArrayType>(t);
|
||||
if (arrty)
|
||||
{
|
||||
llvm::Value* ptr = LLVM_DtoGEPi(l,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* dim = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrty->getNumElements(), false);
|
||||
llvm::Value* ptr = DtoGEPi(l,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* dim = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false);
|
||||
llvm::Value* val = r;
|
||||
LLVM_DtoArrayInit(ptr, dim, val);
|
||||
DtoArrayInit(ptr, dim, val);
|
||||
}
|
||||
else if (llvm::isa<llvm::StructType>(t))
|
||||
{
|
||||
@@ -157,7 +157,7 @@ static size_t checkRectArrayInit(const llvm::Type* pt, constLLVMTypeP& finalty)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LLVM_DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
|
||||
void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
|
||||
{
|
||||
const llvm::Type* pt = ptr->getType()->getContainedType(0);
|
||||
const llvm::Type* t = val->getType();
|
||||
@@ -166,7 +166,7 @@ void LLVM_DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
|
||||
assert(finalTy == t);
|
||||
llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(dim);
|
||||
assert(c);
|
||||
dim = llvm::ConstantExpr::getMul(c, LLVM_DtoConstSize_t(arrsz));
|
||||
dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz));
|
||||
ptr = gIR->ir->CreateBitCast(ptr, llvm::PointerType::get(finalTy), "tmp");
|
||||
}
|
||||
else if (llvm::isa<llvm::StructType>(t)) {
|
||||
@@ -229,34 +229,34 @@ void LLVM_DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr)
|
||||
void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr)
|
||||
{
|
||||
Logger::cout() << "LLVM_DtoSetArray(" << *arr << ", " << *dim << ", " << *ptr << ")\n";
|
||||
Logger::cout() << "DtoSetArray(" << *arr << ", " << *dim << ", " << *ptr << ")\n";
|
||||
const llvm::StructType* st = llvm::cast<llvm::StructType>(arr->getType()->getContainedType(0));
|
||||
//const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(r->getType());
|
||||
|
||||
llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
|
||||
llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
|
||||
|
||||
llvm::Value* arrdim = LLVM_DtoGEP(arr,zero,zero,"tmp",gIR->scopebb());
|
||||
llvm::Value* arrdim = DtoGEP(arr,zero,zero,"tmp",gIR->scopebb());
|
||||
new llvm::StoreInst(dim, arrdim, gIR->scopebb());
|
||||
|
||||
llvm::Value* arrptr = LLVM_DtoGEP(arr,zero,one,"tmp",gIR->scopebb());
|
||||
llvm::Value* arrptr = DtoGEP(arr,zero,one,"tmp",gIR->scopebb());
|
||||
new llvm::StoreInst(ptr, arrptr, gIR->scopebb());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Constant* LLVM_DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
{
|
||||
Logger::println("arr init begin");
|
||||
Type* arrinittype = LLVM_DtoDType(arrinit->type);
|
||||
Type* arrinittype = DtoDType(arrinit->type);
|
||||
assert(arrinittype->ty == Tsarray);
|
||||
TypeSArray* t = (TypeSArray*)arrinittype;
|
||||
integer_t tdim = t->dim->toInteger();
|
||||
|
||||
std::vector<llvm::Constant*> inits(tdim, 0);
|
||||
|
||||
const llvm::Type* elemty = LLVM_DtoType(arrinittype->next);
|
||||
const llvm::Type* elemty = DtoType(arrinittype->next);
|
||||
|
||||
assert(arrinit->index.dim == arrinit->value.dim);
|
||||
for (int i=0,j=0; i < tdim; ++i)
|
||||
@@ -292,11 +292,11 @@ llvm::Constant* LLVM_DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
}
|
||||
else if (StructInitializer* si = init->isStructInitializer())
|
||||
{
|
||||
v = LLVM_DtoConstStructInitializer(si);
|
||||
v = DtoConstStructInitializer(si);
|
||||
}
|
||||
else if (ArrayInitializer* ai = init->isArrayInitializer())
|
||||
{
|
||||
v = LLVM_DtoConstArrayInitializer(ai);
|
||||
v = DtoConstArrayInitializer(ai);
|
||||
}
|
||||
else if (init->isVoidInitializer())
|
||||
{
|
||||
@@ -308,7 +308,7 @@ llvm::Constant* LLVM_DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
inits[i] = v;
|
||||
}
|
||||
|
||||
const llvm::ArrayType* arrty = LLVM_DtoStaticArrayType(t);
|
||||
const llvm::ArrayType* arrty = DtoStaticArrayType(t);
|
||||
return llvm::ConstantArray::get(arrty, inits);
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ static llvm::Value* get_slice_ptr(elem* e, llvm::Value*& sz)
|
||||
ret = e->mem;
|
||||
|
||||
size_t elembsz = gTargetData->getTypeSize(ret->getType());
|
||||
llvm::ConstantInt* elemsz = llvm::ConstantInt::get(LLVM_DtoSize_t(), elembsz, false);
|
||||
llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
|
||||
|
||||
if (llvm::isa<llvm::ConstantInt>(e->arg)) {
|
||||
sz = llvm::ConstantExpr::getMul(elemsz, llvm::cast<llvm::Constant>(e->arg));
|
||||
@@ -333,24 +333,24 @@ static llvm::Value* get_slice_ptr(elem* e, llvm::Value*& sz)
|
||||
}
|
||||
}
|
||||
else if (llvm::isa<llvm::ArrayType>(t)) {
|
||||
ret = LLVM_DtoGEPi(e->mem, 0, 0, "tmp", gIR->scopebb());
|
||||
ret = DtoGEPi(e->mem, 0, 0, "tmp", gIR->scopebb());
|
||||
|
||||
size_t elembsz = gTargetData->getTypeSize(ret->getType()->getContainedType(0));
|
||||
llvm::ConstantInt* elemsz = llvm::ConstantInt::get(LLVM_DtoSize_t(), elembsz, false);
|
||||
llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
|
||||
|
||||
size_t numelements = llvm::cast<llvm::ArrayType>(t)->getNumElements();
|
||||
llvm::ConstantInt* nelems = llvm::ConstantInt::get(LLVM_DtoSize_t(), numelements, false);
|
||||
llvm::ConstantInt* nelems = llvm::ConstantInt::get(DtoSize_t(), numelements, false);
|
||||
|
||||
sz = llvm::ConstantExpr::getMul(elemsz, nelems);
|
||||
}
|
||||
else if (llvm::isa<llvm::StructType>(t)) {
|
||||
ret = LLVM_DtoGEPi(e->mem, 0, 1, "tmp", gIR->scopebb());
|
||||
ret = DtoGEPi(e->mem, 0, 1, "tmp", gIR->scopebb());
|
||||
ret = new llvm::LoadInst(ret, "tmp", gIR->scopebb());
|
||||
|
||||
size_t elembsz = gTargetData->getTypeSize(ret->getType()->getContainedType(0));
|
||||
llvm::ConstantInt* elemsz = llvm::ConstantInt::get(LLVM_DtoSize_t(), elembsz, false);
|
||||
llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
|
||||
|
||||
llvm::Value* len = LLVM_DtoGEPi(e->mem, 0, 0, "tmp", gIR->scopebb());
|
||||
llvm::Value* len = DtoGEPi(e->mem, 0, 0, "tmp", gIR->scopebb());
|
||||
len = new llvm::LoadInst(len, "tmp", gIR->scopebb());
|
||||
sz = llvm::BinaryOperator::createMul(len,elemsz,"tmp",gIR->scopebb());
|
||||
}
|
||||
@@ -360,7 +360,7 @@ static llvm::Value* get_slice_ptr(elem* e, llvm::Value*& sz)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LLVM_DtoArrayCopy(elem* dst, elem* src)
|
||||
void DtoArrayCopy(elem* dst, elem* src)
|
||||
{
|
||||
Logger::cout() << "Array copy ((((" << *src->mem << ")))) into ((((" << *dst->mem << "))))\n";
|
||||
|
||||
@@ -387,11 +387,11 @@ void LLVM_DtoArrayCopy(elem* dst, elem* src)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
void LLVM_DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src)
|
||||
void DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src)
|
||||
{
|
||||
assert(dst->getType() == src->getType());
|
||||
size_t arrsz = gTargetData->getTypeSize(dst->getType()->getContainedType(0));
|
||||
llvm::Value* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrsz, false);
|
||||
llvm::Value* n = llvm::ConstantInt::get(DtoSize_t(), arrsz, false);
|
||||
|
||||
llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
|
||||
@@ -409,7 +409,7 @@ void LLVM_DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Constant* LLVM_DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr)
|
||||
llvm::Constant* DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr)
|
||||
{
|
||||
std::vector<const llvm::Type*> types;
|
||||
types.push_back(dim->getType());
|
||||
@@ -422,73 +422,73 @@ llvm::Constant* LLVM_DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* LLVM_DtoNewDynArray(llvm::Value* dst, llvm::Value* dim, Type* dty, bool doinit)
|
||||
llvm::Value* DtoNewDynArray(llvm::Value* dst, llvm::Value* dim, Type* dty, bool doinit)
|
||||
{
|
||||
const llvm::Type* ty = LLVM_DtoType(dty);
|
||||
const llvm::Type* ty = DtoType(dty);
|
||||
assert(ty != llvm::Type::VoidTy);
|
||||
size_t sz = gTargetData->getTypeSize(ty);
|
||||
llvm::ConstantInt* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), sz, false);
|
||||
llvm::ConstantInt* n = llvm::ConstantInt::get(DtoSize_t(), sz, false);
|
||||
llvm::Value* bytesize = (sz == 1) ? dim : llvm::BinaryOperator::createMul(n,dim,"tmp",gIR->scopebb());
|
||||
|
||||
llvm::Value* nullptr = llvm::ConstantPointerNull::get(llvm::PointerType::get(ty));
|
||||
|
||||
llvm::Value* newptr = LLVM_DtoRealloc(nullptr, bytesize);
|
||||
llvm::Value* newptr = DtoRealloc(nullptr, bytesize);
|
||||
|
||||
if (doinit) {
|
||||
elem* e = dty->defaultInit()->toElem(gIR);
|
||||
LLVM_DtoArrayInit(newptr,dim,e->getValue());
|
||||
DtoArrayInit(newptr,dim,e->getValue());
|
||||
delete e;
|
||||
}
|
||||
|
||||
llvm::Value* lenptr = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* lenptr = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
new llvm::StoreInst(dim,lenptr,gIR->scopebb());
|
||||
llvm::Value* ptrptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
|
||||
llvm::Value* ptrptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
|
||||
new llvm::StoreInst(newptr,ptrptr,gIR->scopebb());
|
||||
|
||||
return newptr;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
void LLVM_DtoResizeDynArray(llvm::Value* arr, llvm::Value* sz)
|
||||
void DtoResizeDynArray(llvm::Value* arr, llvm::Value* sz)
|
||||
{
|
||||
llvm::Value* ptr = LLVM_DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb());
|
||||
llvm::Value* ptr = DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb());
|
||||
llvm::Value* ptrld = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
|
||||
|
||||
size_t isz = gTargetData->getTypeSize(ptrld->getType()->getContainedType(0));
|
||||
llvm::ConstantInt* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), isz, false);
|
||||
llvm::ConstantInt* n = llvm::ConstantInt::get(DtoSize_t(), isz, false);
|
||||
llvm::Value* bytesz = (isz == 1) ? sz : llvm::BinaryOperator::createMul(n,sz,"tmp",gIR->scopebb());
|
||||
|
||||
llvm::Value* newptr = LLVM_DtoRealloc(ptrld, bytesz);
|
||||
llvm::Value* newptr = DtoRealloc(ptrld, bytesz);
|
||||
new llvm::StoreInst(newptr,ptr,gIR->scopebb());
|
||||
|
||||
llvm::Value* len = LLVM_DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb());
|
||||
llvm::Value* len = DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb());
|
||||
new llvm::StoreInst(sz,len,gIR->scopebb());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
void LLVM_DtoCatAssignElement(llvm::Value* arr, Expression* exp)
|
||||
void DtoCatAssignElement(llvm::Value* arr, Expression* exp)
|
||||
{
|
||||
llvm::Value* ptr = LLVM_DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb());
|
||||
llvm::Value* ptr = DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb());
|
||||
llvm::Value* idx = new llvm::LoadInst(ptr, "tmp", gIR->scopebb());
|
||||
llvm::Value* one = llvm::ConstantInt::get(idx->getType(),1,false);
|
||||
llvm::Value* len = llvm::BinaryOperator::createAdd(idx, one, "tmp", gIR->scopebb());
|
||||
LLVM_DtoResizeDynArray(arr,len);
|
||||
DtoResizeDynArray(arr,len);
|
||||
|
||||
ptr = LLVM_DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb());
|
||||
ptr = DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb());
|
||||
ptr = new llvm::LoadInst(ptr, "tmp", gIR->scopebb());
|
||||
ptr = new llvm::GetElementPtrInst(ptr, idx, "tmp", gIR->scopebb());
|
||||
|
||||
elem* e = exp->toElem(gIR);
|
||||
Type* et = LLVM_DtoDType(exp->type);
|
||||
LLVM_DtoAssign(et, ptr, e->getValue());
|
||||
Type* et = DtoDType(exp->type);
|
||||
DtoAssign(et, ptr, e->getValue());
|
||||
delete e;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
void LLVM_DtoCatArrays(llvm::Value* arr, Expression* exp1, Expression* exp2)
|
||||
void DtoCatArrays(llvm::Value* arr, Expression* exp1, Expression* exp2)
|
||||
{
|
||||
Type* t1 = LLVM_DtoDType(exp1->type);
|
||||
Type* t2 = LLVM_DtoDType(exp2->type);
|
||||
Type* t1 = DtoDType(exp1->type);
|
||||
Type* t2 = DtoDType(exp2->type);
|
||||
|
||||
assert(t1->ty == Tarray);
|
||||
assert(t1->ty == t2->ty);
|
||||
@@ -502,22 +502,22 @@ void LLVM_DtoCatArrays(llvm::Value* arr, Expression* exp1, Expression* exp2)
|
||||
delete e2;
|
||||
|
||||
llvm::Value *len1, *len2, *src1, *src2, *res;
|
||||
len1 = gIR->ir->CreateLoad(LLVM_DtoGEPi(a,0,0,"tmp"),"tmp");
|
||||
len2 = gIR->ir->CreateLoad(LLVM_DtoGEPi(b,0,0,"tmp"),"tmp");
|
||||
len1 = gIR->ir->CreateLoad(DtoGEPi(a,0,0,"tmp"),"tmp");
|
||||
len2 = gIR->ir->CreateLoad(DtoGEPi(b,0,0,"tmp"),"tmp");
|
||||
res = gIR->ir->CreateAdd(len1,len2,"tmp");
|
||||
|
||||
llvm::Value* mem = LLVM_DtoNewDynArray(arr, res, LLVM_DtoDType(t1->next), false);
|
||||
llvm::Value* mem = DtoNewDynArray(arr, res, DtoDType(t1->next), false);
|
||||
|
||||
src1 = gIR->ir->CreateLoad(LLVM_DtoGEPi(a,0,1,"tmp"),"tmp");
|
||||
src2 = gIR->ir->CreateLoad(LLVM_DtoGEPi(b,0,1,"tmp"),"tmp");
|
||||
src1 = gIR->ir->CreateLoad(DtoGEPi(a,0,1,"tmp"),"tmp");
|
||||
src2 = gIR->ir->CreateLoad(DtoGEPi(b,0,1,"tmp"),"tmp");
|
||||
|
||||
LLVM_DtoMemCpy(mem,src1,len1);
|
||||
DtoMemCpy(mem,src1,len1);
|
||||
mem = gIR->ir->CreateGEP(mem,len1,"tmp");
|
||||
LLVM_DtoMemCpy(mem,src2,len2);
|
||||
DtoMemCpy(mem,src2,len2);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* LLVM_DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
llvm::Value* DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
{
|
||||
const char* fname;
|
||||
if (op == TOKequal)
|
||||
@@ -536,7 +536,7 @@ llvm::Value* LLVM_DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
|
||||
llvm::Value* ll = new llvm::BitCastInst(l, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
|
||||
llvm::Value* rr = new llvm::BitCastInst(r, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
|
||||
llvm::Value* n = llvm::ConstantInt::get(LLVM_DtoSize_t(),gTargetData->getTypeSize(arrty),false);
|
||||
llvm::Value* n = llvm::ConstantInt::get(DtoSize_t(),gTargetData->getTypeSize(arrty),false);
|
||||
|
||||
std::vector<llvm::Value*> args;
|
||||
args.push_back(ll);
|
||||
@@ -547,7 +547,7 @@ llvm::Value* LLVM_DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
llvm::Value* DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
{
|
||||
const char* fname;
|
||||
if (op == TOKequal)
|
||||
@@ -568,7 +568,7 @@ llvm::Value* LLVM_DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
const llvm::Type* elemType = structType->getElementType(1)->getContainedType(0);
|
||||
|
||||
std::vector<const llvm::Type*> arrTypes;
|
||||
arrTypes.push_back(LLVM_DtoSize_t());
|
||||
arrTypes.push_back(DtoSize_t());
|
||||
arrTypes.push_back(llvm::PointerType::get(llvm::Type::Int8Ty));
|
||||
const llvm::StructType* arrType = llvm::StructType::get(arrTypes);
|
||||
|
||||
@@ -578,26 +578,26 @@ llvm::Value* LLVM_DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
if (arrty != arrType) {
|
||||
llmem= new llvm::AllocaInst(arrType,"tmparr",gIR->topallocapoint());
|
||||
|
||||
llvm::Value* ll = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,0, "tmp"),"tmp");
|
||||
ll = LLVM_DtoArrayCastLength(ll, elemType, llvm::Type::Int8Ty);
|
||||
llvm::Value* lllen = LLVM_DtoGEPi(llmem, 0,0, "tmp");
|
||||
llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
|
||||
ll = DtoArrayCastLength(ll, elemType, llvm::Type::Int8Ty);
|
||||
llvm::Value* lllen = DtoGEPi(llmem, 0,0, "tmp");
|
||||
gIR->ir->CreateStore(ll,lllen);
|
||||
|
||||
ll = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,1, "tmp"),"tmp");
|
||||
ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
|
||||
ll = new llvm::BitCastInst(ll, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
|
||||
llvm::Value* llptr = LLVM_DtoGEPi(llmem, 0,1, "tmp");
|
||||
llvm::Value* llptr = DtoGEPi(llmem, 0,1, "tmp");
|
||||
gIR->ir->CreateStore(ll,llptr);
|
||||
|
||||
rrmem = new llvm::AllocaInst(arrType,"tmparr",gIR->topallocapoint());
|
||||
|
||||
llvm::Value* rr = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,0, "tmp"),"tmp");
|
||||
rr = LLVM_DtoArrayCastLength(rr, elemType, llvm::Type::Int8Ty);
|
||||
llvm::Value* rrlen = LLVM_DtoGEPi(rrmem, 0,0, "tmp");
|
||||
llvm::Value* rr = gIR->ir->CreateLoad(DtoGEPi(r, 0,0, "tmp"),"tmp");
|
||||
rr = DtoArrayCastLength(rr, elemType, llvm::Type::Int8Ty);
|
||||
llvm::Value* rrlen = DtoGEPi(rrmem, 0,0, "tmp");
|
||||
gIR->ir->CreateStore(rr,rrlen);
|
||||
|
||||
rr = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,1, "tmp"),"tmp");
|
||||
rr = gIR->ir->CreateLoad(DtoGEPi(r, 0,1, "tmp"),"tmp");
|
||||
rr = new llvm::BitCastInst(rr, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
|
||||
llvm::Value* rrptr = LLVM_DtoGEPi(rrmem, 0,1, "tmp");
|
||||
llvm::Value* rrptr = DtoGEPi(rrmem, 0,1, "tmp");
|
||||
gIR->ir->CreateStore(rr,rrptr);
|
||||
}
|
||||
|
||||
@@ -608,28 +608,28 @@ llvm::Value* LLVM_DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* LLVM_DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty)
|
||||
llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty)
|
||||
{
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len");
|
||||
assert(fn);
|
||||
std::vector<llvm::Value*> args;
|
||||
args.push_back(len);
|
||||
args.push_back(llvm::ConstantInt::get(LLVM_DtoSize_t(), gTargetData->getTypeSize(elemty), false));
|
||||
args.push_back(llvm::ConstantInt::get(LLVM_DtoSize_t(), gTargetData->getTypeSize(newelemty), false));
|
||||
args.push_back(llvm::ConstantInt::get(DtoSize_t(), gTargetData->getTypeSize(elemty), false));
|
||||
args.push_back(llvm::ConstantInt::get(DtoSize_t(), gTargetData->getTypeSize(newelemty), false));
|
||||
return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* LLVM_DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
{
|
||||
llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
|
||||
|
||||
if (r == NULL) {
|
||||
llvm::Value* ll = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,0, "tmp"),"tmp");
|
||||
llvm::Value* rl = LLVM_DtoConstSize_t(0);
|
||||
llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
|
||||
llvm::Value* rl = DtoConstSize_t(0);
|
||||
llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
|
||||
|
||||
llvm::Value* lp = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,1, "tmp"),"tmp");
|
||||
llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
|
||||
const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(lp->getType());
|
||||
llvm::Value* rp = llvm::ConstantPointerNull::get(pty);
|
||||
llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
|
||||
@@ -640,12 +640,12 @@ llvm::Value* LLVM_DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
else {
|
||||
assert(l->getType() == r->getType());
|
||||
|
||||
llvm::Value* ll = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,0, "tmp"),"tmp");
|
||||
llvm::Value* rl = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,0, "tmp"),"tmp");
|
||||
llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
|
||||
llvm::Value* rl = gIR->ir->CreateLoad(DtoGEPi(r, 0,0, "tmp"),"tmp");
|
||||
llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
|
||||
|
||||
llvm::Value* lp = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,1, "tmp"),"tmp");
|
||||
llvm::Value* rp = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,1, "tmp"),"tmp");
|
||||
llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
|
||||
llvm::Value* rp = gIR->ir->CreateLoad(DtoGEPi(r, 0,1, "tmp"),"tmp");
|
||||
llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
|
||||
|
||||
llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
|
||||
@@ -654,14 +654,14 @@ llvm::Value* LLVM_DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Constant* LLVM_DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c)
|
||||
llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c)
|
||||
{
|
||||
assert(llvm::isa<llvm::ArrayType>(t));
|
||||
const llvm::ArrayType* at = llvm::cast<llvm::ArrayType>(t);
|
||||
|
||||
if (llvm::isa<llvm::ArrayType>(at->getElementType()))
|
||||
{
|
||||
c = LLVM_DtoConstStaticArray(at->getElementType(), c);
|
||||
c = DtoConstStaticArray(at->getElementType(), c);
|
||||
}
|
||||
else {
|
||||
assert(at->getElementType() == c->getType());
|
||||
|
||||
40
gen/arrays.h
40
gen/arrays.h
@@ -1,33 +1,33 @@
|
||||
#ifndef LLVMC_GEN_ARRAYS_H
|
||||
#define LLVMC_GEN_ARRAYS_H
|
||||
|
||||
const llvm::StructType* LLVM_DtoArrayType(Type* t);
|
||||
const llvm::ArrayType* LLVM_DtoStaticArrayType(Type* t);
|
||||
const llvm::StructType* DtoArrayType(Type* t);
|
||||
const llvm::ArrayType* DtoStaticArrayType(Type* t);
|
||||
|
||||
llvm::Constant* LLVM_DtoConstArrayInitializer(ArrayInitializer* si);
|
||||
llvm::Constant* LLVM_DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr);
|
||||
llvm::Constant* LLVM_DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c);
|
||||
llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* si);
|
||||
llvm::Constant* DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr);
|
||||
llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c);
|
||||
|
||||
void LLVM_DtoArrayCopy(elem* dst, elem* src);
|
||||
void LLVM_DtoArrayInit(llvm::Value* l, llvm::Value* r);
|
||||
void LLVM_DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val);
|
||||
void LLVM_DtoArrayAssign(llvm::Value* l, llvm::Value* r);
|
||||
void LLVM_DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr);
|
||||
void LLVM_DtoNullArray(llvm::Value* v);
|
||||
void DtoArrayCopy(elem* dst, elem* src);
|
||||
void DtoArrayInit(llvm::Value* l, llvm::Value* r);
|
||||
void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val);
|
||||
void DtoArrayAssign(llvm::Value* l, llvm::Value* r);
|
||||
void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr);
|
||||
void DtoNullArray(llvm::Value* v);
|
||||
|
||||
llvm::Value* LLVM_DtoNewDynArray(llvm::Value* dst, llvm::Value* dim, Type* dty, bool doinit=true);
|
||||
void LLVM_DtoResizeDynArray(llvm::Value* arr, llvm::Value* sz);
|
||||
llvm::Value* DtoNewDynArray(llvm::Value* dst, llvm::Value* dim, Type* dty, bool doinit=true);
|
||||
void DtoResizeDynArray(llvm::Value* arr, llvm::Value* sz);
|
||||
|
||||
void LLVM_DtoCatAssignElement(llvm::Value* arr, Expression* exp);
|
||||
void LLVM_DtoCatArrays(llvm::Value* arr, Expression* e1, Expression* e2);
|
||||
void DtoCatAssignElement(llvm::Value* arr, Expression* exp);
|
||||
void DtoCatArrays(llvm::Value* arr, Expression* e1, Expression* e2);
|
||||
|
||||
void LLVM_DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src);
|
||||
void DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src);
|
||||
|
||||
llvm::Value* LLVM_DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r);
|
||||
llvm::Value* DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r);
|
||||
|
||||
llvm::Value* LLVM_DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r);
|
||||
llvm::Value* LLVM_DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r);
|
||||
llvm::Value* DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r);
|
||||
llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r);
|
||||
|
||||
llvm::Value* LLVM_DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty);
|
||||
llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty);
|
||||
|
||||
#endif // LLVMC_GEN_ARRAYS_H
|
||||
|
||||
@@ -122,13 +122,15 @@ IRStruct::IRStruct(Type* t)
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IRFinally::IRFinally()
|
||||
: bb(NULL), ret(false), retval(NULL)
|
||||
{
|
||||
bb = 0;
|
||||
retbb = 0;
|
||||
}
|
||||
|
||||
IRFinally::IRFinally(llvm::BasicBlock* b)
|
||||
: bb(b), ret(false), retval(NULL)
|
||||
IRFinally::IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb)
|
||||
{
|
||||
bb = b;
|
||||
retbb = rb;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -145,11 +147,12 @@ LLVMBuilder* IRBuilderHelper::operator->()
|
||||
IRFunction::IRFunction(FuncDeclaration* fd)
|
||||
{
|
||||
decl = fd;
|
||||
Type* t = LLVM_DtoDType(fd->type);
|
||||
Type* t = DtoDType(fd->type);
|
||||
assert(t->ty == Tfunction);
|
||||
type = (TypeFunction*)t;
|
||||
func = NULL;
|
||||
allocapoint = NULL;
|
||||
finallyretval = NULL;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -69,11 +69,10 @@ public:
|
||||
struct IRFinally
|
||||
{
|
||||
llvm::BasicBlock* bb;
|
||||
bool ret;
|
||||
llvm::Value* retval;
|
||||
llvm::BasicBlock* retbb;
|
||||
|
||||
IRFinally();
|
||||
IRFinally(llvm::BasicBlock* b);
|
||||
IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb);
|
||||
};
|
||||
|
||||
// represents a function
|
||||
@@ -87,6 +86,7 @@ struct IRFunction
|
||||
// finally blocks
|
||||
typedef std::vector<IRFinally> FinallyVec;
|
||||
FinallyVec finallys;
|
||||
llvm::Value* finallyretval;
|
||||
|
||||
IRFunction(FuncDeclaration*);
|
||||
};
|
||||
|
||||
137
gen/statements.c
137
gen/statements.c
@@ -7,6 +7,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "gen/llvm.h"
|
||||
#include "llvm/Transforms/Utils/Cloning.h"
|
||||
|
||||
#include "total.h"
|
||||
#include "init.h"
|
||||
@@ -40,7 +41,6 @@ void CompoundStatement::toIR(IRState* p)
|
||||
//assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@@ -55,10 +55,10 @@ void ReturnStatement::toIR(IRState* p)
|
||||
{
|
||||
Logger::println("return type is: %s", exp->type->toChars());
|
||||
|
||||
Type* exptype = LLVM_DtoDType(exp->type);
|
||||
Type* exptype = DtoDType(exp->type);
|
||||
TY expty = exptype->ty;
|
||||
if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) {
|
||||
assert(LLVM_DtoIsPassedByRef(exptype));
|
||||
assert(DtoIsPassedByRef(exptype));
|
||||
|
||||
TypeFunction* f = p->topfunctype();
|
||||
assert(f->llvmRetInPtr && f->llvmRetArg);
|
||||
@@ -69,23 +69,23 @@ void ReturnStatement::toIR(IRState* p)
|
||||
|
||||
if (expty == Tstruct) {
|
||||
if (!e->inplace)
|
||||
LLVM_DtoStructCopy(f->llvmRetArg,e->getValue());
|
||||
DtoStructCopy(f->llvmRetArg,e->getValue());
|
||||
}
|
||||
else if (expty == Tdelegate) {
|
||||
if (!e->inplace)
|
||||
LLVM_DtoDelegateCopy(f->llvmRetArg,e->getValue());
|
||||
DtoDelegateCopy(f->llvmRetArg,e->getValue());
|
||||
}
|
||||
else if (expty == Tarray) {
|
||||
if (e->type == elem::SLICE) {
|
||||
assert(e->mem);
|
||||
LLVM_DtoSetArray(f->llvmRetArg,e->arg,e->mem);
|
||||
DtoSetArray(f->llvmRetArg,e->arg,e->mem);
|
||||
}
|
||||
else if (!e->inplace) {
|
||||
if (e->type == elem::NUL) {
|
||||
LLVM_DtoNullArray(f->llvmRetArg);
|
||||
DtoNullArray(f->llvmRetArg);
|
||||
}
|
||||
else {
|
||||
LLVM_DtoArrayAssign(f->llvmRetArg, e->getValue());
|
||||
DtoArrayAssign(f->llvmRetArg, e->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,8 +96,7 @@ void ReturnStatement::toIR(IRState* p)
|
||||
if (fin.empty())
|
||||
new llvm::ReturnInst(p->scopebb());
|
||||
else {
|
||||
new llvm::BranchInst(fin.back().bb, p->scopebb());
|
||||
fin.back().ret = true;
|
||||
new llvm::BranchInst(fin.back().retbb, p->scopebb());
|
||||
}
|
||||
delete e;
|
||||
}
|
||||
@@ -112,11 +111,11 @@ void ReturnStatement::toIR(IRState* p)
|
||||
new llvm::ReturnInst(v, p->scopebb());
|
||||
}
|
||||
else {
|
||||
llvm::Value* rettmp = new llvm::AllocaInst(v->getType(),"tmpreturn",p->topallocapoint());
|
||||
if (!p->func().finallyretval)
|
||||
p->func().finallyretval = new llvm::AllocaInst(v->getType(),"tmpreturn",p->topallocapoint());
|
||||
llvm::Value* rettmp = p->func().finallyretval;
|
||||
new llvm::StoreInst(v,rettmp,p->scopebb());
|
||||
new llvm::BranchInst(fin.back().bb, p->scopebb());
|
||||
fin.back().ret = true;
|
||||
fin.back().retval = rettmp;
|
||||
new llvm::BranchInst(fin.back().retbb, p->scopebb());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,8 +127,7 @@ void ReturnStatement::toIR(IRState* p)
|
||||
new llvm::ReturnInst(p->scopebb());
|
||||
}
|
||||
else {
|
||||
new llvm::BranchInst(fin.back().bb, p->scopebb());
|
||||
fin.back().ret = true;
|
||||
new llvm::BranchInst(fin.back().retbb, p->scopebb());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -173,30 +171,21 @@ void IfStatement::toIR(IRState* p)
|
||||
|
||||
llvm::BasicBlock* ifbb = new llvm::BasicBlock("if", gIR->topfunc(), oldend);
|
||||
llvm::BasicBlock* endbb = new llvm::BasicBlock("endif", gIR->topfunc(), oldend);
|
||||
llvm::BasicBlock* elsebb = 0;
|
||||
if (elsebody) {
|
||||
elsebb = new llvm::BasicBlock("else", gIR->topfunc(), endbb);
|
||||
}
|
||||
else {
|
||||
elsebb = endbb;
|
||||
}
|
||||
llvm::BasicBlock* elsebb = elsebody ? new llvm::BasicBlock("else", gIR->topfunc(), endbb) : endbb;
|
||||
|
||||
if (cond_val->getType() != llvm::Type::Int1Ty) {
|
||||
Logger::cout() << "if conditional: " << *cond_val << '\n';
|
||||
cond_val = LLVM_DtoBoolean(cond_val);
|
||||
cond_val = DtoBoolean(cond_val);
|
||||
}
|
||||
llvm::Value* ifgoback = new llvm::BranchInst(ifbb, elsebb, cond_val, gIR->scopebegin());
|
||||
|
||||
// replace current scope
|
||||
gIR->scope() = IRScope(ifbb,elsebb);
|
||||
|
||||
bool endifUsed = false;
|
||||
|
||||
// do scoped statements
|
||||
ifbody->toIR(p);
|
||||
if (!gIR->scopereturned()) {
|
||||
new llvm::BranchInst(endbb,gIR->scopebegin());
|
||||
endifUsed = true;
|
||||
}
|
||||
|
||||
if (elsebody) {
|
||||
@@ -205,7 +194,6 @@ void IfStatement::toIR(IRState* p)
|
||||
elsebody->toIR(p);
|
||||
if (!gIR->scopereturned()) {
|
||||
new llvm::BranchInst(endbb,gIR->scopebegin());
|
||||
endifUsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +211,7 @@ void ScopeStatement::toIR(IRState* p)
|
||||
llvm::BasicBlock* oldend = p->scopeend();
|
||||
|
||||
llvm::BasicBlock* beginbb = 0;
|
||||
|
||||
|
||||
// remove useless branches by clearing and reusing the current basicblock
|
||||
llvm::BasicBlock* bb = p->scopebegin();
|
||||
if (bb->empty()) {
|
||||
@@ -267,7 +255,7 @@ void WhileStatement::toIR(IRState* p)
|
||||
|
||||
// create the condition
|
||||
elem* cond_e = condition->toElem(p);
|
||||
llvm::Value* cond_val = LLVM_DtoBoolean(cond_e->getValue());
|
||||
llvm::Value* cond_val = DtoBoolean(cond_e->getValue());
|
||||
delete cond_e;
|
||||
|
||||
// conditional branch
|
||||
@@ -310,7 +298,7 @@ void DoStatement::toIR(IRState* p)
|
||||
|
||||
// create the condition
|
||||
elem* cond_e = condition->toElem(p);
|
||||
llvm::Value* cond_val = LLVM_DtoBoolean(cond_e->getValue());
|
||||
llvm::Value* cond_val = DtoBoolean(cond_e->getValue());
|
||||
delete cond_e;
|
||||
|
||||
// conditional branch
|
||||
@@ -349,7 +337,7 @@ void ForStatement::toIR(IRState* p)
|
||||
|
||||
// create the condition
|
||||
elem* cond_e = condition->toElem(p);
|
||||
llvm::Value* cond_val = LLVM_DtoBoolean(cond_e->getValue());
|
||||
llvm::Value* cond_val = DtoBoolean(cond_e->getValue());
|
||||
delete cond_e;
|
||||
|
||||
// conditional branch
|
||||
@@ -428,51 +416,82 @@ void OnScopeStatement::toIR(IRState* p)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void replaceFinallyBBs(std::vector<llvm::BasicBlock*>& a, std::vector<llvm::BasicBlock*>& b)
|
||||
{
|
||||
}
|
||||
|
||||
void TryFinallyStatement::toIR(IRState* p)
|
||||
{
|
||||
static int wsi = 0;
|
||||
Logger::println("TryFinallyStatement::toIR(%d): %s", wsi++, toChars());
|
||||
Logger::println("TryFinallyStatement::toIR(): %s", toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
// create basic blocks
|
||||
llvm::BasicBlock* oldend = p->scopeend();
|
||||
|
||||
llvm::BasicBlock* trybb = new llvm::BasicBlock("try", p->topfunc(), oldend);
|
||||
llvm::BasicBlock* finallybb = new llvm::BasicBlock("finally", p->topfunc(), oldend);
|
||||
llvm::BasicBlock* finallyretbb = new llvm::BasicBlock("finallyreturn", p->topfunc(), oldend);
|
||||
llvm::BasicBlock* endbb = new llvm::BasicBlock("endtryfinally", p->topfunc(), oldend);
|
||||
|
||||
// pass the previous BB into this
|
||||
assert(!gIR->scopereturned());
|
||||
new llvm::BranchInst(trybb, p->scopebb());
|
||||
|
||||
// do the try block
|
||||
p->scope() = IRScope(trybb,finallybb);
|
||||
gIR->func().finallys.push_back(IRFinally(finallybb,finallyretbb));
|
||||
IRFinally& fin = p->func().finallys.back();
|
||||
|
||||
assert(body);
|
||||
gIR->func().finallys.push_back(IRFinally(finallybb));
|
||||
body->toIR(p);
|
||||
if (!gIR->scopereturned())
|
||||
|
||||
// terminate try BB
|
||||
if (!p->scopereturned())
|
||||
new llvm::BranchInst(finallybb, p->scopebb());
|
||||
|
||||
// rewrite the scope
|
||||
p->scope() = IRScope(finallybb,endbb);
|
||||
|
||||
// do finally block
|
||||
p->scope() = IRScope(finallybb,finallyretbb);
|
||||
assert(finalbody);
|
||||
finalbody->toIR(p);
|
||||
if (gIR->func().finallys.back().ret) {
|
||||
llvm::Value* retval = p->func().finallys.back().retval;
|
||||
if (retval) {
|
||||
retval = new llvm::LoadInst(retval,"tmp",p->scopebb());
|
||||
new llvm::ReturnInst(retval, p->scopebb());
|
||||
}
|
||||
else {
|
||||
new llvm::ReturnInst(p->scopebb());
|
||||
}
|
||||
}
|
||||
else if (!gIR->scopereturned()) {
|
||||
|
||||
// terminate finally
|
||||
if (!gIR->scopereturned()) {
|
||||
new llvm::BranchInst(endbb, p->scopebb());
|
||||
}
|
||||
|
||||
p->func().finallys.pop_back();
|
||||
// do finally block (return path)
|
||||
p->scope() = IRScope(finallyretbb,endbb);
|
||||
assert(finalbody);
|
||||
finalbody->toIR(p); // hope this will work, otherwise it's time it gets fixed
|
||||
|
||||
// terminate finally (return path)
|
||||
size_t nfin = p->func().finallys.size();
|
||||
if (nfin > 1) {
|
||||
IRFinally& ofin = p->func().finallys[nfin-2];
|
||||
p->ir->CreateBr(ofin.retbb);
|
||||
}
|
||||
// no outer
|
||||
else
|
||||
{
|
||||
llvm::Value* retval = p->func().finallyretval;
|
||||
if (retval) {
|
||||
retval = p->ir->CreateLoad(retval,"tmp");
|
||||
p->ir->CreateRet(retval);
|
||||
}
|
||||
else {
|
||||
FuncDeclaration* fd = p->func().decl;
|
||||
if (fd->isMain()) {
|
||||
assert(fd->type->next->ty == Tvoid);
|
||||
p->ir->CreateRet(DtoConstInt(0));
|
||||
}
|
||||
else {
|
||||
p->ir->CreateRetVoid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rewrite the scope
|
||||
p->func().finallys.pop_back();
|
||||
p->scope() = IRScope(endbb,oldend);
|
||||
}
|
||||
|
||||
@@ -508,7 +527,7 @@ void ThrowStatement::toIR(IRState* p)
|
||||
Logger::println("*** ATTENTION: throw is not yet implemented, replacing expression with assert(0);");
|
||||
|
||||
llvm::Value* line = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false);
|
||||
LLVM_DtoAssert(NULL, line, NULL);
|
||||
DtoAssert(NULL, line, NULL);
|
||||
|
||||
/*
|
||||
assert(exp);
|
||||
@@ -653,14 +672,14 @@ void ForeachStatement::toIR(IRState* p)
|
||||
|
||||
llvm::Value* numiters = 0;
|
||||
|
||||
const llvm::Type* keytype = key ? LLVM_DtoType(key->type) : LLVM_DtoSize_t();
|
||||
const llvm::Type* keytype = key ? DtoType(key->type) : DtoSize_t();
|
||||
llvm::Value* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint());
|
||||
if (key) key->llvmValue = keyvar;
|
||||
|
||||
const llvm::Type* valtype = LLVM_DtoType(value->type);
|
||||
const llvm::Type* valtype = DtoType(value->type);
|
||||
llvm::Value* valvar = !value->isRef() ? new llvm::AllocaInst(valtype, "foreachval", p->topallocapoint()) : NULL;
|
||||
|
||||
Type* aggrtype = LLVM_DtoDType(aggr->type);
|
||||
Type* aggrtype = DtoDType(aggr->type);
|
||||
if (aggrtype->ty == Tsarray)
|
||||
{
|
||||
assert(llvm::isa<llvm::PointerType>(val->getType()));
|
||||
@@ -676,8 +695,8 @@ void ForeachStatement::toIR(IRState* p)
|
||||
val = arr->mem;
|
||||
}
|
||||
else {
|
||||
numiters = p->ir->CreateLoad(LLVM_DtoGEPi(val,0,0,"tmp",p->scopebb()));
|
||||
val = p->ir->CreateLoad(LLVM_DtoGEPi(val,0,1,"tmp",p->scopebb()));
|
||||
numiters = p->ir->CreateLoad(DtoGEPi(val,0,0,"tmp",p->scopebb()));
|
||||
val = p->ir->CreateLoad(DtoGEPi(val,0,1,"tmp",p->scopebb()));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -725,7 +744,7 @@ void ForeachStatement::toIR(IRState* p)
|
||||
llvm::Constant* zero = llvm::ConstantInt::get(keytype,0,false);
|
||||
llvm::Value* loadedKey = p->ir->CreateLoad(keyvar,"tmp");
|
||||
if (aggrtype->ty == Tsarray)
|
||||
value->llvmValue = LLVM_DtoGEP(val,zero,loadedKey,"tmp");
|
||||
value->llvmValue = DtoGEP(val,zero,loadedKey,"tmp");
|
||||
else if (aggrtype->ty == Tarray)
|
||||
value->llvmValue = new llvm::GetElementPtrInst(val,loadedKey,"tmp",p->scopebb());
|
||||
|
||||
@@ -733,7 +752,7 @@ void ForeachStatement::toIR(IRState* p)
|
||||
elem* e = new elem;
|
||||
e->mem = value->llvmValue;
|
||||
e->type = elem::VAR;
|
||||
LLVM_DtoAssign(LLVM_DtoDType(value->type), valvar, e->getValue());
|
||||
DtoAssign(DtoDType(value->type), valvar, e->getValue());
|
||||
delete e;
|
||||
value->llvmValue = valvar;
|
||||
}
|
||||
|
||||
364
gen/toir.c
364
gen/toir.c
File diff suppressed because it is too large
Load Diff
242
gen/tollvm.c
242
gen/tollvm.c
@@ -15,23 +15,23 @@
|
||||
#include "gen/elem.h"
|
||||
#include "gen/arrays.h"
|
||||
|
||||
bool LLVM_DtoIsPassedByRef(Type* type)
|
||||
bool DtoIsPassedByRef(Type* type)
|
||||
{
|
||||
TY t = LLVM_DtoDType(type)->ty;
|
||||
TY t = DtoDType(type)->ty;
|
||||
return (t == Tstruct || t == Tarray || t == Tdelegate);
|
||||
}
|
||||
|
||||
Type* LLVM_DtoDType(Type* t)
|
||||
Type* DtoDType(Type* t)
|
||||
{
|
||||
if (t->ty == Ttypedef) {
|
||||
Type* bt = t->toBasetype();
|
||||
assert(bt);
|
||||
return LLVM_DtoDType(bt);
|
||||
return DtoDType(bt);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
const llvm::Type* LLVM_DtoType(Type* t)
|
||||
const llvm::Type* DtoType(Type* t)
|
||||
{
|
||||
assert(t);
|
||||
switch (t->ty)
|
||||
@@ -78,14 +78,14 @@ const llvm::Type* LLVM_DtoType(Type* t)
|
||||
if (t->next->ty == Tvoid)
|
||||
return (const llvm::Type*)llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
else
|
||||
return (const llvm::Type*)llvm::PointerType::get(LLVM_DtoType(t->next));
|
||||
return (const llvm::Type*)llvm::PointerType::get(DtoType(t->next));
|
||||
}
|
||||
|
||||
// arrays
|
||||
case Tarray:
|
||||
return LLVM_DtoArrayType(t);
|
||||
return DtoArrayType(t);
|
||||
case Tsarray:
|
||||
return LLVM_DtoStaticArrayType(t);
|
||||
return DtoStaticArrayType(t);
|
||||
|
||||
// void
|
||||
case Tvoid:
|
||||
@@ -144,7 +144,7 @@ const llvm::Type* LLVM_DtoType(Type* t)
|
||||
case Tfunction:
|
||||
{
|
||||
if (t->llvmType == 0) {
|
||||
return LLVM_DtoFunctionType(t,NULL);
|
||||
return DtoFunctionType(t,NULL);
|
||||
}
|
||||
else {
|
||||
return t->llvmType;
|
||||
@@ -155,7 +155,7 @@ const llvm::Type* LLVM_DtoType(Type* t)
|
||||
case Tdelegate:
|
||||
{
|
||||
if (t->llvmType == 0) {
|
||||
return LLVM_DtoDelegateType(t);
|
||||
return DtoDelegateType(t);
|
||||
}
|
||||
else {
|
||||
return t->llvmType;
|
||||
@@ -169,7 +169,7 @@ const llvm::Type* LLVM_DtoType(Type* t)
|
||||
{
|
||||
Type* bt = t->toBasetype();
|
||||
assert(bt);
|
||||
return LLVM_DtoType(bt);
|
||||
return DtoType(bt);
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -181,7 +181,7 @@ const llvm::Type* LLVM_DtoType(Type* t)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::FunctionType* LLVM_DtoFunctionType(Type* type, const llvm::Type* thistype, bool ismain)
|
||||
const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype, bool ismain)
|
||||
{
|
||||
TypeFunction* f = (TypeFunction*)type;
|
||||
assert(f != 0);
|
||||
@@ -204,13 +204,13 @@ const llvm::FunctionType* LLVM_DtoFunctionType(Type* type, const llvm::Type* thi
|
||||
}
|
||||
else {
|
||||
assert(rt);
|
||||
if (LLVM_DtoIsPassedByRef(rt)) {
|
||||
rettype = llvm::PointerType::get(LLVM_DtoType(rt));
|
||||
if (DtoIsPassedByRef(rt)) {
|
||||
rettype = llvm::PointerType::get(DtoType(rt));
|
||||
actualRettype = llvm::Type::VoidTy;
|
||||
f->llvmRetInPtr = retinptr = true;
|
||||
}
|
||||
else {
|
||||
rettype = LLVM_DtoType(rt);
|
||||
rettype = DtoType(rt);
|
||||
actualRettype = rettype;
|
||||
}
|
||||
}
|
||||
@@ -234,7 +234,7 @@ const llvm::FunctionType* LLVM_DtoFunctionType(Type* type, const llvm::Type* thi
|
||||
ti->toObjFile();
|
||||
assert(ti->llvmInitZ);
|
||||
std::vector<const llvm::Type*> types;
|
||||
types.push_back(LLVM_DtoSize_t());
|
||||
types.push_back(DtoSize_t());
|
||||
types.push_back(llvm::PointerType::get(llvm::PointerType::get(ti->llvmInitZ->getType())));
|
||||
const llvm::Type* t1 = llvm::StructType::get(types);
|
||||
paramvec.push_back(llvm::PointerType::get(t1));
|
||||
@@ -246,7 +246,7 @@ const llvm::FunctionType* LLVM_DtoFunctionType(Type* type, const llvm::Type* thi
|
||||
for (int i=0; i < n; ++i) {
|
||||
Argument* arg = Argument::getNth(f->parameters, i);
|
||||
// ensure scalar
|
||||
Type* argT = LLVM_DtoDType(arg->type);
|
||||
Type* argT = DtoDType(arg->type);
|
||||
assert(argT);
|
||||
|
||||
if ((arg->storageClass & STCref) || (arg->storageClass & STCout)) {
|
||||
@@ -256,7 +256,7 @@ const llvm::FunctionType* LLVM_DtoFunctionType(Type* type, const llvm::Type* thi
|
||||
else
|
||||
arg->llvmCopy = true;
|
||||
|
||||
const llvm::Type* at = LLVM_DtoType(argT);
|
||||
const llvm::Type* at = DtoType(argT);
|
||||
if (llvm::isa<llvm::StructType>(at)) {
|
||||
Logger::println("struct param");
|
||||
paramvec.push_back(llvm::PointerType::get(at));
|
||||
@@ -300,7 +300,7 @@ const llvm::FunctionType* LLVM_DtoFunctionType(Type* type, const llvm::Type* thi
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const llvm::FunctionType* LLVM_DtoVaFunctionType(FuncDeclaration* fdecl)
|
||||
static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
|
||||
{
|
||||
TypeFunction* f = (TypeFunction*)fdecl->type;
|
||||
assert(f != 0);
|
||||
@@ -327,10 +327,10 @@ static const llvm::FunctionType* LLVM_DtoVaFunctionType(FuncDeclaration* fdecl)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::FunctionType* LLVM_DtoFunctionType(FuncDeclaration* fdecl)
|
||||
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
|
||||
{
|
||||
if ((fdecl->llvmInternal == LLVMva_start) || (fdecl->llvmInternal == LLVMva_intrinsic)) {
|
||||
return LLVM_DtoVaFunctionType(fdecl);
|
||||
return DtoVaFunctionType(fdecl);
|
||||
}
|
||||
|
||||
// type has already been resolved
|
||||
@@ -342,7 +342,7 @@ const llvm::FunctionType* LLVM_DtoFunctionType(FuncDeclaration* fdecl)
|
||||
if (fdecl->needThis()) {
|
||||
if (AggregateDeclaration* ad = fdecl->isMember()) {
|
||||
Logger::print("isMember = this is: %s\n", ad->type->toChars());
|
||||
thisty = LLVM_DtoType(ad->type);
|
||||
thisty = DtoType(ad->type);
|
||||
Logger::cout() << "this llvm type: " << *thisty << '\n';
|
||||
if (llvm::isa<llvm::StructType>(thisty) || thisty == gIR->topstruct().recty.get())
|
||||
thisty = llvm::PointerType::get(thisty);
|
||||
@@ -354,17 +354,17 @@ const llvm::FunctionType* LLVM_DtoFunctionType(FuncDeclaration* fdecl)
|
||||
thisty = llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
}
|
||||
|
||||
const llvm::FunctionType* functype = LLVM_DtoFunctionType(fdecl->type, thisty, fdecl->isMain());
|
||||
const llvm::FunctionType* functype = DtoFunctionType(fdecl->type, thisty, fdecl->isMain());
|
||||
fdecl->type->llvmType = functype;
|
||||
return functype;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::StructType* LLVM_DtoDelegateType(Type* t)
|
||||
const llvm::StructType* DtoDelegateType(Type* t)
|
||||
{
|
||||
const llvm::Type* i8ptr = llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
const llvm::Type* func = LLVM_DtoFunctionType(t->next, i8ptr);
|
||||
const llvm::Type* func = DtoFunctionType(t->next, i8ptr);
|
||||
const llvm::Type* funcptr = llvm::PointerType::get(func);
|
||||
|
||||
std::vector<const llvm::Type*> types;
|
||||
@@ -375,7 +375,7 @@ const llvm::StructType* LLVM_DtoDelegateType(Type* t)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::Type* LLVM_DtoStructType(Type* t)
|
||||
const llvm::Type* DtoStructType(Type* t)
|
||||
{
|
||||
assert(0);
|
||||
std::vector<const llvm::Type*> types;
|
||||
@@ -456,7 +456,7 @@ llvm::Function* LLVM_DeclareMemCpy64()
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoStructZeroInit(llvm::Value* v)
|
||||
llvm::Value* DtoStructZeroInit(llvm::Value* v)
|
||||
{
|
||||
assert(gIR);
|
||||
uint64_t n = gTargetData->getTypeSize(v->getType()->getContainedType(0));
|
||||
@@ -480,7 +480,7 @@ llvm::Value* LLVM_DtoStructZeroInit(llvm::Value* v)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoStructCopy(llvm::Value* dst, llvm::Value* src)
|
||||
llvm::Value* DtoStructCopy(llvm::Value* dst, llvm::Value* src)
|
||||
{
|
||||
assert(dst->getType() == src->getType());
|
||||
assert(gIR);
|
||||
@@ -504,7 +504,7 @@ llvm::Value* LLVM_DtoStructCopy(llvm::Value* dst, llvm::Value* src)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Constant* LLVM_DtoConstStructInitializer(StructInitializer* si)
|
||||
llvm::Constant* DtoConstStructInitializer(StructInitializer* si)
|
||||
{
|
||||
llvm::StructType* structtype = llvm::cast<llvm::StructType>(si->ad->llvmType);
|
||||
size_t n = structtype->getNumElements();
|
||||
@@ -519,7 +519,7 @@ llvm::Constant* LLVM_DtoConstStructInitializer(StructInitializer* si)
|
||||
assert(ini);
|
||||
|
||||
VarDeclaration* vd = (VarDeclaration*)si->vars.data[i];
|
||||
Type* vdtype = LLVM_DtoDType(vd->type);
|
||||
Type* vdtype = DtoDType(vd->type);
|
||||
assert(vd);
|
||||
Logger::println("vars[%d] = %s", i, vd->toChars());
|
||||
|
||||
@@ -534,11 +534,11 @@ llvm::Constant* LLVM_DtoConstStructInitializer(StructInitializer* si)
|
||||
}
|
||||
else if (StructInitializer* si = ini->isStructInitializer())
|
||||
{
|
||||
v = LLVM_DtoConstStructInitializer(si);
|
||||
v = DtoConstStructInitializer(si);
|
||||
}
|
||||
else if (ArrayInitializer* ai = ini->isArrayInitializer())
|
||||
{
|
||||
v = LLVM_DtoConstArrayInitializer(ai);
|
||||
v = DtoConstArrayInitializer(ai);
|
||||
}
|
||||
else if (ini->isVoidInitializer())
|
||||
{
|
||||
@@ -581,7 +581,7 @@ llvm::Constant* LLVM_DtoConstStructInitializer(StructInitializer* si)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoNullDelegate(llvm::Value* v)
|
||||
llvm::Value* DtoNullDelegate(llvm::Value* v)
|
||||
{
|
||||
assert(gIR);
|
||||
d_uns64 n = (global.params.is64bit) ? 16 : 8;
|
||||
@@ -605,7 +605,7 @@ llvm::Value* LLVM_DtoNullDelegate(llvm::Value* v)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoDelegateCopy(llvm::Value* dst, llvm::Value* src)
|
||||
llvm::Value* DtoDelegateCopy(llvm::Value* dst, llvm::Value* src)
|
||||
{
|
||||
assert(dst->getType() == src->getType());
|
||||
assert(gIR);
|
||||
@@ -630,14 +630,14 @@ llvm::Value* LLVM_DtoDelegateCopy(llvm::Value* dst, llvm::Value* src)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoCompareDelegate(TOK op, llvm::Value* lhs, llvm::Value* rhs)
|
||||
llvm::Value* DtoCompareDelegate(TOK op, llvm::Value* lhs, llvm::Value* rhs)
|
||||
{
|
||||
llvm::ICmpInst::Predicate pred = (op == TOKequal) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
|
||||
llvm::Value* l = gIR->ir->CreateLoad(LLVM_DtoGEPi(lhs,0,0,"tmp"),"tmp");
|
||||
llvm::Value* r = gIR->ir->CreateLoad(LLVM_DtoGEPi(rhs,0,0,"tmp"),"tmp");
|
||||
llvm::Value* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp");
|
||||
llvm::Value* r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,0,"tmp"),"tmp");
|
||||
llvm::Value* b1 = gIR->ir->CreateICmp(pred,l,r,"tmp");
|
||||
l = gIR->ir->CreateLoad(LLVM_DtoGEPi(lhs,0,1,"tmp"),"tmp");
|
||||
r = gIR->ir->CreateLoad(LLVM_DtoGEPi(rhs,0,1,"tmp"),"tmp");
|
||||
l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,1,"tmp"),"tmp");
|
||||
r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,1,"tmp"),"tmp");
|
||||
llvm::Value* b2 = gIR->ir->CreateICmp(pred,l,r,"tmp");
|
||||
llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
|
||||
if (op == TOKnotequal)
|
||||
@@ -647,7 +647,7 @@ llvm::Value* LLVM_DtoCompareDelegate(TOK op, llvm::Value* lhs, llvm::Value* rhs)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::GlobalValue::LinkageTypes LLVM_DtoLinkage(PROT prot, uint stc)
|
||||
llvm::GlobalValue::LinkageTypes DtoLinkage(PROT prot, uint stc)
|
||||
{
|
||||
switch(prot)
|
||||
{
|
||||
@@ -673,7 +673,7 @@ llvm::GlobalValue::LinkageTypes LLVM_DtoLinkage(PROT prot, uint stc)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
unsigned LLVM_DtoCallingConv(LINK l)
|
||||
unsigned DtoCallingConv(LINK l)
|
||||
{
|
||||
if (l == LINKc)
|
||||
return llvm::CallingConv::C;
|
||||
@@ -687,7 +687,7 @@ unsigned LLVM_DtoCallingConv(LINK l)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoPointedType(llvm::Value* ptr, llvm::Value* val)
|
||||
llvm::Value* DtoPointedType(llvm::Value* ptr, llvm::Value* val)
|
||||
{
|
||||
const llvm::Type* ptrTy = ptr->getType()->getContainedType(0);
|
||||
const llvm::Type* valTy = val->getType();
|
||||
@@ -720,7 +720,7 @@ llvm::Value* LLVM_DtoPointedType(llvm::Value* ptr, llvm::Value* val)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoBoolean(llvm::Value* val)
|
||||
llvm::Value* DtoBoolean(llvm::Value* val)
|
||||
{
|
||||
const llvm::Type* t = val->getType();
|
||||
if (t->isInteger())
|
||||
@@ -733,7 +733,7 @@ llvm::Value* LLVM_DtoBoolean(llvm::Value* val)
|
||||
}
|
||||
}
|
||||
else if (llvm::isa<llvm::PointerType>(t)) {
|
||||
const llvm::Type* st = LLVM_DtoSize_t();
|
||||
const llvm::Type* st = DtoSize_t();
|
||||
llvm::Value* ptrasint = new llvm::PtrToIntInst(val,st,"tmp",gIR->scopebb());
|
||||
llvm::Value* zero = llvm::ConstantInt::get(st, 0, false);
|
||||
return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, ptrasint, zero, "tmp", gIR->scopebb());
|
||||
@@ -748,7 +748,7 @@ llvm::Value* LLVM_DtoBoolean(llvm::Value* val)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::Type* LLVM_DtoSize_t()
|
||||
const llvm::Type* DtoSize_t()
|
||||
{
|
||||
if (global.params.is64bit)
|
||||
return llvm::Type::Int64Ty;
|
||||
@@ -758,7 +758,7 @@ const llvm::Type* LLVM_DtoSize_t()
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoMain()
|
||||
void DtoMain()
|
||||
{
|
||||
// emit main function llvm style
|
||||
// int main(int argc, char**argv, char**env);
|
||||
@@ -799,7 +799,7 @@ void LLVM_DtoMain()
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoCallClassDtors(TypeClass* tc, llvm::Value* instance)
|
||||
void DtoCallClassDtors(TypeClass* tc, llvm::Value* instance)
|
||||
{
|
||||
Array* arr = &tc->sym->dtors;
|
||||
for (size_t i=0; i<arr->dim; i++)
|
||||
@@ -812,16 +812,16 @@ void LLVM_DtoCallClassDtors(TypeClass* tc, llvm::Value* instance)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoInitClass(TypeClass* tc, llvm::Value* dst)
|
||||
void DtoInitClass(TypeClass* tc, llvm::Value* dst)
|
||||
{
|
||||
assert(gIR);
|
||||
|
||||
assert(tc->llvmType);
|
||||
uint64_t size_t_size = gTargetData->getTypeSize(LLVM_DtoSize_t());
|
||||
uint64_t size_t_size = gTargetData->getTypeSize(DtoSize_t());
|
||||
uint64_t n = gTargetData->getTypeSize(tc->llvmType) - size_t_size;
|
||||
|
||||
// set vtable field
|
||||
llvm::Value* vtblvar = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* vtblvar = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
assert(tc->sym->llvmVtbl);
|
||||
new llvm::StoreInst(tc->sym->llvmVtbl, vtblvar, gIR->scopebb());
|
||||
|
||||
@@ -833,10 +833,10 @@ void LLVM_DtoInitClass(TypeClass* tc, llvm::Value* dst)
|
||||
llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
|
||||
llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
|
||||
dstarr = LLVM_DtoGEPi(dstarr,size_t_size,"tmp",gIR->scopebb());
|
||||
dstarr = DtoGEPi(dstarr,size_t_size,"tmp",gIR->scopebb());
|
||||
|
||||
llvm::Value* srcarr = new llvm::BitCastInst(tc->llvmInit,arrty,"tmp",gIR->scopebb());
|
||||
srcarr = LLVM_DtoGEPi(srcarr,size_t_size,"tmp",gIR->scopebb());
|
||||
srcarr = DtoGEPi(srcarr,size_t_size,"tmp",gIR->scopebb());
|
||||
|
||||
llvm::Function* fn = LLVM_DeclareMemCpy32();
|
||||
std::vector<llvm::Value*> llargs;
|
||||
@@ -852,7 +852,7 @@ void LLVM_DtoInitClass(TypeClass* tc, llvm::Value* dst)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Constant* LLVM_DtoConstInitializer(Type* type, Initializer* init)
|
||||
llvm::Constant* DtoConstInitializer(Type* type, Initializer* init)
|
||||
{
|
||||
llvm::Constant* _init = 0; // may return zero
|
||||
if (!init)
|
||||
@@ -868,17 +868,17 @@ llvm::Constant* LLVM_DtoConstInitializer(Type* type, Initializer* init)
|
||||
else if (StructInitializer* si = init->isStructInitializer())
|
||||
{
|
||||
Logger::println("const struct initializer");
|
||||
_init = LLVM_DtoConstStructInitializer(si);
|
||||
_init = DtoConstStructInitializer(si);
|
||||
}
|
||||
else if (ArrayInitializer* ai = init->isArrayInitializer())
|
||||
{
|
||||
Logger::println("const array initializer");
|
||||
_init = LLVM_DtoConstArrayInitializer(ai);
|
||||
_init = DtoConstArrayInitializer(ai);
|
||||
}
|
||||
else if (init->isVoidInitializer())
|
||||
{
|
||||
Logger::println("const void initializer");
|
||||
const llvm::Type* ty = LLVM_DtoType(type);
|
||||
const llvm::Type* ty = DtoType(type);
|
||||
_init = llvm::Constant::getNullValue(ty);
|
||||
}
|
||||
else {
|
||||
@@ -889,7 +889,7 @@ llvm::Constant* LLVM_DtoConstInitializer(Type* type, Initializer* init)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoInitializer(Initializer* init)
|
||||
void DtoInitializer(Initializer* init)
|
||||
{
|
||||
if (ExpInitializer* ex = init->isExpInitializer())
|
||||
{
|
||||
@@ -904,7 +904,7 @@ void LLVM_DtoInitializer(Initializer* init)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb)
|
||||
llvm::Value* DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb)
|
||||
{
|
||||
std::vector<llvm::Value*> v(2);
|
||||
v[0] = i0;
|
||||
@@ -915,7 +915,7 @@ llvm::Value* LLVM_DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, con
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoGEP(llvm::Value* ptr, const std::vector<unsigned>& src, const std::string& var, llvm::BasicBlock* bb)
|
||||
llvm::Value* DtoGEP(llvm::Value* ptr, const std::vector<unsigned>& src, const std::string& var, llvm::BasicBlock* bb)
|
||||
{
|
||||
size_t n = src.size();
|
||||
std::vector<llvm::Value*> dst(n);
|
||||
@@ -932,14 +932,14 @@ llvm::Value* LLVM_DtoGEP(llvm::Value* ptr, const std::vector<unsigned>& src, con
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoGEPi(llvm::Value* ptr, unsigned i, const std::string& var, llvm::BasicBlock* bb)
|
||||
llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i, const std::string& var, llvm::BasicBlock* bb)
|
||||
{
|
||||
return new llvm::GetElementPtrInst(ptr, llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false), var, bb?bb:gIR->scopebb());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb)
|
||||
llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb)
|
||||
{
|
||||
std::vector<llvm::Value*> v(2);
|
||||
v[0] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i0, false);
|
||||
@@ -949,10 +949,10 @@ llvm::Value* LLVM_DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static llvm::Function* LLVM_DtoDeclareVaFunction(FuncDeclaration* fdecl)
|
||||
static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
|
||||
{
|
||||
TypeFunction* f = (TypeFunction*)LLVM_DtoDType(fdecl->type);
|
||||
const llvm::FunctionType* fty = LLVM_DtoVaFunctionType(fdecl);
|
||||
TypeFunction* f = (TypeFunction*)DtoDType(fdecl->type);
|
||||
const llvm::FunctionType* fty = DtoVaFunctionType(fdecl);
|
||||
llvm::Constant* fn = 0;
|
||||
|
||||
if (fdecl->llvmInternal == LLVMva_start) {
|
||||
@@ -975,10 +975,10 @@ static llvm::Function* LLVM_DtoDeclareVaFunction(FuncDeclaration* fdecl)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Function* LLVM_DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||
llvm::Function* DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||
{
|
||||
if ((fdecl->llvmInternal == LLVMva_start) || (fdecl->llvmInternal == LLVMva_intrinsic)) {
|
||||
return LLVM_DtoDeclareVaFunction(fdecl);
|
||||
return DtoDeclareVaFunction(fdecl);
|
||||
}
|
||||
|
||||
// mangled name
|
||||
@@ -1004,7 +1004,7 @@ llvm::Function* LLVM_DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||
}
|
||||
|
||||
// regular function
|
||||
TypeFunction* f = (TypeFunction*)LLVM_DtoDType(fdecl->type);
|
||||
TypeFunction* f = (TypeFunction*)DtoDType(fdecl->type);
|
||||
assert(f != 0);
|
||||
|
||||
if (fdecl->llvmValue != 0) {
|
||||
@@ -1025,16 +1025,16 @@ llvm::Function* LLVM_DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||
}
|
||||
|
||||
// construct function
|
||||
const llvm::FunctionType* functype = (f->llvmType == 0) ? LLVM_DtoFunctionType(fdecl) : llvm::cast<llvm::FunctionType>(f->llvmType);
|
||||
const llvm::FunctionType* functype = (f->llvmType == 0) ? DtoFunctionType(fdecl) : llvm::cast<llvm::FunctionType>(f->llvmType);
|
||||
|
||||
// make the function
|
||||
llvm::Function* func = gIR->module->getFunction(mangled_name);
|
||||
if (func == 0) {
|
||||
func = new llvm::Function(functype,LLVM_DtoLinkage(fdecl->protection, fdecl->storage_class),mangled_name,gIR->module);
|
||||
func = new llvm::Function(functype,DtoLinkage(fdecl->protection, fdecl->storage_class),mangled_name,gIR->module);
|
||||
}
|
||||
|
||||
if (fdecl->llvmInternal != LLVMintrinsic)
|
||||
func->setCallingConv(LLVM_DtoCallingConv(f->linkage));
|
||||
func->setCallingConv(DtoCallingConv(f->linkage));
|
||||
|
||||
fdecl->llvmValue = func;
|
||||
f->llvmType = functype;
|
||||
@@ -1093,7 +1093,7 @@ llvm::Function* LLVM_DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoGiveArgumentStorage(elem* l)
|
||||
void DtoGiveArgumentStorage(elem* l)
|
||||
{
|
||||
assert(l->mem == 0);
|
||||
assert(l->val);
|
||||
@@ -1107,21 +1107,21 @@ void LLVM_DtoGiveArgumentStorage(elem* l)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoRealloc(llvm::Value* ptr, const llvm::Type* ty)
|
||||
llvm::Value* DtoRealloc(llvm::Value* ptr, const llvm::Type* ty)
|
||||
{
|
||||
/*size_t sz = gTargetData->getTypeSize(ty);
|
||||
llvm::ConstantInt* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), sz, false);
|
||||
llvm::ConstantInt* n = llvm::ConstantInt::get(DtoSize_t(), sz, false);
|
||||
if (ptr == 0) {
|
||||
llvm::PointerType* i8pty = llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
ptr = llvm::ConstantPointerNull::get(i8pty);
|
||||
}
|
||||
return LLVM_DtoRealloc(ptr, n);*/
|
||||
return DtoRealloc(ptr, n);*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoRealloc(llvm::Value* ptr, llvm::Value* n)
|
||||
llvm::Value* DtoRealloc(llvm::Value* ptr, llvm::Value* n)
|
||||
{
|
||||
assert(ptr);
|
||||
assert(n);
|
||||
@@ -1146,12 +1146,12 @@ llvm::Value* LLVM_DtoRealloc(llvm::Value* ptr, llvm::Value* n)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoAssert(llvm::Value* cond, llvm::Value* loc, llvm::Value* msg)
|
||||
void DtoAssert(llvm::Value* cond, llvm::Value* loc, llvm::Value* msg)
|
||||
{
|
||||
assert(loc);
|
||||
std::vector<llvm::Value*> llargs;
|
||||
llargs.resize(3);
|
||||
llargs[0] = cond ? LLVM_DtoBoolean(cond) : llvm::ConstantInt::getFalse();
|
||||
llargs[0] = cond ? DtoBoolean(cond) : llvm::ConstantInt::getFalse();
|
||||
llargs[1] = loc;
|
||||
llargs[2] = msg ? msg : llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty));
|
||||
|
||||
@@ -1163,7 +1163,7 @@ void LLVM_DtoAssert(llvm::Value* cond, llvm::Value* loc, llvm::Value* msg)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expression* argexp)
|
||||
llvm::Value* DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expression* argexp)
|
||||
{
|
||||
llvm::Value* retval = 0;
|
||||
|
||||
@@ -1183,9 +1183,9 @@ llvm::Value* LLVM_DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expr
|
||||
return retval;
|
||||
}
|
||||
|
||||
Type* realtype = LLVM_DtoDType(argexp->type);
|
||||
Type* realtype = DtoDType(argexp->type);
|
||||
TY argty = realtype->ty;
|
||||
if (LLVM_DtoIsPassedByRef(realtype)) {
|
||||
if (DtoIsPassedByRef(realtype)) {
|
||||
if (!fnarg || !fnarg->llvmCopy) {
|
||||
retval = arg->getValue();
|
||||
assert(retval != 0);
|
||||
@@ -1194,24 +1194,24 @@ llvm::Value* LLVM_DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expr
|
||||
llvm::Value* allocaInst = 0;
|
||||
llvm::BasicBlock* entryblock = &gIR->topfunc()->front();
|
||||
//const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(arg->mem->getType());
|
||||
const llvm::Type* realtypell = LLVM_DtoType(realtype);
|
||||
const llvm::Type* realtypell = DtoType(realtype);
|
||||
const llvm::PointerType* pty = llvm::PointerType::get(realtypell);
|
||||
if (argty == Tstruct) {
|
||||
allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
|
||||
LLVM_DtoStructCopy(allocaInst,arg->mem);
|
||||
DtoStructCopy(allocaInst,arg->mem);
|
||||
}
|
||||
else if (argty == Tdelegate) {
|
||||
allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
|
||||
LLVM_DtoDelegateCopy(allocaInst,arg->mem);
|
||||
DtoDelegateCopy(allocaInst,arg->mem);
|
||||
}
|
||||
else if (argty == Tarray) {
|
||||
if (arg->type == elem::SLICE) {
|
||||
allocaInst = new llvm::AllocaInst(realtypell, "tmpparam", gIR->topallocapoint());
|
||||
LLVM_DtoSetArray(allocaInst, arg->arg, arg->mem);
|
||||
DtoSetArray(allocaInst, arg->arg, arg->mem);
|
||||
}
|
||||
else {
|
||||
allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
|
||||
LLVM_DtoArrayAssign(allocaInst,arg->mem);
|
||||
DtoArrayAssign(allocaInst,arg->mem);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1235,7 +1235,7 @@ llvm::Value* LLVM_DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expr
|
||||
if (paramtype && retval->getType() != paramtype)
|
||||
{
|
||||
assert(retval->getType() == paramtype->getContainedType(0));
|
||||
LLVM_DtoGiveArgumentStorage(arg);
|
||||
DtoGiveArgumentStorage(arg);
|
||||
new llvm::StoreInst(retval, arg->mem, gIR->scopebb());
|
||||
retval = arg->mem;
|
||||
}
|
||||
@@ -1260,7 +1260,7 @@ llvm::Value* LLVM_DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expr
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoNestedVariable(VarDeclaration* vd)
|
||||
llvm::Value* DtoNestedVariable(VarDeclaration* vd)
|
||||
{
|
||||
FuncDeclaration* fd = vd->toParent()->isFuncDeclaration();
|
||||
assert(fd != NULL);
|
||||
@@ -1270,8 +1270,8 @@ llvm::Value* LLVM_DtoNestedVariable(VarDeclaration* vd)
|
||||
|
||||
// on this stack
|
||||
if (fd == f) {
|
||||
llvm::Value* v = LLVM_DtoGEPi(vd->llvmValue,0,unsigned(vd->llvmNestedIndex),"tmp");
|
||||
if (vd->isParameter() && (vd->isRef() || vd->isOut() || LLVM_DtoIsPassedByRef(vd->type))) {
|
||||
llvm::Value* v = DtoGEPi(vd->llvmValue,0,unsigned(vd->llvmNestedIndex),"tmp");
|
||||
if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) {
|
||||
Logger::cout() << "1267 loading: " << *v << '\n';
|
||||
v = gIR->ir->CreateLoad(v,"tmp");
|
||||
}
|
||||
@@ -1294,15 +1294,15 @@ llvm::Value* LLVM_DtoNestedVariable(VarDeclaration* vd)
|
||||
|
||||
while (f) {
|
||||
if (fd == f) {
|
||||
llvm::Value* v = LLVM_DtoGEPi(ptr,0,vd->llvmNestedIndex,"tmp");
|
||||
if (vd->isParameter() && (vd->isRef() || vd->isOut() || LLVM_DtoIsPassedByRef(vd->type))) {
|
||||
llvm::Value* v = DtoGEPi(ptr,0,vd->llvmNestedIndex,"tmp");
|
||||
if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) {
|
||||
Logger::cout() << "1291 loading: " << *v << '\n';
|
||||
v = gIR->ir->CreateLoad(v,"tmp");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
ptr = LLVM_DtoGEPi(ptr,0,0,"tmp");
|
||||
ptr = DtoGEPi(ptr,0,0,"tmp");
|
||||
ptr = gIR->ir->CreateLoad(ptr,"tmp");
|
||||
}
|
||||
f = f->toParent()->isFuncDeclaration();
|
||||
@@ -1314,25 +1314,25 @@ llvm::Value* LLVM_DtoNestedVariable(VarDeclaration* vd)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoAssign(Type* t, llvm::Value* lhs, llvm::Value* rhs)
|
||||
void DtoAssign(Type* t, llvm::Value* lhs, llvm::Value* rhs)
|
||||
{
|
||||
Logger::cout() << "assignment:" << '\n' << *lhs << *rhs << '\n';
|
||||
|
||||
if (t->ty == Tstruct) {
|
||||
assert(lhs->getType() == rhs->getType());
|
||||
LLVM_DtoStructCopy(lhs,rhs);
|
||||
DtoStructCopy(lhs,rhs);
|
||||
}
|
||||
else if (t->ty == Tarray) {
|
||||
assert(lhs->getType() == rhs->getType());
|
||||
LLVM_DtoArrayAssign(lhs,rhs);
|
||||
DtoArrayAssign(lhs,rhs);
|
||||
}
|
||||
else if (t->ty == Tsarray) {
|
||||
assert(lhs->getType() == rhs->getType());
|
||||
LLVM_DtoStaticArrayCopy(lhs,rhs);
|
||||
DtoStaticArrayCopy(lhs,rhs);
|
||||
}
|
||||
else if (t->ty == Tdelegate) {
|
||||
assert(lhs->getType() == rhs->getType());
|
||||
LLVM_DtoDelegateCopy(lhs,rhs);
|
||||
DtoDelegateCopy(lhs,rhs);
|
||||
}
|
||||
else {
|
||||
assert(lhs->getType()->getContainedType(0) == rhs->getType());
|
||||
@@ -1342,33 +1342,41 @@ void LLVM_DtoAssign(Type* t, llvm::Value* lhs, llvm::Value* rhs)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::ConstantInt* LLVM_DtoConstSize_t(size_t i)
|
||||
llvm::ConstantInt* DtoConstSize_t(size_t i)
|
||||
{
|
||||
return llvm::ConstantInt::get(LLVM_DtoSize_t(), i, false);
|
||||
return llvm::ConstantInt::get(DtoSize_t(), i, false);
|
||||
}
|
||||
llvm::ConstantInt* LLVM_DtoConstUint(unsigned i)
|
||||
llvm::ConstantInt* DtoConstUint(unsigned i)
|
||||
{
|
||||
return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false);
|
||||
}
|
||||
llvm::ConstantInt* DtoConstInt(int i)
|
||||
{
|
||||
return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, true);
|
||||
}
|
||||
llvm::Constant* DtoConstBool(bool b)
|
||||
{
|
||||
return llvm::ConstantInt::get(llvm::Type::Int1Ty, b, false);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Constant* LLVM_DtoConstString(const char* str)
|
||||
llvm::Constant* DtoConstString(const char* str)
|
||||
{
|
||||
std::string s(str);
|
||||
llvm::Constant* init = llvm::ConstantArray::get(s, true);
|
||||
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
|
||||
init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module);
|
||||
llvm::Constant* idxs[2] = { LLVM_DtoConstUint(0), LLVM_DtoConstUint(0) };
|
||||
return LLVM_DtoConstSlice(
|
||||
LLVM_DtoConstSize_t(s.length()),
|
||||
llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
|
||||
return DtoConstSlice(
|
||||
DtoConstSize_t(s.length()),
|
||||
llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2)
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LLVM_DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes)
|
||||
void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes)
|
||||
{
|
||||
assert(dst->getType() == src->getType());
|
||||
|
||||
@@ -1398,7 +1406,7 @@ void LLVM_DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* LLVM_DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs)
|
||||
llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs)
|
||||
{
|
||||
Logger::println("checking for offset %u type %s:", os, t->toChars());
|
||||
LOG_SCOPE;
|
||||
@@ -1406,20 +1414,20 @@ llvm::Value* LLVM_DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type*
|
||||
if (idxs.empty())
|
||||
idxs.push_back(0);
|
||||
|
||||
const llvm::Type* llt = llvm::PointerType::get(LLVM_DtoType(t));
|
||||
const llvm::Type* llt = llvm::PointerType::get(DtoType(t));
|
||||
|
||||
for (unsigned i=0; i<sd->fields.dim; ++i) {
|
||||
VarDeclaration* vd = (VarDeclaration*)sd->fields.data[i];
|
||||
Type* vdtype = LLVM_DtoDType(vd->type);
|
||||
Type* vdtype = DtoDType(vd->type);
|
||||
Logger::println("found %u type %s", vd->offset, vdtype->toChars());
|
||||
assert(vd->llvmFieldIndex >= 0);
|
||||
if (os == vd->offset && vdtype == t) {
|
||||
idxs.push_back(vd->llvmFieldIndex);
|
||||
ptr = LLVM_DtoGEP(ptr, idxs, "tmp");
|
||||
ptr = DtoGEP(ptr, idxs, "tmp");
|
||||
if (ptr->getType() != llt)
|
||||
ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
|
||||
if (vd->llvmFieldIndexOffset)
|
||||
ptr = new llvm::GetElementPtrInst(ptr, LLVM_DtoConstUint(vd->llvmFieldIndexOffset), "tmp", gIR->scopebb());
|
||||
ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->llvmFieldIndexOffset), "tmp", gIR->scopebb());
|
||||
return ptr;
|
||||
}
|
||||
else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) {
|
||||
@@ -1428,22 +1436,22 @@ llvm::Value* LLVM_DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type*
|
||||
idxs.push_back(vd->llvmFieldIndex);
|
||||
if (vd->llvmFieldIndexOffset) {
|
||||
Logger::println("has union field offset");
|
||||
ptr = LLVM_DtoGEP(ptr, idxs, "tmp");
|
||||
ptr = DtoGEP(ptr, idxs, "tmp");
|
||||
if (ptr->getType() != llt)
|
||||
ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
|
||||
ptr = new llvm::GetElementPtrInst(ptr, LLVM_DtoConstUint(vd->llvmFieldIndexOffset), "tmp", gIR->scopebb());
|
||||
ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->llvmFieldIndexOffset), "tmp", gIR->scopebb());
|
||||
std::vector<unsigned> tmp;
|
||||
return LLVM_DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
|
||||
return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
|
||||
}
|
||||
else {
|
||||
const llvm::Type* sty = llvm::PointerType::get(LLVM_DtoType(vd->type));
|
||||
const llvm::Type* sty = llvm::PointerType::get(DtoType(vd->type));
|
||||
if (ptr->getType() != sty) {
|
||||
ptr = gIR->ir->CreateBitCast(ptr, sty, "tmp");
|
||||
std::vector<unsigned> tmp;
|
||||
return LLVM_DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
|
||||
return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
|
||||
}
|
||||
else {
|
||||
return LLVM_DtoIndexStruct(ptr, ssd, t, os-vd->offset, idxs);
|
||||
return DtoIndexStruct(ptr, ssd, t, os-vd->offset, idxs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1452,5 +1460,5 @@ llvm::Value* LLVM_DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type*
|
||||
size_t llt_sz = gTargetData->getTypeSize(llt->getContainedType(0));
|
||||
assert(os % llt_sz == 0);
|
||||
ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
|
||||
return new llvm::GetElementPtrInst(ptr, LLVM_DtoConstUint(os / llt_sz), "tmp", gIR->scopebb());
|
||||
return new llvm::GetElementPtrInst(ptr, DtoConstUint(os / llt_sz), "tmp", gIR->scopebb());
|
||||
}
|
||||
|
||||
82
gen/tollvm.h
82
gen/tollvm.h
@@ -2,69 +2,71 @@
|
||||
|
||||
struct StructInitializer;
|
||||
|
||||
const llvm::Type* LLVM_DtoType(Type* t);
|
||||
bool LLVM_DtoIsPassedByRef(Type* type);
|
||||
Type* LLVM_DtoDType(Type* t);
|
||||
const llvm::Type* DtoType(Type* t);
|
||||
bool DtoIsPassedByRef(Type* type);
|
||||
Type* DtoDType(Type* t);
|
||||
|
||||
const llvm::Type* LLVM_DtoStructType(Type* t);
|
||||
llvm::Value* LLVM_DtoStructZeroInit(llvm::Value* v);
|
||||
llvm::Value* LLVM_DtoStructCopy(llvm::Value* dst, llvm::Value* src);
|
||||
llvm::Constant* LLVM_DtoConstStructInitializer(StructInitializer* si);
|
||||
const llvm::Type* DtoStructType(Type* t);
|
||||
llvm::Value* DtoStructZeroInit(llvm::Value* v);
|
||||
llvm::Value* DtoStructCopy(llvm::Value* dst, llvm::Value* src);
|
||||
llvm::Constant* DtoConstStructInitializer(StructInitializer* si);
|
||||
|
||||
const llvm::FunctionType* LLVM_DtoFunctionType(Type* t, const llvm::Type* thistype, bool ismain = false);
|
||||
const llvm::FunctionType* LLVM_DtoFunctionType(FuncDeclaration* fdecl);
|
||||
llvm::Function* LLVM_DtoDeclareFunction(FuncDeclaration* fdecl);
|
||||
const llvm::FunctionType* DtoFunctionType(Type* t, const llvm::Type* thistype, bool ismain = false);
|
||||
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl);
|
||||
llvm::Function* DtoDeclareFunction(FuncDeclaration* fdecl);
|
||||
|
||||
const llvm::StructType* LLVM_DtoDelegateType(Type* t);
|
||||
llvm::Value* LLVM_DtoNullDelegate(llvm::Value* v);
|
||||
llvm::Value* LLVM_DtoDelegateCopy(llvm::Value* dst, llvm::Value* src);
|
||||
llvm::Value* LLVM_DtoCompareDelegate(TOK op, llvm::Value* lhs, llvm::Value* rhs);
|
||||
const llvm::StructType* DtoDelegateType(Type* t);
|
||||
llvm::Value* DtoNullDelegate(llvm::Value* v);
|
||||
llvm::Value* DtoDelegateCopy(llvm::Value* dst, llvm::Value* src);
|
||||
llvm::Value* DtoCompareDelegate(TOK op, llvm::Value* lhs, llvm::Value* rhs);
|
||||
|
||||
llvm::GlobalValue::LinkageTypes LLVM_DtoLinkage(PROT prot, uint stc);
|
||||
unsigned LLVM_DtoCallingConv(LINK l);
|
||||
llvm::GlobalValue::LinkageTypes DtoLinkage(PROT prot, uint stc);
|
||||
unsigned DtoCallingConv(LINK l);
|
||||
|
||||
llvm::Value* LLVM_DtoPointedType(llvm::Value* ptr, llvm::Value* val);
|
||||
llvm::Value* LLVM_DtoBoolean(llvm::Value* val);
|
||||
llvm::Value* DtoPointedType(llvm::Value* ptr, llvm::Value* val);
|
||||
llvm::Value* DtoBoolean(llvm::Value* val);
|
||||
|
||||
const llvm::Type* LLVM_DtoSize_t();
|
||||
const llvm::Type* DtoSize_t();
|
||||
|
||||
void LLVM_DtoMain();
|
||||
void DtoMain();
|
||||
|
||||
void LLVM_DtoCallClassDtors(TypeClass* tc, llvm::Value* instance);
|
||||
void LLVM_DtoInitClass(TypeClass* tc, llvm::Value* dst);
|
||||
void DtoCallClassDtors(TypeClass* tc, llvm::Value* instance);
|
||||
void DtoInitClass(TypeClass* tc, llvm::Value* dst);
|
||||
|
||||
llvm::Constant* LLVM_DtoConstInitializer(Type* type, Initializer* init);
|
||||
void LLVM_DtoInitializer(Initializer* init);
|
||||
llvm::Constant* DtoConstInitializer(Type* type, Initializer* init);
|
||||
void DtoInitializer(Initializer* init);
|
||||
|
||||
llvm::Function* LLVM_DeclareMemSet32();
|
||||
llvm::Function* LLVM_DeclareMemSet64();
|
||||
llvm::Function* LLVM_DeclareMemCpy32();
|
||||
llvm::Function* LLVM_DeclareMemCpy64();
|
||||
|
||||
llvm::Value* LLVM_DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
llvm::Value* LLVM_DtoGEP(llvm::Value* ptr, const std::vector<unsigned>& src, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
llvm::Value* LLVM_DtoGEPi(llvm::Value* ptr, unsigned i0, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
llvm::Value* LLVM_DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
llvm::Value* DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
llvm::Value* DtoGEP(llvm::Value* ptr, const std::vector<unsigned>& src, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i0, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
|
||||
void LLVM_DtoGiveArgumentStorage(elem* e);
|
||||
void DtoGiveArgumentStorage(elem* e);
|
||||
|
||||
llvm::Value* LLVM_DtoRealloc(llvm::Value* ptr, const llvm::Type* ty);
|
||||
llvm::Value* LLVM_DtoRealloc(llvm::Value* ptr, llvm::Value* len);
|
||||
llvm::Value* DtoRealloc(llvm::Value* ptr, const llvm::Type* ty);
|
||||
llvm::Value* DtoRealloc(llvm::Value* ptr, llvm::Value* len);
|
||||
|
||||
void LLVM_DtoAssert(llvm::Value* cond, llvm::Value* loc, llvm::Value* msg);
|
||||
void DtoAssert(llvm::Value* cond, llvm::Value* loc, llvm::Value* msg);
|
||||
|
||||
llvm::Value* LLVM_DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expression* argexp);
|
||||
llvm::Value* DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expression* argexp);
|
||||
|
||||
llvm::Value* LLVM_DtoNestedVariable(VarDeclaration* vd);
|
||||
llvm::Value* DtoNestedVariable(VarDeclaration* vd);
|
||||
|
||||
void LLVM_DtoAssign(Type* lhsType, llvm::Value* lhs, llvm::Value* rhs);
|
||||
void DtoAssign(Type* lhsType, llvm::Value* lhs, llvm::Value* rhs);
|
||||
|
||||
llvm::ConstantInt* LLVM_DtoConstSize_t(size_t);
|
||||
llvm::ConstantInt* LLVM_DtoConstUint(unsigned i);
|
||||
llvm::Constant* LLVM_DtoConstString(const char*);
|
||||
llvm::ConstantInt* DtoConstSize_t(size_t);
|
||||
llvm::ConstantInt* DtoConstUint(unsigned i);
|
||||
llvm::ConstantInt* DtoConstInt(int i);
|
||||
llvm::Constant* DtoConstString(const char*);
|
||||
llvm::Constant* DtoConstBool(bool);
|
||||
|
||||
void LLVM_DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes);
|
||||
void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes);
|
||||
|
||||
llvm::Value* LLVM_DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs);
|
||||
llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs);
|
||||
|
||||
#include "enums.h"
|
||||
|
||||
42
gen/toobj.c
42
gen/toobj.c
@@ -86,7 +86,7 @@ Module::genobjfile()
|
||||
|
||||
// emit the llvm main function if necessary
|
||||
if (ir.emitMain) {
|
||||
LLVM_DtoMain();
|
||||
DtoMain();
|
||||
}
|
||||
|
||||
// verify the llvm
|
||||
@@ -157,7 +157,7 @@ void InterfaceDeclaration::toObjFile()
|
||||
|
||||
void StructDeclaration::toObjFile()
|
||||
{
|
||||
TypeStruct* ts = (TypeStruct*)LLVM_DtoDType(type);
|
||||
TypeStruct* ts = (TypeStruct*)DtoDType(type);
|
||||
if (llvmType != 0)
|
||||
return;
|
||||
|
||||
@@ -200,14 +200,14 @@ void StructDeclaration::toObjFile()
|
||||
if (lastoffset == (unsigned)-1) {
|
||||
lastoffset = i->first;
|
||||
assert(lastoffset == 0);
|
||||
fieldtype = LLVM_DtoType(i->second.var->type);
|
||||
fieldtype = DtoType(i->second.var->type);
|
||||
fieldinit = i->second.init;
|
||||
prevsize = gTargetData->getTypeSize(fieldtype);
|
||||
i->second.var->llvmFieldIndex = idx;
|
||||
}
|
||||
// colliding offset?
|
||||
else if (lastoffset == i->first) {
|
||||
const llvm::Type* t = LLVM_DtoType(i->second.var->type);
|
||||
const llvm::Type* t = DtoType(i->second.var->type);
|
||||
size_t s = gTargetData->getTypeSize(t);
|
||||
if (s > prevsize) {
|
||||
fieldpad += s - prevsize;
|
||||
@@ -218,7 +218,7 @@ void StructDeclaration::toObjFile()
|
||||
}
|
||||
// intersecting offset?
|
||||
else if (i->first < (lastoffset + prevsize)) {
|
||||
const llvm::Type* t = LLVM_DtoType(i->second.var->type);
|
||||
const llvm::Type* t = DtoType(i->second.var->type);
|
||||
size_t s = gTargetData->getTypeSize(t);
|
||||
assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size
|
||||
llvmHasUnions = true;
|
||||
@@ -243,7 +243,7 @@ void StructDeclaration::toObjFile()
|
||||
|
||||
// start new
|
||||
lastoffset = i->first;
|
||||
fieldtype = LLVM_DtoType(i->second.var->type);
|
||||
fieldtype = DtoType(i->second.var->type);
|
||||
fieldinit = i->second.init;
|
||||
prevsize = gTargetData->getTypeSize(fieldtype);
|
||||
i->second.var->llvmFieldIndex = idx;
|
||||
@@ -389,7 +389,7 @@ static void LLVM_AddBaseClassData(BaseClasses* bcs)
|
||||
|
||||
void ClassDeclaration::toObjFile()
|
||||
{
|
||||
TypeClass* ts = (TypeClass*)LLVM_DtoDType(type);
|
||||
TypeClass* ts = (TypeClass*)DtoDType(type);
|
||||
if (ts->llvmType != 0 || llvmInProgress)
|
||||
return;
|
||||
|
||||
@@ -423,7 +423,7 @@ void ClassDeclaration::toObjFile()
|
||||
|
||||
// fill out fieldtypes/inits
|
||||
for (IRStruct::OffsetMap::iterator i=gIR->topstruct().offsets.begin(); i!=gIR->topstruct().offsets.end(); ++i) {
|
||||
fieldtypes.push_back(LLVM_DtoType(i->second.var->type));
|
||||
fieldtypes.push_back(DtoType(i->second.var->type));
|
||||
fieldinits.push_back(i->second.init);
|
||||
}
|
||||
|
||||
@@ -574,11 +574,11 @@ void VarDeclaration::toObjFile()
|
||||
if (parent && parent->isFuncDeclaration())
|
||||
_linkage = llvm::GlobalValue::InternalLinkage;
|
||||
else
|
||||
_linkage = LLVM_DtoLinkage(protection, storage_class);
|
||||
_linkage = DtoLinkage(protection, storage_class);
|
||||
|
||||
Type* t = LLVM_DtoDType(type);
|
||||
Type* t = DtoDType(type);
|
||||
|
||||
const llvm::Type* _type = LLVM_DtoType(t);
|
||||
const llvm::Type* _type = DtoType(t);
|
||||
assert(_type);
|
||||
|
||||
llvm::Constant* _init = 0;
|
||||
@@ -593,7 +593,7 @@ void VarDeclaration::toObjFile()
|
||||
// if extern don't emit initializer
|
||||
if (!(storage_class & STCextern))
|
||||
{
|
||||
_init = LLVM_DtoConstInitializer(t, init);
|
||||
_init = DtoConstInitializer(t, init);
|
||||
|
||||
//Logger::cout() << "initializer: " << *_init << '\n';
|
||||
if (_type != _init->getType()) {
|
||||
@@ -614,7 +614,7 @@ void VarDeclaration::toObjFile()
|
||||
// array single value init
|
||||
else if (llvm::isa<llvm::ArrayType>(_type))
|
||||
{
|
||||
_init = LLVM_DtoConstStaticArray(_type, _init);
|
||||
_init = DtoConstStaticArray(_type, _init);
|
||||
}
|
||||
else {
|
||||
Logger::cout() << "Unexpected initializer type: " << *_type << '\n';
|
||||
@@ -637,10 +637,10 @@ void VarDeclaration::toObjFile()
|
||||
{
|
||||
Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset);
|
||||
|
||||
Type* t = LLVM_DtoDType(type);
|
||||
const llvm::Type* _type = LLVM_DtoType(t);
|
||||
Type* t = DtoDType(type);
|
||||
const llvm::Type* _type = DtoType(t);
|
||||
|
||||
llvm::Constant*_init = LLVM_DtoConstInitializer(t, init);
|
||||
llvm::Constant*_init = DtoConstInitializer(t, init);
|
||||
assert(_init);
|
||||
Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n';
|
||||
if (_type != _init->getType())
|
||||
@@ -716,7 +716,7 @@ void FuncDeclaration::toObjFile()
|
||||
return;
|
||||
}
|
||||
|
||||
Type* t = LLVM_DtoDType(type);
|
||||
Type* t = DtoDType(type);
|
||||
TypeFunction* f = (TypeFunction*)t;
|
||||
|
||||
bool declareOnly = false;
|
||||
@@ -736,7 +736,7 @@ void FuncDeclaration::toObjFile()
|
||||
}
|
||||
}
|
||||
|
||||
llvm::Function* func = LLVM_DtoDeclareFunction(this);
|
||||
llvm::Function* func = DtoDeclareFunction(this);
|
||||
|
||||
if (declareOnly)
|
||||
return;
|
||||
@@ -830,7 +830,7 @@ void FuncDeclaration::toObjFile()
|
||||
nestTypes.push_back(vd->llvmValue->getType());
|
||||
}
|
||||
else {
|
||||
nestTypes.push_back(LLVM_DtoType(vd->type));
|
||||
nestTypes.push_back(DtoType(vd->type));
|
||||
}
|
||||
}
|
||||
const llvm::StructType* nestSType = llvm::StructType::get(nestTypes);
|
||||
@@ -839,12 +839,12 @@ void FuncDeclaration::toObjFile()
|
||||
if (parentNested) {
|
||||
assert(llvmThisVar);
|
||||
llvm::Value* ptr = gIR->ir->CreateBitCast(llvmThisVar, parentNested->getType(), "tmp");
|
||||
gIR->ir->CreateStore(ptr, LLVM_DtoGEPi(llvmNested, 0,0, "tmp"));
|
||||
gIR->ir->CreateStore(ptr, DtoGEPi(llvmNested, 0,0, "tmp"));
|
||||
}
|
||||
for (std::set<VarDeclaration*>::iterator i=llvmNestedVars.begin(); i!=llvmNestedVars.end(); ++i) {
|
||||
VarDeclaration* vd = *i;
|
||||
if (vd->isParameter()) {
|
||||
gIR->ir->CreateStore(vd->llvmValue, LLVM_DtoGEPi(llvmNested, 0, vd->llvmNestedIndex, "tmp"));
|
||||
gIR->ir->CreateStore(vd->llvmValue, DtoGEPi(llvmNested, 0, vd->llvmNestedIndex, "tmp"));
|
||||
vd->llvmValue = llvmNested;
|
||||
}
|
||||
}
|
||||
|
||||
28
gen/typinf.c
28
gen/typinf.c
@@ -302,24 +302,24 @@ void TypeInfoTypedefDeclaration::toDt(dt_t **pdt)
|
||||
|
||||
// char[] name
|
||||
char *name = sd->toPrettyChars();
|
||||
sinits.push_back(LLVM_DtoConstString(name));
|
||||
sinits.push_back(DtoConstString(name));
|
||||
assert(sinits.back()->getType() == initZ->getOperand(2)->getType());
|
||||
|
||||
// void[] init
|
||||
const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
if (tinfo->isZeroInit() || !sd->init) // 0 initializer, or the same as the base type
|
||||
{
|
||||
sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
|
||||
}
|
||||
else
|
||||
{
|
||||
llvm::Constant* ci = LLVM_DtoConstInitializer(sd->basetype, sd->init);
|
||||
llvm::Constant* ci = DtoConstInitializer(sd->basetype, sd->init);
|
||||
std::string ciname(sd->mangle());
|
||||
ciname.append("__init");
|
||||
llvm::GlobalVariable* civar = new llvm::GlobalVariable(LLVM_DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
|
||||
llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
|
||||
llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt);
|
||||
size_t cisize = gTargetData->getTypeSize(LLVM_DtoType(sd->basetype));
|
||||
sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(cisize), cicast));
|
||||
size_t cisize = gTargetData->getTypeSize(DtoType(sd->basetype));
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
|
||||
}
|
||||
|
||||
// create the symbol
|
||||
@@ -366,25 +366,25 @@ void TypeInfoEnumDeclaration::toDt(dt_t **pdt)
|
||||
|
||||
// char[] name
|
||||
char *name = sd->toPrettyChars();
|
||||
sinits.push_back(LLVM_DtoConstString(name));
|
||||
sinits.push_back(DtoConstString(name));
|
||||
assert(sinits.back()->getType() == initZ->getOperand(2)->getType());
|
||||
|
||||
// void[] init
|
||||
const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
if (tinfo->isZeroInit() || !sd->defaultval) // 0 initializer, or the same as the base type
|
||||
{
|
||||
sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
|
||||
}
|
||||
else
|
||||
{
|
||||
const llvm::Type* memty = LLVM_DtoType(sd->memtype);
|
||||
const llvm::Type* memty = DtoType(sd->memtype);
|
||||
llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned());
|
||||
std::string ciname(sd->mangle());
|
||||
ciname.append("__init");
|
||||
llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
|
||||
llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt);
|
||||
size_t cisize = gTargetData->getTypeSize(memty);
|
||||
sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(cisize), cicast));
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
|
||||
}
|
||||
|
||||
// create the symbol
|
||||
@@ -544,7 +544,7 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
|
||||
|
||||
// char[] name
|
||||
char *name = sd->toPrettyChars();
|
||||
sinits.push_back(LLVM_DtoConstString(name));
|
||||
sinits.push_back(DtoConstString(name));
|
||||
Logger::println("************** A");
|
||||
assert(sinits.back()->getType() == stype->getElementType(1));
|
||||
|
||||
@@ -552,14 +552,14 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
|
||||
const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
if (sd->zeroInit) // 0 initializer, or the same as the base type
|
||||
{
|
||||
sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(sd->llvmInitZ);
|
||||
size_t cisize = gTargetData->getTypeSize(tc->llvmType);
|
||||
llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(tc->llvmInit, initpt);
|
||||
sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(cisize), cicast));
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
|
||||
}
|
||||
|
||||
// toX functions ground work
|
||||
@@ -684,7 +684,7 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
|
||||
}
|
||||
|
||||
// uint m_flags;
|
||||
sinits.push_back(LLVM_DtoConstUint(tc->hasPointers()));
|
||||
sinits.push_back(DtoConstUint(tc->hasPointers()));
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
|
||||
27
test/scope5.d
Normal file
27
test/scope5.d
Normal file
@@ -0,0 +1,27 @@
|
||||
module scope5;
|
||||
|
||||
int i;
|
||||
|
||||
void func(int a, int b)
|
||||
{
|
||||
i = 0;
|
||||
{
|
||||
scope(exit) i++;
|
||||
if (a) {
|
||||
scope(exit) i++;
|
||||
if (b) return;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
func(0,0);
|
||||
assert(i == 2);
|
||||
func(1,1);
|
||||
assert(i == 2);
|
||||
func(1,0);
|
||||
assert(i == 4);
|
||||
}
|
||||
Reference in New Issue
Block a user