mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
[svn r229] Updated the object.d implementation to the latest Tango.
Fixed a bunch of the built-in typeinfos for arrays, they did not inherit TypeInfo_Array. Applied patch to tango/text/convert/Layout.d by fvbommel, closes #47 . Cleaned up some type code. Replaced uses of llvm::Type with LLType (a typedef), same for Value and Constant. Fixed a few cases where typeinfo for user structs could be emitted multiple times, seems to still be some cases of this :/
This commit is contained in:
51
gen/aa.cpp
51
gen/aa.cpp
@@ -13,11 +13,11 @@
|
||||
|
||||
// makes sure the key value lives in memory so it can be passed to the runtime functions without problems
|
||||
// returns the pointer
|
||||
static llvm::Value* to_pkey(DValue* key)
|
||||
static LLValue* to_pkey(DValue* key)
|
||||
{
|
||||
Type* keytype = key->getType();
|
||||
bool needmem = !DtoIsPassedByRef(keytype);
|
||||
llvm::Value* pkey;
|
||||
LLValue* pkey;
|
||||
if (key->isIm()) {
|
||||
pkey = key->getRVal();
|
||||
}
|
||||
@@ -35,7 +35,7 @@ static llvm::Value* to_pkey(DValue* key)
|
||||
pkey = key->getRVal();
|
||||
}
|
||||
else {
|
||||
llvm::Value* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint());
|
||||
LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint());
|
||||
DVarValue* var = new DVarValue(keytype, tmp, true);
|
||||
DtoAssign(var, key);
|
||||
return tmp;
|
||||
@@ -43,7 +43,7 @@ static llvm::Value* to_pkey(DValue* key)
|
||||
|
||||
// give memory
|
||||
if (needmem) {
|
||||
llvm::Value* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint());
|
||||
LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint());
|
||||
DtoStore(pkey, tmp);
|
||||
pkey = tmp;
|
||||
}
|
||||
@@ -52,17 +52,12 @@ static llvm::Value* to_pkey(DValue* key)
|
||||
}
|
||||
|
||||
// returns the keytype typeinfo
|
||||
static llvm::Value* to_keyti(DValue* key)
|
||||
static LLValue* to_keyti(DValue* key)
|
||||
{
|
||||
// keyti param
|
||||
Type* keytype = key->getType();
|
||||
keytype->getTypeInfo(NULL);
|
||||
TypeInfoDeclaration* tid = keytype->getTypeInfoDeclaration();
|
||||
assert(tid);
|
||||
DtoResolveDsymbol(Type::typeinfo);
|
||||
DtoForceDeclareDsymbol(tid);
|
||||
assert(tid->ir.irGlobal->value);
|
||||
return tid->ir.irGlobal->value;
|
||||
return DtoTypeInfoOf(keytype, false);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -77,32 +72,32 @@ DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key)
|
||||
const llvm::FunctionType* funcTy = func->getFunctionType();
|
||||
|
||||
// aa param
|
||||
llvm::Value* aaval = aa->getLVal();
|
||||
LLValue* aaval = aa->getLVal();
|
||||
aaval = DtoBitCast(aaval, funcTy->getParamType(0));
|
||||
|
||||
// keyti param
|
||||
llvm::Value* keyti = to_keyti(key);
|
||||
LLValue* keyti = to_keyti(key);
|
||||
keyti = DtoBitCast(keyti, funcTy->getParamType(1));
|
||||
|
||||
// valuesize param
|
||||
llvm::Value* valsize = DtoConstSize_t(getABITypeSize(DtoType(type)));
|
||||
LLValue* valsize = DtoConstSize_t(getABITypeSize(DtoType(type)));
|
||||
|
||||
// pkey param
|
||||
llvm::Value* pkey = to_pkey(key);
|
||||
LLValue* pkey = to_pkey(key);
|
||||
pkey = DtoBitCast(pkey, funcTy->getParamType(3));
|
||||
|
||||
// build arg vector
|
||||
std::vector<llvm::Value*> args;
|
||||
LLSmallVector<LLValue*, 4> args;
|
||||
args.push_back(aaval);
|
||||
args.push_back(keyti);
|
||||
args.push_back(valsize);
|
||||
args.push_back(pkey);
|
||||
|
||||
// call runtime
|
||||
llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.index");
|
||||
LLValue* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.index");
|
||||
|
||||
// cast return value
|
||||
const llvm::Type* targettype = getPtrToType(DtoType(type));
|
||||
const LLType* targettype = getPtrToType(DtoType(type));
|
||||
if (ret->getType() != targettype)
|
||||
ret = DtoBitCast(ret, targettype);
|
||||
|
||||
@@ -123,30 +118,30 @@ DValue* DtoAAIn(Type* type, DValue* aa, DValue* key)
|
||||
Logger::cout() << "_aaIn = " << *func << '\n';
|
||||
|
||||
// aa param
|
||||
llvm::Value* aaval = aa->getRVal();
|
||||
LLValue* aaval = aa->getRVal();
|
||||
Logger::cout() << "aaval: " << *aaval << '\n';
|
||||
Logger::cout() << "totype: " << *funcTy->getParamType(0) << '\n';
|
||||
aaval = DtoBitCast(aaval, funcTy->getParamType(0));
|
||||
|
||||
// keyti param
|
||||
llvm::Value* keyti = to_keyti(key);
|
||||
LLValue* keyti = to_keyti(key);
|
||||
keyti = DtoBitCast(keyti, funcTy->getParamType(1));
|
||||
|
||||
// pkey param
|
||||
llvm::Value* pkey = to_pkey(key);
|
||||
LLValue* pkey = to_pkey(key);
|
||||
pkey = DtoBitCast(pkey, funcTy->getParamType(2));
|
||||
|
||||
// build arg vector
|
||||
std::vector<llvm::Value*> args;
|
||||
LLSmallVector<LLValue*, 3> args;
|
||||
args.push_back(aaval);
|
||||
args.push_back(keyti);
|
||||
args.push_back(pkey);
|
||||
|
||||
// call runtime
|
||||
llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.in");
|
||||
LLValue* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.in");
|
||||
|
||||
// cast return value
|
||||
const llvm::Type* targettype = DtoType(type);
|
||||
const LLType* targettype = DtoType(type);
|
||||
if (ret->getType() != targettype)
|
||||
ret = DtoBitCast(ret, targettype);
|
||||
|
||||
@@ -167,21 +162,21 @@ void DtoAARemove(DValue* aa, DValue* key)
|
||||
Logger::cout() << "_aaDel = " << *func << '\n';
|
||||
|
||||
// aa param
|
||||
llvm::Value* aaval = aa->getRVal();
|
||||
LLValue* aaval = aa->getRVal();
|
||||
Logger::cout() << "aaval: " << *aaval << '\n';
|
||||
Logger::cout() << "totype: " << *funcTy->getParamType(0) << '\n';
|
||||
aaval = DtoBitCast(aaval, funcTy->getParamType(0));
|
||||
|
||||
// keyti param
|
||||
llvm::Value* keyti = to_keyti(key);
|
||||
LLValue* keyti = to_keyti(key);
|
||||
keyti = DtoBitCast(keyti, funcTy->getParamType(1));
|
||||
|
||||
// pkey param
|
||||
llvm::Value* pkey = to_pkey(key);
|
||||
LLValue* pkey = to_pkey(key);
|
||||
pkey = DtoBitCast(pkey, funcTy->getParamType(2));
|
||||
|
||||
// build arg vector
|
||||
std::vector<llvm::Value*> args;
|
||||
LLSmallVector<LLValue*, 3> args;
|
||||
args.push_back(aaval);
|
||||
args.push_back(keyti);
|
||||
args.push_back(pkey);
|
||||
|
||||
301
gen/arrays.cpp
301
gen/arrays.cpp
@@ -18,23 +18,10 @@
|
||||
const llvm::StructType* DtoArrayType(Type* t)
|
||||
{
|
||||
assert(t->next);
|
||||
const llvm::Type* at = DtoType(t->next);
|
||||
const llvm::Type* arrty;
|
||||
|
||||
if (at == llvm::Type::VoidTy) {
|
||||
at = llvm::Type::Int8Ty;
|
||||
}
|
||||
arrty = getPtrToType(at);
|
||||
|
||||
std::vector<const llvm::Type*> members;
|
||||
if (global.params.is64bit)
|
||||
members.push_back(llvm::Type::Int64Ty);
|
||||
else
|
||||
members.push_back(llvm::Type::Int32Ty);
|
||||
|
||||
members.push_back(arrty);
|
||||
|
||||
return llvm::StructType::get(members);
|
||||
const LLType* elemty = DtoType(t->next);
|
||||
if (elemty == llvm::Type::VoidTy)
|
||||
elemty = llvm::Type::Int8Ty;
|
||||
return llvm::StructType::get(DtoSize_t(), getPtrToType(elemty), 0);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -47,7 +34,7 @@ const llvm::ArrayType* DtoStaticArrayType(Type* t)
|
||||
assert(t->ty == Tsarray);
|
||||
assert(t->next);
|
||||
|
||||
const llvm::Type* at = DtoType(t->next);
|
||||
const LLType* at = DtoType(t->next);
|
||||
|
||||
TypeSArray* tsa = (TypeSArray*)t;
|
||||
assert(tsa->dim->type->isintegral());
|
||||
@@ -60,24 +47,24 @@ const llvm::ArrayType* DtoStaticArrayType(Type* t)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoSetArrayToNull(llvm::Value* v)
|
||||
void DtoSetArrayToNull(LLValue* v)
|
||||
{
|
||||
Logger::println("DtoSetArrayToNull");
|
||||
LOG_SCOPE;
|
||||
|
||||
llvm::Value* len = DtoGEPi(v,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* zerolen = llvm::ConstantInt::get(len->getType()->getContainedType(0), 0, false);
|
||||
LLValue* len = DtoGEPi(v,0,0,"tmp",gIR->scopebb());
|
||||
LLValue* zerolen = llvm::ConstantInt::get(len->getType()->getContainedType(0), 0, false);
|
||||
new llvm::StoreInst(zerolen, len, gIR->scopebb());
|
||||
|
||||
llvm::Value* ptr = DtoGEPi(v,0,1,"tmp",gIR->scopebb());
|
||||
LLValue* ptr = DtoGEPi(v,0,1,"tmp",gIR->scopebb());
|
||||
const llvm::PointerType* pty = isaPointer(ptr->getType()->getContainedType(0));
|
||||
llvm::Value* nullptr = llvm::ConstantPointerNull::get(pty);
|
||||
LLValue* nullptr = llvm::ConstantPointerNull::get(pty);
|
||||
new llvm::StoreInst(nullptr, ptr, gIR->scopebb());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
|
||||
void DtoArrayAssign(LLValue* dst, LLValue* src)
|
||||
{
|
||||
Logger::println("DtoArrayAssign");
|
||||
LOG_SCOPE;
|
||||
@@ -85,8 +72,8 @@ void DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
|
||||
assert(gIR);
|
||||
if (dst->getType() == src->getType())
|
||||
{
|
||||
llvm::Value* ptr = DtoGEPi(src,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
|
||||
LLValue* ptr = DtoGEPi(src,0,0,"tmp",gIR->scopebb());
|
||||
LLValue* val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
|
||||
ptr = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
new llvm::StoreInst(val, ptr, gIR->scopebb());
|
||||
|
||||
@@ -104,38 +91,38 @@ void DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
|
||||
Logger::cout() << "invalid: " << *src << '\n';
|
||||
assert(0);
|
||||
}
|
||||
const llvm::Type* dstty = getPtrToType(arrty->getElementType());
|
||||
const LLType* dstty = getPtrToType(arrty->getElementType());
|
||||
|
||||
llvm::Value* dstlen = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* srclen = DtoConstSize_t(arrty->getNumElements());
|
||||
LLValue* dstlen = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
|
||||
LLValue* srclen = DtoConstSize_t(arrty->getNumElements());
|
||||
new llvm::StoreInst(srclen, dstlen, gIR->scopebb());
|
||||
|
||||
llvm::Value* dstptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
|
||||
llvm::Value* srcptr = new llvm::BitCastInst(src,dstty,"tmp",gIR->scopebb());
|
||||
LLValue* dstptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
|
||||
LLValue* srcptr = DtoBitCast(src, dstty);
|
||||
new llvm::StoreInst(srcptr, dstptr, gIR->scopebb());
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoArrayInit(llvm::Value* l, llvm::Value* r)
|
||||
void DtoArrayInit(LLValue* l, LLValue* r)
|
||||
{
|
||||
Logger::println("DtoArrayInit");
|
||||
LOG_SCOPE;
|
||||
|
||||
const llvm::PointerType* ptrty = isaPointer(l->getType());
|
||||
const llvm::Type* t = ptrty->getContainedType(0);
|
||||
const LLType* t = ptrty->getContainedType(0);
|
||||
const llvm::ArrayType* arrty = isaArray(t);
|
||||
if (arrty)
|
||||
{
|
||||
llvm::Value* ptr = DtoGEPi(l,0,0,"tmp",gIR->scopebb());
|
||||
llvm::Value* dim = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false);
|
||||
LLValue* ptr = DtoGEPi(l,0,0,"tmp",gIR->scopebb());
|
||||
LLValue* dim = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false);
|
||||
DtoArrayInit(ptr, dim, r);
|
||||
}
|
||||
else if (isaStruct(t))
|
||||
{
|
||||
llvm::Value* dim = DtoLoad(DtoGEPi(l, 0,0, "tmp"));
|
||||
llvm::Value* ptr = DtoLoad(DtoGEPi(l, 0,1, "tmp"));
|
||||
LLValue* dim = DtoLoad(DtoGEPi(l, 0,0, "tmp"));
|
||||
LLValue* ptr = DtoLoad(DtoGEPi(l, 0,1, "tmp"));
|
||||
DtoArrayInit(ptr, dim, r);
|
||||
}
|
||||
else
|
||||
@@ -144,9 +131,9 @@ void DtoArrayInit(llvm::Value* l, llvm::Value* r)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef const llvm::Type* constLLVMTypeP;
|
||||
typedef const LLType* constLLVMTypeP;
|
||||
|
||||
static size_t checkRectArrayInit(const llvm::Type* pt, constLLVMTypeP& finalty)
|
||||
static size_t checkRectArrayInit(const LLType* pt, constLLVMTypeP& finalty)
|
||||
{
|
||||
if (const llvm::ArrayType* arrty = isaArray(pt)) {
|
||||
size_t n = checkRectArrayInit(arrty->getElementType(), finalty);
|
||||
@@ -158,28 +145,28 @@ static size_t checkRectArrayInit(const llvm::Type* pt, constLLVMTypeP& finalty)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
|
||||
void DtoArrayInit(LLValue* ptr, LLValue* dim, LLValue* val)
|
||||
{
|
||||
Logger::println("DtoArrayInit");
|
||||
LOG_SCOPE;
|
||||
|
||||
Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n';
|
||||
const llvm::Type* pt = ptr->getType()->getContainedType(0);
|
||||
const llvm::Type* t = val->getType();
|
||||
const llvm::Type* finalTy;
|
||||
const LLType* pt = ptr->getType()->getContainedType(0);
|
||||
const LLType* t = val->getType();
|
||||
const LLType* finalTy;
|
||||
size_t aggrsz = 0;
|
||||
if (size_t arrsz = checkRectArrayInit(pt, finalTy)) {
|
||||
assert(finalTy == t);
|
||||
llvm::Constant* c = isaConstant(dim);
|
||||
LLConstant* c = isaConstant(dim);
|
||||
assert(c);
|
||||
dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz));
|
||||
ptr = gIR->ir->CreateBitCast(ptr, getPtrToType(finalTy), "tmp");
|
||||
}
|
||||
else if (isaStruct(t)) {
|
||||
aggrsz = getABITypeSize(t);
|
||||
llvm::Constant* c = isaConstant(val);
|
||||
LLConstant* c = isaConstant(val);
|
||||
if (c && c->isNullValue()) {
|
||||
llvm::Value* nbytes;
|
||||
LLValue* nbytes;
|
||||
if (aggrsz == 1)
|
||||
nbytes = dim;
|
||||
else
|
||||
@@ -197,7 +184,7 @@ void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
|
||||
|
||||
Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n';
|
||||
|
||||
std::vector<llvm::Value*> args;
|
||||
std::vector<LLValue*> args;
|
||||
args.push_back(ptr);
|
||||
args.push_back(dim);
|
||||
args.push_back(val);
|
||||
@@ -211,13 +198,13 @@ void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
|
||||
else if (isaPointer(t)) {
|
||||
funcname = "_d_array_init_pointer";
|
||||
|
||||
const llvm::Type* dstty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
|
||||
const LLType* dstty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
|
||||
if (args[0]->getType() != dstty)
|
||||
args[0] = new llvm::BitCastInst(args[0],dstty,"tmp",gIR->scopebb());
|
||||
args[0] = DtoBitCast(args[0],dstty);
|
||||
|
||||
const llvm::Type* valty = getPtrToType(llvm::Type::Int8Ty);
|
||||
const LLType* valty = getPtrToType(llvm::Type::Int8Ty);
|
||||
if (args[2]->getType() != valty)
|
||||
args[2] = new llvm::BitCastInst(args[2],valty,"tmp",gIR->scopebb());
|
||||
args[2] = DtoBitCast(args[2],valty);
|
||||
}
|
||||
else if (t == llvm::Type::Int1Ty) {
|
||||
funcname = "_d_array_init_i1";
|
||||
@@ -254,7 +241,7 @@ void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr)
|
||||
void DtoSetArray(LLValue* arr, LLValue* dim, LLValue* ptr)
|
||||
{
|
||||
Logger::println("DtoSetArray");
|
||||
LOG_SCOPE;
|
||||
@@ -265,20 +252,20 @@ void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr)
|
||||
|
||||
const llvm::StructType* st = isaStruct(arr->getType()->getContainedType(0));
|
||||
|
||||
llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
|
||||
llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
|
||||
LLValue* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
|
||||
LLValue* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
|
||||
|
||||
llvm::Value* arrdim = DtoGEP(arr,zero,zero,"tmp",gIR->scopebb());
|
||||
LLValue* arrdim = DtoGEP(arr,zero,zero,"tmp",gIR->scopebb());
|
||||
Logger::cout() << "arrdim = " << *arrdim << '\n';
|
||||
new llvm::StoreInst(dim, arrdim, gIR->scopebb());
|
||||
|
||||
llvm::Value* arrptr = DtoGEP(arr,zero,one,"tmp",gIR->scopebb());
|
||||
LLValue* arrptr = DtoGEP(arr,zero,one,"tmp",gIR->scopebb());
|
||||
Logger::cout() << "arrptr = " << *arrptr << '\n';
|
||||
new llvm::StoreInst(ptr, arrptr, gIR->scopebb());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
{
|
||||
Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars());
|
||||
LOG_SCOPE;
|
||||
@@ -303,10 +290,10 @@ llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
|
||||
Logger::println("dim = %u", tdim);
|
||||
|
||||
std::vector<llvm::Constant*> inits(tdim, NULL);
|
||||
std::vector<LLConstant*> inits(tdim, NULL);
|
||||
|
||||
Type* arrnext = arrinittype->next;
|
||||
const llvm::Type* elemty = DtoType(arrinittype->next);
|
||||
const LLType* elemty = DtoType(arrinittype->next);
|
||||
|
||||
assert(arrinit->index.dim == arrinit->value.dim);
|
||||
for (unsigned i=0,j=0; i < tdim; ++i)
|
||||
@@ -319,7 +306,7 @@ llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
else
|
||||
idx = NULL;
|
||||
|
||||
llvm::Constant* v = NULL;
|
||||
LLConstant* v = NULL;
|
||||
|
||||
if (idx)
|
||||
{
|
||||
@@ -331,7 +318,7 @@ llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
Logger::println("has idx->type", i);
|
||||
//integer_t k = idx->toInteger();
|
||||
//Logger::println("getting value for exp: %s | %s", idx->toChars(), arrnext->toChars());
|
||||
llvm::Constant* cc = idx->toConstElem(gIR);
|
||||
LLConstant* cc = idx->toConstElem(gIR);
|
||||
Logger::println("value gotten");
|
||||
assert(cc != NULL);
|
||||
llvm::ConstantInt* ci = llvm::dyn_cast<llvm::ConstantInt>(cc);
|
||||
@@ -365,7 +352,7 @@ llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
|
||||
Logger::println("building constant array");
|
||||
const llvm::ArrayType* arrty = llvm::ArrayType::get(elemty,tdim);
|
||||
llvm::Constant* constarr = llvm::ConstantArray::get(arrty, inits);
|
||||
LLConstant* constarr = llvm::ConstantArray::get(arrty, inits);
|
||||
|
||||
if (arrinittype->ty == Tsarray)
|
||||
return constarr;
|
||||
@@ -373,16 +360,16 @@ llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
assert(arrinittype->ty == Tarray);
|
||||
|
||||
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrty,true,llvm::GlobalValue::InternalLinkage,constarr,"constarray",gIR->module);
|
||||
llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
|
||||
llvm::Constant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
|
||||
LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
|
||||
LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
|
||||
return DtoConstSlice(DtoConstSize_t(tdim),gep);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
static llvm::Value* get_slice_ptr(DSliceValue* e, llvm::Value*& sz)
|
||||
static LLValue* get_slice_ptr(DSliceValue* e, LLValue*& sz)
|
||||
{
|
||||
const llvm::Type* t = e->ptr->getType()->getContainedType(0);
|
||||
llvm::Value* ret = 0;
|
||||
const LLType* t = e->ptr->getType()->getContainedType(0);
|
||||
LLValue* ret = 0;
|
||||
if (e->len != 0) {
|
||||
// this means it's a real slice
|
||||
ret = e->ptr;
|
||||
@@ -415,7 +402,7 @@ static llvm::Value* get_slice_ptr(DSliceValue* e, llvm::Value*& sz)
|
||||
size_t elembsz = getABITypeSize(ret->getType()->getContainedType(0));
|
||||
llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
|
||||
|
||||
llvm::Value* len = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb());
|
||||
LLValue* len = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb());
|
||||
len = new llvm::LoadInst(len, "tmp", gIR->scopebb());
|
||||
sz = llvm::BinaryOperator::createMul(len,elemsz,"tmp",gIR->scopebb());
|
||||
}
|
||||
@@ -428,16 +415,16 @@ static llvm::Value* get_slice_ptr(DSliceValue* e, llvm::Value*& sz)
|
||||
void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src)
|
||||
{
|
||||
Logger::println("ArrayCopySlices");
|
||||
const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
const LLType* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
|
||||
llvm::Value* sz1;
|
||||
llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb());
|
||||
LLValue* sz1;
|
||||
LLValue* dstarr = DtoBitCast(get_slice_ptr(dst,sz1),arrty);
|
||||
|
||||
llvm::Value* sz2;
|
||||
llvm::Value* srcarr = new llvm::BitCastInst(get_slice_ptr(src,sz2),arrty,"tmp",gIR->scopebb());
|
||||
LLValue* sz2;
|
||||
LLValue* srcarr = DtoBitCast(get_slice_ptr(src,sz2),arrty);
|
||||
|
||||
llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
|
||||
std::vector<llvm::Value*> llargs;
|
||||
std::vector<LLValue*> llargs;
|
||||
llargs.resize(4);
|
||||
llargs[0] = dstarr;
|
||||
llargs[1] = srcarr;
|
||||
@@ -450,14 +437,14 @@ void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src)
|
||||
void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src)
|
||||
{
|
||||
Logger::println("ArrayCopyToSlice");
|
||||
const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
const LLType* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
|
||||
llvm::Value* sz1;
|
||||
llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb());
|
||||
llvm::Value* srcarr = new llvm::BitCastInst(DtoArrayPtr(src),arrty,"tmp",gIR->scopebb());
|
||||
LLValue* sz1;
|
||||
LLValue* dstarr = DtoBitCast(get_slice_ptr(dst,sz1),arrty);
|
||||
LLValue* srcarr = DtoBitCast(DtoArrayPtr(src),arrty);
|
||||
|
||||
llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
|
||||
std::vector<llvm::Value*> llargs;
|
||||
std::vector<LLValue*> llargs;
|
||||
llargs.resize(4);
|
||||
llargs[0] = dstarr;
|
||||
llargs[1] = srcarr;
|
||||
@@ -468,19 +455,19 @@ void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
void DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src)
|
||||
void DtoStaticArrayCopy(LLValue* dst, LLValue* src)
|
||||
{
|
||||
Logger::cout() << "static array copy: " << *dst << " from " << *src << '\n';
|
||||
assert(dst->getType() == src->getType());
|
||||
size_t arrsz = getABITypeSize(dst->getType()->getContainedType(0));
|
||||
llvm::Value* n = llvm::ConstantInt::get(DtoSize_t(), arrsz, false);
|
||||
LLValue* n = llvm::ConstantInt::get(DtoSize_t(), arrsz, false);
|
||||
|
||||
const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
|
||||
llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb());
|
||||
const LLType* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
LLValue* dstarr = DtoBitCast(dst,arrty);
|
||||
LLValue* srcarr = DtoBitCast(src,arrty);
|
||||
|
||||
llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
|
||||
std::vector<llvm::Value*> llargs;
|
||||
std::vector<LLValue*> llargs;
|
||||
llargs.resize(4);
|
||||
llargs[0] = dstarr;
|
||||
llargs[1] = srcarr;
|
||||
@@ -491,13 +478,13 @@ void DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Constant* DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr)
|
||||
LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr)
|
||||
{
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(dim->getType());
|
||||
types.push_back(ptr->getType());
|
||||
const llvm::StructType* type = llvm::StructType::get(types);
|
||||
std::vector<llvm::Constant*> values;
|
||||
std::vector<LLConstant*> values;
|
||||
values.push_back(dim);
|
||||
values.push_back(ptr);
|
||||
return llvm::ConstantStruct::get(type,values);
|
||||
@@ -512,13 +499,13 @@ DSliceValue* DtoNewDynArray(Type* arrayType, DValue* dim, bool defaultInit)
|
||||
bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarrayT" : "_d_newarrayiT" );
|
||||
|
||||
llvm::SmallVector<llvm::Value*,2> args;
|
||||
LLSmallVector<LLValue*,2> args;
|
||||
args.push_back(DtoTypeInfoOf(arrayType));
|
||||
assert(DtoType(dim->getType()) == DtoSize_t());
|
||||
args.push_back(dim->getRVal());
|
||||
|
||||
llvm::Value* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem");
|
||||
const llvm::Type* dstType = DtoType(arrayType)->getContainedType(1);
|
||||
LLValue* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem");
|
||||
const LLType* dstType = DtoType(arrayType)->getContainedType(1);
|
||||
if (newptr->getType() != dstType)
|
||||
newptr = DtoBitCast(newptr, dstType, ".gc_mem");
|
||||
|
||||
@@ -551,15 +538,15 @@ DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim)
|
||||
// call runtime
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_arraysetlengthT" : "_d_arraysetlengthiT" );
|
||||
|
||||
llvm::SmallVector<llvm::Value*,4> args;
|
||||
LLSmallVector<LLValue*,4> args;
|
||||
args.push_back(DtoTypeInfoOf(arrayType));
|
||||
args.push_back(newdim->getRVal());
|
||||
args.push_back(DtoArrayLen(array));
|
||||
llvm::Value* arrPtr = DtoArrayPtr(array);
|
||||
LLValue* arrPtr = DtoArrayPtr(array);
|
||||
Logger::cout() << "arrPtr = " << *arrPtr << '\n';
|
||||
args.push_back(DtoBitCast(arrPtr, fn->getFunctionType()->getParamType(3), "tmp"));
|
||||
|
||||
llvm::Value* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem");
|
||||
LLValue* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem");
|
||||
if (newptr->getType() != arrPtr->getType())
|
||||
newptr = DtoBitCast(newptr, arrPtr->getType(), ".gc_mem");
|
||||
|
||||
@@ -574,14 +561,14 @@ DSliceValue* DtoCatAssignElement(DValue* array, Expression* exp)
|
||||
|
||||
assert(array);
|
||||
|
||||
llvm::Value* idx = DtoArrayLen(array);
|
||||
llvm::Value* one = DtoConstSize_t(1);
|
||||
llvm::Value* len = gIR->ir->CreateAdd(idx,one,"tmp");
|
||||
LLValue* idx = DtoArrayLen(array);
|
||||
LLValue* one = DtoConstSize_t(1);
|
||||
LLValue* len = gIR->ir->CreateAdd(idx,one,"tmp");
|
||||
|
||||
DValue* newdim = new DImValue(Type::tsize_t, len);
|
||||
DSliceValue* slice = DtoResizeDynArray(array->getType(), array, newdim);
|
||||
|
||||
llvm::Value* ptr = slice->ptr;
|
||||
LLValue* ptr = slice->ptr;
|
||||
ptr = llvm::GetElementPtrInst::Create(ptr, idx, "tmp", gIR->scopebb());
|
||||
|
||||
DValue* dptr = new DVarValue(exp->type, ptr, true);
|
||||
@@ -620,8 +607,8 @@ DSliceValue* DtoCatAssignArray(DValue* arr, Expression* exp)
|
||||
src1 = gIR->ir->CreateGEP(src1,len1,"tmp");
|
||||
|
||||
// memcpy
|
||||
llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src2->getType()->getContainedType(0)));
|
||||
llvm::Value* bytelen = gIR->ir->CreateMul(len2, elemSize, "tmp");
|
||||
LLValue* elemSize = DtoConstSize_t(getABITypeSize(src2->getType()->getContainedType(0)));
|
||||
LLValue* bytelen = gIR->ir->CreateMul(len2, elemSize, "tmp");
|
||||
DtoMemCpy(src1,src2,bytelen);
|
||||
|
||||
return slice;
|
||||
@@ -650,14 +637,14 @@ DSliceValue* DtoCatArrays(Type* type, Expression* exp1, Expression* exp2)
|
||||
|
||||
DValue* lenval = new DImValue(Type::tsize_t, res);
|
||||
DSliceValue* slice = DtoNewDynArray(type, lenval, false);
|
||||
llvm::Value* mem = slice->ptr;
|
||||
LLValue* mem = slice->ptr;
|
||||
|
||||
src1 = DtoArrayPtr(e1);
|
||||
src2 = DtoArrayPtr(e2);
|
||||
|
||||
// first memcpy
|
||||
llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
|
||||
llvm::Value* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp");
|
||||
LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
|
||||
LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp");
|
||||
DtoMemCpy(mem,src1,bytelen);
|
||||
|
||||
// second memcpy
|
||||
@@ -690,7 +677,7 @@ DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2)
|
||||
|
||||
DValue* lenval = new DImValue(Type::tsize_t, res);
|
||||
DSliceValue* slice = DtoNewDynArray(type, lenval, false);
|
||||
llvm::Value* mem = slice->ptr;
|
||||
LLValue* mem = slice->ptr;
|
||||
|
||||
DVarValue* memval = new DVarValue(e1->getType(), mem, true);
|
||||
DtoAssign(memval, e1);
|
||||
@@ -699,8 +686,8 @@ DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2)
|
||||
|
||||
mem = gIR->ir->CreateGEP(mem,DtoConstSize_t(1),"tmp");
|
||||
|
||||
llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
|
||||
llvm::Value* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp");
|
||||
LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
|
||||
LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp");
|
||||
DtoMemCpy(mem,src1,bytelen);
|
||||
|
||||
|
||||
@@ -714,12 +701,12 @@ DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2)
|
||||
|
||||
DValue* lenval = new DImValue(Type::tsize_t, res);
|
||||
DSliceValue* slice = DtoNewDynArray(type, lenval, false);
|
||||
llvm::Value* mem = slice->ptr;
|
||||
LLValue* mem = slice->ptr;
|
||||
|
||||
src1 = DtoArrayPtr(e1);
|
||||
|
||||
llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
|
||||
llvm::Value* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp");
|
||||
LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
|
||||
LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp");
|
||||
DtoMemCpy(mem,src1,bytelen);
|
||||
|
||||
mem = gIR->ir->CreateGEP(mem,len1,"tmp");
|
||||
@@ -732,14 +719,14 @@ DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// helper for eq and cmp
|
||||
static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool useti)
|
||||
static LLValue* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool useti)
|
||||
{
|
||||
Logger::println("comparing arrays");
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, func);
|
||||
assert(fn);
|
||||
|
||||
llvm::Value* lmem;
|
||||
llvm::Value* rmem;
|
||||
LLValue* lmem;
|
||||
LLValue* rmem;
|
||||
|
||||
// cast static arrays to dynamic ones, this turns them into DSliceValues
|
||||
Logger::println("casting to dynamic arrays");
|
||||
@@ -785,9 +772,9 @@ static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, b
|
||||
else
|
||||
rmem = r->getRVal();
|
||||
|
||||
const llvm::Type* pt = fn->getFunctionType()->getParamType(0);
|
||||
const LLType* pt = fn->getFunctionType()->getParamType(0);
|
||||
|
||||
std::vector<llvm::Value*> args;
|
||||
std::vector<LLValue*> args;
|
||||
Logger::cout() << "bitcasting to " << *pt << '\n';
|
||||
Logger::cout() << *lmem << '\n';
|
||||
Logger::cout() << *rmem << '\n';
|
||||
@@ -796,24 +783,26 @@ static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, b
|
||||
|
||||
// pass element typeinfo ?
|
||||
if (useti) {
|
||||
TypeInfoDeclaration* ti = DtoDType(l->getType())->next->getTypeInfoDeclaration();
|
||||
DtoForceConstInitDsymbol(ti);
|
||||
Logger::cout() << "typeinfo decl: " << *ti->ir.getIrValue() << '\n';
|
||||
Type* t = DtoDType(l->getType())->next;
|
||||
LLValue* tival = DtoTypeInfoOf(t);
|
||||
// DtoTypeInfoOf only does declare, not enough in this case :/
|
||||
DtoForceConstInitDsymbol(t->vtinfo);
|
||||
Logger::cout() << "typeinfo decl: " << *tival << '\n';
|
||||
|
||||
pt = fn->getFunctionType()->getParamType(2);
|
||||
args.push_back(DtoBitCast(ti->ir.getIrValue(), pt));
|
||||
args.push_back(DtoBitCast(tival, pt));
|
||||
}
|
||||
|
||||
return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* DtoArrayEquals(TOK op, DValue* l, DValue* r)
|
||||
LLValue* DtoArrayEquals(TOK op, DValue* l, DValue* r)
|
||||
{
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_adEq");
|
||||
assert(fn);
|
||||
|
||||
llvm::Value* res = DtoArrayEqCmp_impl("_adEq", l, r, true);
|
||||
LLValue* res = DtoArrayEqCmp_impl("_adEq", l, r, true);
|
||||
if (op == TOKnotequal)
|
||||
res = gIR->ir->CreateNot(res, "tmp");
|
||||
|
||||
@@ -821,9 +810,9 @@ llvm::Value* DtoArrayEquals(TOK op, DValue* l, DValue* r)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* DtoArrayCompare(TOK op, DValue* l, DValue* r)
|
||||
LLValue* DtoArrayCompare(TOK op, DValue* l, DValue* r)
|
||||
{
|
||||
llvm::Value* res = 0;
|
||||
LLValue* res = 0;
|
||||
|
||||
llvm::ICmpInst::Predicate cmpop;
|
||||
bool skip = false;
|
||||
@@ -880,7 +869,7 @@ llvm::Value* DtoArrayCompare(TOK op, DValue* l, DValue* r)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty)
|
||||
LLValue* DtoArrayCastLength(LLValue* len, const LLType* elemty, const LLType* newelemty)
|
||||
{
|
||||
Logger::println("DtoArrayCastLength");
|
||||
LOG_SCOPE;
|
||||
@@ -894,7 +883,7 @@ llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, cons
|
||||
if (esz == nsz)
|
||||
return len;
|
||||
|
||||
std::vector<llvm::Value*> args;
|
||||
std::vector<LLValue*> args;
|
||||
args.push_back(len);
|
||||
args.push_back(llvm::ConstantInt::get(DtoSize_t(), esz, false));
|
||||
args.push_back(llvm::ConstantInt::get(DtoSize_t(), nsz, false));
|
||||
@@ -904,41 +893,41 @@ llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, cons
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
|
||||
LLValue* DtoDynArrayIs(TOK op, LLValue* l, LLValue* r)
|
||||
{
|
||||
llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
|
||||
|
||||
if (r == NULL) {
|
||||
llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
|
||||
llvm::Value* rl = llvm::Constant::getNullValue(ll->getType());//DtoConstSize_t(0);
|
||||
llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
|
||||
LLValue* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
|
||||
LLValue* rl = llvm::Constant::getNullValue(ll->getType());//DtoConstSize_t(0);
|
||||
LLValue* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
|
||||
|
||||
llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
|
||||
LLValue* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
|
||||
const llvm::PointerType* pty = isaPointer(lp->getType());
|
||||
llvm::Value* rp = llvm::ConstantPointerNull::get(pty);
|
||||
llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
|
||||
LLValue* rp = llvm::ConstantPointerNull::get(pty);
|
||||
LLValue* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
|
||||
|
||||
llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
|
||||
LLValue* b = gIR->ir->CreateAnd(b1,b2,"tmp");
|
||||
return b;
|
||||
}
|
||||
else {
|
||||
assert(l->getType() == r->getType());
|
||||
|
||||
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");
|
||||
LLValue* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
|
||||
LLValue* rl = gIR->ir->CreateLoad(DtoGEPi(r, 0,0, "tmp"),"tmp");
|
||||
LLValue* b1 = gIR->ir->CreateICmp(pred,ll,rl,"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");
|
||||
LLValue* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
|
||||
LLValue* rp = gIR->ir->CreateLoad(DtoGEPi(r, 0,1, "tmp"),"tmp");
|
||||
LLValue* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
|
||||
|
||||
llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
|
||||
LLValue* b = gIR->ir->CreateAnd(b1,b2,"tmp");
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c)
|
||||
LLConstant* DtoConstStaticArray(const LLType* t, LLConstant* c)
|
||||
{
|
||||
const llvm::ArrayType* at = isaArray(t);
|
||||
assert(at);
|
||||
@@ -950,13 +939,13 @@ llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c)
|
||||
else {
|
||||
assert(at->getElementType() == c->getType());
|
||||
}
|
||||
std::vector<llvm::Constant*> initvals;
|
||||
std::vector<LLConstant*> initvals;
|
||||
initvals.resize(at->getNumElements(), c);
|
||||
return llvm::ConstantArray::get(at, initvals);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* DtoArrayLen(DValue* v)
|
||||
LLValue* DtoArrayLen(DValue* v)
|
||||
{
|
||||
Logger::println("DtoArrayLen");
|
||||
LOG_SCOPE;
|
||||
@@ -977,7 +966,7 @@ llvm::Value* DtoArrayLen(DValue* v)
|
||||
}
|
||||
else if (t->ty == Tsarray) {
|
||||
assert(!v->isSlice());
|
||||
llvm::Value* rv = v->getRVal();
|
||||
LLValue* rv = v->getRVal();
|
||||
Logger::cout() << "casting: " << *rv << '\n';
|
||||
const llvm::ArrayType* t = isaArray(rv->getType()->getContainedType(0));
|
||||
return DtoConstSize_t(t->getNumElements());
|
||||
@@ -987,7 +976,7 @@ llvm::Value* DtoArrayLen(DValue* v)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Value* DtoArrayPtr(DValue* v)
|
||||
LLValue* DtoArrayPtr(DValue* v)
|
||||
{
|
||||
Logger::println("DtoArrayPtr");
|
||||
LOG_SCOPE;
|
||||
@@ -996,7 +985,7 @@ llvm::Value* DtoArrayPtr(DValue* v)
|
||||
if (t->ty == Tarray) {
|
||||
if (DSliceValue* s = v->isSlice()) {
|
||||
if (s->len) return s->ptr;
|
||||
const llvm::Type* t = s->ptr->getType()->getContainedType(0);
|
||||
const LLType* t = s->ptr->getType()->getContainedType(0);
|
||||
Logger::cout() << "ptr of full slice: " << *s->ptr << '\n';
|
||||
const llvm::ArrayType* arrTy = isaArray(s->ptr->getType()->getContainedType(0));
|
||||
if (arrTy)
|
||||
@@ -1019,14 +1008,14 @@ DValue* DtoCastArray(DValue* u, Type* to)
|
||||
Logger::println("DtoCastArray");
|
||||
LOG_SCOPE;
|
||||
|
||||
const llvm::Type* tolltype = DtoType(to);
|
||||
const LLType* tolltype = DtoType(to);
|
||||
|
||||
Type* totype = DtoDType(to);
|
||||
Type* fromtype = DtoDType(u->getType());
|
||||
assert(fromtype->ty == Tarray || fromtype->ty == Tsarray);
|
||||
|
||||
llvm::Value* rval;
|
||||
llvm::Value* rval2;
|
||||
LLValue* rval;
|
||||
LLValue* rval2;
|
||||
bool isslice = false;
|
||||
|
||||
Logger::cout() << "from array or sarray" << '\n';
|
||||
@@ -1038,37 +1027,37 @@ DValue* DtoCastArray(DValue* u, Type* to)
|
||||
}
|
||||
else if (totype->ty == Tarray) {
|
||||
Logger::cout() << "to array" << '\n';
|
||||
const llvm::Type* ptrty = DtoType(totype->next);
|
||||
const LLType* ptrty = DtoType(totype->next);
|
||||
if (ptrty == llvm::Type::VoidTy)
|
||||
ptrty = llvm::Type::Int8Ty;
|
||||
ptrty = getPtrToType(ptrty);
|
||||
|
||||
const llvm::Type* ety = DtoType(fromtype->next);
|
||||
const LLType* ety = DtoType(fromtype->next);
|
||||
if (ety == llvm::Type::VoidTy)
|
||||
ety = llvm::Type::Int8Ty;
|
||||
|
||||
if (DSliceValue* usl = u->isSlice()) {
|
||||
Logger::println("from slice");
|
||||
Logger::cout() << "from: " << *usl->ptr << " to: " << *ptrty << '\n';
|
||||
rval = new llvm::BitCastInst(usl->ptr, ptrty, "tmp", gIR->scopebb());
|
||||
rval = DtoBitCast(usl->ptr, ptrty);
|
||||
if (fromtype->next->size() == totype->next->size())
|
||||
rval2 = DtoArrayLen(usl);
|
||||
else
|
||||
rval2 = DtoArrayCastLength(DtoArrayLen(usl), ety, ptrty->getContainedType(0));
|
||||
}
|
||||
else {
|
||||
llvm::Value* uval = u->getRVal();
|
||||
LLValue* uval = u->getRVal();
|
||||
if (fromtype->ty == Tsarray) {
|
||||
Logger::cout() << "uvalTy = " << *uval->getType() << '\n';
|
||||
assert(isaPointer(uval->getType()));
|
||||
const llvm::ArrayType* arrty = isaArray(uval->getType()->getContainedType(0));
|
||||
rval2 = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false);
|
||||
rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0));
|
||||
rval = new llvm::BitCastInst(uval, ptrty, "tmp", gIR->scopebb());
|
||||
rval = DtoBitCast(uval, ptrty);
|
||||
}
|
||||
else {
|
||||
llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
|
||||
llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
|
||||
LLValue* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
|
||||
LLValue* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
|
||||
rval2 = DtoGEP(uval,zero,zero,"tmp",gIR->scopebb());
|
||||
rval2 = new llvm::LoadInst(rval2, "tmp", gIR->scopebb());
|
||||
rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0));
|
||||
@@ -1076,7 +1065,7 @@ DValue* DtoCastArray(DValue* u, Type* to)
|
||||
rval = DtoGEP(uval,zero,one,"tmp",gIR->scopebb());
|
||||
rval = new llvm::LoadInst(rval, "tmp", gIR->scopebb());
|
||||
//Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n';
|
||||
rval = new llvm::BitCastInst(rval, ptrty, "tmp", gIR->scopebb());
|
||||
rval = DtoBitCast(rval, ptrty);
|
||||
}
|
||||
}
|
||||
isslice = true;
|
||||
|
||||
30
gen/arrays.h
30
gen/arrays.h
@@ -6,18 +6,18 @@ struct DSliceValue;
|
||||
const llvm::StructType* DtoArrayType(Type* t);
|
||||
const llvm::ArrayType* DtoStaticArrayType(Type* t);
|
||||
|
||||
llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* si);
|
||||
llvm::Constant* DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr);
|
||||
llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c);
|
||||
LLConstant* DtoConstArrayInitializer(ArrayInitializer* si);
|
||||
LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr);
|
||||
LLConstant* DtoConstStaticArray(const llvm::Type* t, LLConstant* c);
|
||||
|
||||
void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src);
|
||||
void DtoArrayCopyToSlice(DSliceValue* dst, DValue* 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 DtoSetArrayToNull(llvm::Value* v);
|
||||
void DtoArrayInit(LLValue* l, LLValue* r);
|
||||
void DtoArrayInit(LLValue* ptr, LLValue* dim, LLValue* val);
|
||||
void DtoArrayAssign(LLValue* l, LLValue* r);
|
||||
void DtoSetArray(LLValue* arr, LLValue* dim, LLValue* ptr);
|
||||
void DtoSetArrayToNull(LLValue* v);
|
||||
|
||||
DSliceValue* DtoNewDynArray(Type* arrayType, DValue* dim, bool defaultInit=true);
|
||||
DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim);
|
||||
@@ -27,17 +27,17 @@ DSliceValue* DtoCatAssignArray(DValue* arr, Expression* exp);
|
||||
DSliceValue* DtoCatArrays(Type* type, Expression* e1, Expression* e2);
|
||||
DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2);
|
||||
|
||||
void DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src);
|
||||
void DtoStaticArrayCopy(LLValue* dst, LLValue* src);
|
||||
|
||||
llvm::Value* DtoArrayEquals(TOK op, DValue* l, DValue* r);
|
||||
llvm::Value* DtoArrayCompare(TOK op, DValue* l, DValue* r);
|
||||
LLValue* DtoArrayEquals(TOK op, DValue* l, DValue* r);
|
||||
LLValue* DtoArrayCompare(TOK op, DValue* l, DValue* r);
|
||||
|
||||
llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r);
|
||||
LLValue* DtoDynArrayIs(TOK op, LLValue* l, LLValue* r);
|
||||
|
||||
llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty);
|
||||
LLValue* DtoArrayCastLength(LLValue* len, const llvm::Type* elemty, const llvm::Type* newelemty);
|
||||
|
||||
llvm::Value* DtoArrayLen(DValue* v);
|
||||
llvm::Value* DtoArrayPtr(DValue* v);
|
||||
LLValue* DtoArrayLen(DValue* v);
|
||||
LLValue* DtoArrayPtr(DValue* v);
|
||||
|
||||
DValue* DtoCastArray(DValue* val, Type* to);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
DValue* DtoBinAdd(DValue* lhs, DValue* rhs)
|
||||
{
|
||||
llvm::Value* v = gIR->ir->CreateAdd(lhs->getRVal(), rhs->getRVal(), "tmp");
|
||||
LLValue* v = gIR->ir->CreateAdd(lhs->getRVal(), rhs->getRVal(), "tmp");
|
||||
return new DImValue( lhs->getType(), v );
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ DValue* DtoBinAdd(DValue* lhs, DValue* rhs)
|
||||
|
||||
DValue* DtoBinSub(DValue* lhs, DValue* rhs)
|
||||
{
|
||||
llvm::Value* v = gIR->ir->CreateSub(lhs->getRVal(), rhs->getRVal(), "tmp");
|
||||
LLValue* v = gIR->ir->CreateSub(lhs->getRVal(), rhs->getRVal(), "tmp");
|
||||
return new DImValue( lhs->getType(), v );
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ DValue* DtoBinSub(DValue* lhs, DValue* rhs)
|
||||
|
||||
DValue* DtoBinMul(DValue* lhs, DValue* rhs)
|
||||
{
|
||||
llvm::Value* v = gIR->ir->CreateMul(lhs->getRVal(), rhs->getRVal(), "tmp");
|
||||
LLValue* v = gIR->ir->CreateMul(lhs->getRVal(), rhs->getRVal(), "tmp");
|
||||
return new DImValue( lhs->getType(), v );
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ DValue* DtoBinDiv(DValue* lhs, DValue* rhs)
|
||||
llvm::Value *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
llvm::Value* res;
|
||||
LLValue* res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFDiv(l, r, "tmp");
|
||||
else if (!t->isunsigned())
|
||||
@@ -56,7 +56,7 @@ DValue* DtoBinRem(DValue* lhs, DValue* rhs)
|
||||
llvm::Value *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
llvm::Value* res;
|
||||
LLValue* res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFRem(l, r, "tmp");
|
||||
else if (!t->isunsigned())
|
||||
|
||||
192
gen/classes.cpp
192
gen/classes.cpp
@@ -129,11 +129,11 @@ void DtoResolveClass(ClassDeclaration* cd)
|
||||
gIR->classes.push_back(cd);
|
||||
|
||||
// vector holding the field types
|
||||
std::vector<const llvm::Type*> fieldtypes;
|
||||
std::vector<const LLType*> fieldtypes;
|
||||
|
||||
// add vtable
|
||||
ts->ir.vtblType = new llvm::PATypeHolder(llvm::OpaqueType::get());
|
||||
const llvm::Type* vtabty = getPtrToType(ts->ir.vtblType->get());
|
||||
const LLType* vtabty = getPtrToType(ts->ir.vtblType->get());
|
||||
fieldtypes.push_back(vtabty);
|
||||
|
||||
// add monitor
|
||||
@@ -162,7 +162,7 @@ void DtoResolveClass(ClassDeclaration* cd)
|
||||
Logger::println("has fields");
|
||||
unsigned prevsize = (unsigned)-1;
|
||||
unsigned lastoffset = (unsigned)-1;
|
||||
const llvm::Type* fieldtype = NULL;
|
||||
const LLType* fieldtype = NULL;
|
||||
VarDeclaration* fieldinit = NULL;
|
||||
size_t fieldpad = 0;
|
||||
int idx = 0;
|
||||
@@ -241,7 +241,7 @@ void DtoResolveClass(ClassDeclaration* cd)
|
||||
|
||||
// set vtbl type
|
||||
TypeClass* itc = (TypeClass*)id->type;
|
||||
const llvm::Type* ivtblTy = getPtrToType(itc->ir.vtblType->get());
|
||||
const LLType* ivtblTy = getPtrToType(itc->ir.vtblType->get());
|
||||
fieldtypes.push_back(ivtblTy);
|
||||
|
||||
// fix the interface vtable type
|
||||
@@ -287,7 +287,7 @@ void DtoResolveClass(ClassDeclaration* cd)
|
||||
= llvm::ArrayType::get(getVoidPtrType(), cd->vtbl.dim);
|
||||
|
||||
#else
|
||||
std::vector<const llvm::Type*> sinits_ty;
|
||||
std::vector<const LLType*> sinits_ty;
|
||||
|
||||
for (int k=0; k < cd->vtbl.dim; k++)
|
||||
{
|
||||
@@ -299,14 +299,14 @@ void DtoResolveClass(ClassDeclaration* cd)
|
||||
DtoResolveFunction(fd);
|
||||
//assert(fd->type->ty == Tfunction);
|
||||
//TypeFunction* tf = (TypeFunction*)fd->type;
|
||||
//const llvm::Type* fpty = getPtrToType(tf->ir.type->get());
|
||||
//const LLType* fpty = getPtrToType(tf->ir.type->get());
|
||||
const llvm::FunctionType* vfty = DtoBaseFunctionType(fd);
|
||||
const llvm::Type* vfpty = getPtrToType(vfty);
|
||||
const LLType* vfpty = getPtrToType(vfty);
|
||||
sinits_ty.push_back(vfpty);
|
||||
}
|
||||
else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) {
|
||||
Logger::println("*** ClassDeclaration in vtable: %s", cd2->toChars());
|
||||
const llvm::Type* cinfoty;
|
||||
const LLType* cinfoty;
|
||||
if (cd->isInterfaceDeclaration()) {
|
||||
cinfoty = infoTy;
|
||||
}
|
||||
@@ -317,7 +317,7 @@ void DtoResolveClass(ClassDeclaration* cd)
|
||||
// this is the ClassInfo class, the type is this type
|
||||
cinfoty = ts->ir.type->get();
|
||||
}
|
||||
const llvm::Type* cty = getPtrToType(cinfoty);
|
||||
const LLType* cty = getPtrToType(cinfoty);
|
||||
sinits_ty.push_back(cty);
|
||||
}
|
||||
else
|
||||
@@ -420,7 +420,7 @@ void DtoDeclareClass(ClassDeclaration* cd)
|
||||
|
||||
assert(iri->vtblTy);
|
||||
iri->vtbl = new llvm::GlobalVariable(iri->vtblTy, true, _linkage, 0, nam, gIR->module);
|
||||
llvm::Constant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)};
|
||||
LLConstant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)};
|
||||
iri->info = llvm::ConstantExpr::getGetElementPtr(irstruct->interfaceInfos, idxs, 2);
|
||||
idx++;
|
||||
}
|
||||
@@ -477,18 +477,18 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i)
|
||||
{
|
||||
IrStruct::Offset* so = &i->second;
|
||||
llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
|
||||
LLConstant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
|
||||
so->init = finit;
|
||||
so->var->ir.irField->constInit = finit;
|
||||
}
|
||||
|
||||
// fill out fieldtypes/inits
|
||||
std::vector<llvm::Constant*> fieldinits;
|
||||
std::vector<LLConstant*> fieldinits;
|
||||
|
||||
// first field is always the vtable
|
||||
if (cd->isAbstract() || cd->isInterfaceDeclaration())
|
||||
{
|
||||
const llvm::Type* ptrTy = getPtrToType(ts->ir.vtblType->get());
|
||||
const LLType* ptrTy = getPtrToType(ts->ir.vtblType->get());
|
||||
fieldinits.push_back(llvm::Constant::getNullValue(ptrTy));
|
||||
}
|
||||
else
|
||||
@@ -503,7 +503,7 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
// go through the field inits and build the default initializer
|
||||
size_t nfi = irstruct->defaultFields.size();
|
||||
for (size_t i=0; i<nfi; ++i) {
|
||||
llvm::Constant* c;
|
||||
LLConstant* c;
|
||||
if (irstruct->defaultFields[i]) {
|
||||
c = irstruct->defaultFields[i]->ir.irField->constInit;
|
||||
assert(c);
|
||||
@@ -511,7 +511,7 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
else {
|
||||
const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i+2));
|
||||
assert(arrty);
|
||||
std::vector<llvm::Constant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
|
||||
std::vector<LLConstant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
|
||||
c = llvm::ConstantArray::get(arrty, vals);
|
||||
}
|
||||
fieldinits.push_back(c);
|
||||
@@ -552,7 +552,7 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
}
|
||||
#endif
|
||||
|
||||
llvm::Constant* _init = llvm::ConstantStruct::get(structtype, fieldinits);
|
||||
LLConstant* _init = llvm::ConstantStruct::get(structtype, fieldinits);
|
||||
assert(_init);
|
||||
cd->ir.irStruct->constInit = _init;
|
||||
|
||||
@@ -561,7 +561,7 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
if (!cd->isInterfaceDeclaration() && !cd->isAbstract())
|
||||
{
|
||||
// generate vtable initializer
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
|
||||
for (int k=0; k < cd->vtbl.dim; k++)
|
||||
{
|
||||
@@ -570,12 +570,12 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
//Logger::cout() << "vtblsym: " << dsym->toChars() << '\n';
|
||||
|
||||
#if OPAQUE_VTBLS
|
||||
const llvm::Type* targetTy = getVoidPtrType();
|
||||
const LLType* targetTy = getVoidPtrType();
|
||||
#else
|
||||
const llvm::Type* targetTy = vtbltype->getElementType(k);
|
||||
const LLType* targetTy = vtbltype->getElementType(k);
|
||||
#endif
|
||||
|
||||
llvm::Constant* c = NULL;
|
||||
LLConstant* c = NULL;
|
||||
// virtual method
|
||||
if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
|
||||
DtoForceDeclareDsymbol(fd);
|
||||
@@ -599,7 +599,7 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
cd->ir.irStruct->constVtbl = llvm::ConstantArray::get(svtbl_ty, sinits);
|
||||
#else
|
||||
const llvm::StructType* svtbl_ty = isaStruct(ts->ir.vtblType->get());
|
||||
llvm::Constant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits);
|
||||
LLConstant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits);
|
||||
cd->ir.irStruct->constVtbl = llvm::cast<llvm::ConstantStruct>(cvtblInit);
|
||||
#endif
|
||||
|
||||
@@ -620,15 +620,15 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
#endif
|
||||
|
||||
// generate interface info initializer
|
||||
std::vector<llvm::Constant*> infoInits;
|
||||
std::vector<LLConstant*> infoInits;
|
||||
|
||||
// classinfo
|
||||
assert(id->ir.irStruct->classInfo);
|
||||
llvm::Constant* c = id->ir.irStruct->classInfo;
|
||||
LLConstant* c = id->ir.irStruct->classInfo;
|
||||
infoInits.push_back(c);
|
||||
|
||||
// vtbl
|
||||
const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
|
||||
const LLType* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
|
||||
c = llvm::ConstantExpr::getBitCast(iri->vtbl, byteptrptrty);
|
||||
c = DtoConstSlice(DtoConstSize_t(b->vtbl.dim), c);
|
||||
infoInits.push_back(c);
|
||||
@@ -642,11 +642,11 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
iri->infoInit = llvm::cast<llvm::ConstantStruct>(llvm::ConstantStruct::get(iri->infoTy, infoInits));
|
||||
|
||||
// generate vtable initializer
|
||||
std::vector<llvm::Constant*> iinits;
|
||||
std::vector<LLConstant*> iinits;
|
||||
|
||||
// add interface info
|
||||
#if OPAQUE_VTBLS
|
||||
const llvm::Type* targetTy = getVoidPtrType();
|
||||
const LLType* targetTy = getVoidPtrType();
|
||||
iinits.push_back(llvm::ConstantExpr::getBitCast(iri->info, targetTy));
|
||||
#else
|
||||
iinits.push_back(iri->info);
|
||||
@@ -661,10 +661,10 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
assert(fd);
|
||||
DtoForceDeclareDsymbol(fd);
|
||||
assert(fd->ir.irFunc->func);
|
||||
llvm::Constant* c = llvm::cast<llvm::Constant>(fd->ir.irFunc->func);
|
||||
LLConstant* c = llvm::cast<llvm::Constant>(fd->ir.irFunc->func);
|
||||
|
||||
#if !OPAQUE_VTBLS
|
||||
const llvm::Type* targetTy = iri->vtblTy->getContainedType(k);
|
||||
const LLType* targetTy = iri->vtblTy->getContainedType(k);
|
||||
#endif
|
||||
|
||||
// we have to bitcast, as the type created in ResolveClass expects a different this type
|
||||
@@ -675,10 +675,10 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
|
||||
#if OPAQUE_VTBLS
|
||||
Logger::cout() << "n: " << iinits.size() << " ivtbl_ty: " << *ivtbl_ty << '\n';
|
||||
llvm::Constant* civtblInit = llvm::ConstantArray::get(ivtbl_ty, iinits);
|
||||
LLConstant* civtblInit = llvm::ConstantArray::get(ivtbl_ty, iinits);
|
||||
iri->vtblInit = llvm::cast<llvm::ConstantArray>(civtblInit);
|
||||
#else
|
||||
llvm::Constant* civtblInit = llvm::ConstantStruct::get(ivtbl_ty, iinits);
|
||||
LLConstant* civtblInit = llvm::ConstantStruct::get(ivtbl_ty, iinits);
|
||||
iri->vtblInit = llvm::cast<llvm::ConstantStruct>(civtblInit);
|
||||
#endif
|
||||
}
|
||||
@@ -698,15 +698,15 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
TypeClass* its = (TypeClass*)id->type;
|
||||
|
||||
// generate interface info initializer
|
||||
std::vector<llvm::Constant*> infoInits;
|
||||
std::vector<LLConstant*> infoInits;
|
||||
|
||||
// classinfo
|
||||
assert(id->ir.irStruct->classInfo);
|
||||
llvm::Constant* c = id->ir.irStruct->classInfo;
|
||||
LLConstant* c = id->ir.irStruct->classInfo;
|
||||
infoInits.push_back(c);
|
||||
|
||||
// vtbl
|
||||
const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
|
||||
const LLType* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
|
||||
c = DtoConstSlice(DtoConstSize_t(0), getNullPtr(byteptrptrty));
|
||||
infoInits.push_back(c);
|
||||
|
||||
@@ -758,7 +758,7 @@ void DtoDefineClass(ClassDeclaration* cd)
|
||||
|
||||
// always do interface info array when possible
|
||||
IrStruct* irstruct = cd->ir.irStruct;
|
||||
std::vector<llvm::Constant*> infoInits;
|
||||
std::vector<LLConstant*> infoInits;
|
||||
for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
|
||||
{
|
||||
IrInterface* iri = *i;
|
||||
@@ -767,7 +767,7 @@ void DtoDefineClass(ClassDeclaration* cd)
|
||||
// set initializer
|
||||
if (!infoInits.empty())
|
||||
{
|
||||
llvm::Constant* arrInit = llvm::ConstantArray::get(irstruct->interfaceInfosTy, infoInits);
|
||||
LLConstant* arrInit = llvm::ConstantArray::get(irstruct->interfaceInfosTy, infoInits);
|
||||
irstruct->interfaceInfos->setInitializer(arrInit);
|
||||
}
|
||||
else
|
||||
@@ -788,7 +788,7 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
|
||||
DtoForceDeclareDsymbol(tc->sym);
|
||||
|
||||
// allocate
|
||||
llvm::Value* mem;
|
||||
LLValue* mem;
|
||||
if (newexp->onstack)
|
||||
{
|
||||
mem = new llvm::AllocaInst(DtoType(tc)->getContainedType(0), "newclass_alloca", gIR->topallocapoint());
|
||||
@@ -796,7 +796,7 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
|
||||
else
|
||||
{
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newclass");
|
||||
std::vector<llvm::Value*> args;
|
||||
std::vector<LLValue*> args;
|
||||
args.push_back(tc->sym->ir.irStruct->classInfo);
|
||||
mem = gIR->ir->CreateCall(fn, args.begin(), args.end(), "newclass_gc_alloc");
|
||||
mem = DtoBitCast(mem, DtoType(tc), "newclass_gc");
|
||||
@@ -812,8 +812,8 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
|
||||
LOG_SCOPE;
|
||||
DValue* thisval = newexp->thisexp->toElem(gIR);
|
||||
size_t idx = 2 + tc->sym->vthis->ir.irField->index;
|
||||
llvm::Value* src = thisval->getRVal();
|
||||
llvm::Value* dst = DtoGEPi(mem,0,idx,"tmp");
|
||||
LLValue* src = thisval->getRVal();
|
||||
LLValue* dst = DtoGEPi(mem,0,idx,"tmp");
|
||||
Logger::cout() << "dst: " << *dst << "\nsrc: " << *src << '\n';
|
||||
DtoStore(src, dst);
|
||||
}
|
||||
@@ -824,11 +824,11 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
|
||||
LOG_SCOPE;
|
||||
size_t idx = 2;
|
||||
//idx += tc->sym->ir.irStruct->interfaces.size();
|
||||
llvm::Value* nest = gIR->func()->decl->ir.irFunc->nestedVar;
|
||||
LLValue* nest = gIR->func()->decl->ir.irFunc->nestedVar;
|
||||
if (!nest)
|
||||
nest = gIR->func()->decl->ir.irFunc->thisVar;
|
||||
assert(nest);
|
||||
llvm::Value* gep = DtoGEPi(mem,0,idx,"tmp");
|
||||
LLValue* gep = DtoGEPi(mem,0,idx,"tmp");
|
||||
nest = DtoBitCast(nest, gep->getType()->getContainedType(0));
|
||||
DtoStore(nest, gep);
|
||||
}
|
||||
@@ -846,7 +846,7 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoInitClass(TypeClass* tc, llvm::Value* dst)
|
||||
void DtoInitClass(TypeClass* tc, LLValue* dst)
|
||||
{
|
||||
size_t presz = 2*getABITypeSize(DtoSize_t());
|
||||
uint64_t n = getABITypeSize(tc->ir.type->get()) - presz;
|
||||
@@ -856,7 +856,7 @@ void DtoInitClass(TypeClass* tc, llvm::Value* dst)
|
||||
DtoStore(tc->sym->ir.irStruct->vtbl, DtoGEPi(dst,0,0,"vtbl"));
|
||||
|
||||
// monitor always defaults to zero
|
||||
llvm::Value* tmp = DtoGEPi(dst,0,1,"monitor");
|
||||
LLValue* tmp = DtoGEPi(dst,0,1,"monitor");
|
||||
DtoStore(llvm::Constant::getNullValue(tmp->getType()->getContainedType(0)), tmp);
|
||||
|
||||
// done?
|
||||
@@ -867,16 +867,16 @@ void DtoInitClass(TypeClass* tc, llvm::Value* dst)
|
||||
assert(tc->sym->ir.irStruct->init);
|
||||
assert(dst->getType() == tc->sym->ir.irStruct->init->getType());
|
||||
|
||||
const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
const LLType* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
|
||||
llvm::Value* dstarr = DtoGEPi(dst,0,2,"tmp");
|
||||
LLValue* dstarr = DtoGEPi(dst,0,2,"tmp");
|
||||
dstarr = DtoBitCast(dstarr, arrty);
|
||||
|
||||
llvm::Value* srcarr = DtoGEPi(tc->sym->ir.irStruct->init,0,2,"tmp");
|
||||
LLValue* srcarr = DtoGEPi(tc->sym->ir.irStruct->init,0,2,"tmp");
|
||||
srcarr = DtoBitCast(srcarr, arrty);
|
||||
|
||||
llvm::Function* fn = LLVM_DeclareMemCpy32();
|
||||
std::vector<llvm::Value*> llargs;
|
||||
std::vector<LLValue*> llargs;
|
||||
llargs.resize(4);
|
||||
llargs[0] = dstarr;
|
||||
llargs[1] = srcarr;
|
||||
@@ -888,7 +888,7 @@ void DtoInitClass(TypeClass* tc, llvm::Value* dst)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, llvm::Value* mem)
|
||||
DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, LLValue* mem)
|
||||
{
|
||||
Logger::println("Calling constructor");
|
||||
LOG_SCOPE;
|
||||
@@ -898,15 +898,15 @@ DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* argument
|
||||
llvm::Function* fn = ctor->ir.irFunc->func;
|
||||
TypeFunction* tf = (TypeFunction*)DtoDType(ctor->type);
|
||||
|
||||
std::vector<llvm::Value*> ctorargs;
|
||||
std::vector<LLValue*> ctorargs;
|
||||
ctorargs.push_back(mem);
|
||||
for (size_t i=0; i<arguments->dim; ++i)
|
||||
{
|
||||
Expression* ex = (Expression*)arguments->data[i];
|
||||
Argument* fnarg = Argument::getNth(tf->parameters, i);
|
||||
DValue* argval = DtoArgument(fnarg, ex);
|
||||
llvm::Value* a = argval->getRVal();
|
||||
const llvm::Type* aty = fn->getFunctionType()->getParamType(i+1);
|
||||
LLValue* a = argval->getRVal();
|
||||
const LLType* aty = fn->getFunctionType()->getParamType(i+1);
|
||||
if (a->getType() != aty)
|
||||
a = DtoBitCast(a, aty);
|
||||
ctorargs.push_back(a);
|
||||
@@ -919,12 +919,12 @@ DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* argument
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoFinalizeClass(llvm::Value* inst)
|
||||
void DtoFinalizeClass(LLValue* inst)
|
||||
{
|
||||
// get runtime function
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_callfinalizer");
|
||||
// build args
|
||||
llvm::SmallVector<llvm::Value*,1> arg;
|
||||
LLSmallVector<LLValue*,1> arg;
|
||||
arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
|
||||
// call
|
||||
llvm::CallInst::Create(fn, arg.begin(), arg.end(), "", gIR->scopebb());
|
||||
@@ -939,8 +939,8 @@ DValue* DtoCastClass(DValue* val, Type* _to)
|
||||
|
||||
Type* to = DtoDType(_to);
|
||||
if (to->ty == Tpointer) {
|
||||
const llvm::Type* tolltype = DtoType(_to);
|
||||
llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype);
|
||||
const LLType* tolltype = DtoType(_to);
|
||||
LLValue* rval = DtoBitCast(val->getRVal(), tolltype);
|
||||
return new DImValue(_to, rval);
|
||||
}
|
||||
|
||||
@@ -970,8 +970,8 @@ DValue* DtoCastClass(DValue* val, Type* _to)
|
||||
}
|
||||
else if (!tc->sym->isInterfaceDeclaration() && tc->sym->isBaseOf(fc->sym,NULL)) {
|
||||
Logger::println("static down cast)");
|
||||
const llvm::Type* tolltype = DtoType(_to);
|
||||
llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype);
|
||||
const LLType* tolltype = DtoType(_to);
|
||||
LLValue* rval = DtoBitCast(val->getRVal(), tolltype);
|
||||
return new DImValue(_to, rval);
|
||||
}
|
||||
else {
|
||||
@@ -994,10 +994,10 @@ DValue* DtoDynamicCastObject(DValue* val, Type* _to)
|
||||
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast");
|
||||
const llvm::FunctionType* funcTy = func->getFunctionType();
|
||||
|
||||
std::vector<llvm::Value*> args;
|
||||
std::vector<LLValue*> args;
|
||||
|
||||
// Object o
|
||||
llvm::Value* tmp = val->getRVal();
|
||||
LLValue* tmp = val->getRVal();
|
||||
tmp = DtoBitCast(tmp, funcTy->getParamType(0));
|
||||
args.push_back(tmp);
|
||||
assert(funcTy->getParamType(0) == tmp->getType());
|
||||
@@ -1014,7 +1014,7 @@ DValue* DtoDynamicCastObject(DValue* val, Type* _to)
|
||||
assert(funcTy->getParamType(1) == tmp->getType());
|
||||
|
||||
// call it
|
||||
llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp");
|
||||
LLValue* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp");
|
||||
|
||||
// cast return value
|
||||
ret = DtoBitCast(ret, DtoType(_to));
|
||||
@@ -1033,11 +1033,11 @@ DValue* DtoCastInterfaceToObject(DValue* val, Type* to)
|
||||
const llvm::FunctionType* funcTy = func->getFunctionType();
|
||||
|
||||
// void* p
|
||||
llvm::Value* tmp = val->getRVal();
|
||||
LLValue* tmp = val->getRVal();
|
||||
tmp = DtoBitCast(tmp, funcTy->getParamType(0));
|
||||
|
||||
// call it
|
||||
llvm::Value* ret = gIR->ir->CreateCall(func, tmp, "tmp");
|
||||
LLValue* ret = gIR->ir->CreateCall(func, tmp, "tmp");
|
||||
|
||||
// cast return value
|
||||
if (to != NULL)
|
||||
@@ -1061,10 +1061,10 @@ DValue* DtoDynamicCastInterface(DValue* val, Type* _to)
|
||||
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_interface_cast");
|
||||
const llvm::FunctionType* funcTy = func->getFunctionType();
|
||||
|
||||
std::vector<llvm::Value*> args;
|
||||
std::vector<LLValue*> args;
|
||||
|
||||
// void* p
|
||||
llvm::Value* tmp = val->getRVal();
|
||||
LLValue* tmp = val->getRVal();
|
||||
tmp = DtoBitCast(tmp, funcTy->getParamType(0));
|
||||
args.push_back(tmp);
|
||||
|
||||
@@ -1079,7 +1079,7 @@ DValue* DtoDynamicCastInterface(DValue* val, Type* _to)
|
||||
args.push_back(tmp);
|
||||
|
||||
// call it
|
||||
llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp");
|
||||
LLValue* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp");
|
||||
|
||||
// cast return value
|
||||
ret = DtoBitCast(ret, DtoType(_to));
|
||||
@@ -1127,7 +1127,7 @@ void ClassDeclaration::offsetToIndex(Type* t, unsigned os, std::vector<unsigned>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsigned os, std::vector<unsigned>& idxs)
|
||||
LLValue* DtoIndexClass(LLValue* ptr, ClassDeclaration* cd, Type* t, unsigned os, std::vector<unsigned>& idxs)
|
||||
{
|
||||
Logger::println("checking for offset %u type %s:", os, t->toChars());
|
||||
LOG_SCOPE;
|
||||
@@ -1135,13 +1135,13 @@ llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsi
|
||||
if (idxs.empty())
|
||||
idxs.push_back(0);
|
||||
|
||||
const llvm::Type* st = DtoType(cd->type);
|
||||
const LLType* st = DtoType(cd->type);
|
||||
if (ptr->getType() != st) {
|
||||
//assert(cd->ir.irStruct->hasUnions);
|
||||
ptr = gIR->ir->CreateBitCast(ptr, st, "tmp");
|
||||
}
|
||||
|
||||
const llvm::Type* llt = getPtrToType(DtoType(t));
|
||||
const LLType* llt = getPtrToType(DtoType(t));
|
||||
unsigned dataoffset = 2;
|
||||
|
||||
IrStruct* irstruct = cd->ir.irStruct;
|
||||
@@ -1180,7 +1180,7 @@ llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsi
|
||||
return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
|
||||
}
|
||||
else {
|
||||
const llvm::Type* sty = getPtrToType(DtoType(vd->type));
|
||||
const LLType* sty = getPtrToType(DtoType(vd->type));
|
||||
if (ptr->getType() != sty) {
|
||||
ptr = gIR->ir->CreateBitCast(ptr, sty, "tmp");
|
||||
std::vector<unsigned> tmp;
|
||||
@@ -1203,16 +1203,16 @@ llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsi
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl)
|
||||
LLValue* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl)
|
||||
{
|
||||
assert(fdecl->isVirtual());//fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual()));
|
||||
assert(fdecl->vtblIndex > 0);
|
||||
assert(DtoDType(inst->getType())->ty == Tclass);
|
||||
|
||||
llvm::Value* vthis = inst->getRVal();
|
||||
LLValue* vthis = inst->getRVal();
|
||||
Logger::cout() << "vthis: " << *vthis << '\n';
|
||||
|
||||
llvm::Value* funcval;
|
||||
LLValue* funcval;
|
||||
funcval = DtoGEPi(vthis, 0, 0, "tmp");
|
||||
funcval = DtoLoad(funcval);
|
||||
funcval = DtoGEPi(funcval, 0, fdecl->vtblIndex, fdecl->toPrettyChars());
|
||||
@@ -1251,15 +1251,15 @@ void DtoDeclareClassInfo(ClassDeclaration* cd)
|
||||
else
|
||||
gname.append("11__InterfaceZ");
|
||||
|
||||
const llvm::Type* st = cinfo->type->ir.type->get();
|
||||
const LLType* st = cinfo->type->ir.type->get();
|
||||
|
||||
cd->ir.irStruct->classInfo = new llvm::GlobalVariable(st, true, DtoLinkage(cd), NULL, gname, gIR->module);
|
||||
}
|
||||
|
||||
static llvm::Constant* build_offti_entry(VarDeclaration* vd)
|
||||
static LLConstant* build_offti_entry(VarDeclaration* vd)
|
||||
{
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<llvm::Constant*> inits;
|
||||
std::vector<const LLType*> types;
|
||||
std::vector<LLConstant*> inits;
|
||||
|
||||
types.push_back(DtoSize_t());
|
||||
|
||||
@@ -1274,9 +1274,9 @@ static llvm::Constant* build_offti_entry(VarDeclaration* vd)
|
||||
vd->type->getTypeInfo(NULL);
|
||||
assert(vd->type->vtinfo);
|
||||
DtoForceDeclareDsymbol(vd->type->vtinfo);
|
||||
llvm::Constant* c = isaConstant(vd->type->vtinfo->ir.getIrValue());
|
||||
LLConstant* c = isaConstant(vd->type->vtinfo->ir.getIrValue());
|
||||
|
||||
const llvm::Type* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get());
|
||||
const LLType* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get());
|
||||
//Logger::cout() << "tiTy = " << *tiTy << '\n';
|
||||
|
||||
types.push_back(tiTy);
|
||||
@@ -1286,12 +1286,12 @@ static llvm::Constant* build_offti_entry(VarDeclaration* vd)
|
||||
return llvm::ConstantStruct::get(sTy, inits);
|
||||
}
|
||||
|
||||
static llvm::Constant* build_offti_array(ClassDeclaration* cd, llvm::Constant* init)
|
||||
static LLConstant* build_offti_array(ClassDeclaration* cd, LLConstant* init)
|
||||
{
|
||||
const llvm::StructType* initTy = isaStruct(init->getType());
|
||||
assert(initTy);
|
||||
|
||||
std::vector<llvm::Constant*> arrayInits;
|
||||
std::vector<LLConstant*> arrayInits;
|
||||
for (ClassDeclaration *cd2 = cd; cd2; cd2 = cd2->baseClass)
|
||||
{
|
||||
if (cd2->members)
|
||||
@@ -1301,7 +1301,7 @@ static llvm::Constant* build_offti_array(ClassDeclaration* cd, llvm::Constant* i
|
||||
Dsymbol *sm = (Dsymbol *)cd2->members->data[i];
|
||||
if (VarDeclaration* vd = sm->isVarDeclaration()) // is this enough?
|
||||
{
|
||||
llvm::Constant* c = build_offti_entry(vd);
|
||||
LLConstant* c = build_offti_entry(vd);
|
||||
assert(c);
|
||||
arrayInits.push_back(c);
|
||||
}
|
||||
@@ -1310,20 +1310,20 @@ static llvm::Constant* build_offti_array(ClassDeclaration* cd, llvm::Constant* i
|
||||
}
|
||||
|
||||
size_t ninits = arrayInits.size();
|
||||
llvm::Constant* size = DtoConstSize_t(ninits);
|
||||
llvm::Constant* ptr;
|
||||
LLConstant* size = DtoConstSize_t(ninits);
|
||||
LLConstant* ptr;
|
||||
|
||||
if (ninits > 0) {
|
||||
// OffsetTypeInfo type
|
||||
std::vector<const llvm::Type*> elemtypes;
|
||||
std::vector<const LLType*> elemtypes;
|
||||
elemtypes.push_back(DtoSize_t());
|
||||
const llvm::Type* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get());
|
||||
const LLType* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get());
|
||||
elemtypes.push_back(tiTy);
|
||||
const llvm::StructType* sTy = llvm::StructType::get(elemtypes);
|
||||
|
||||
// array type
|
||||
const llvm::ArrayType* arrTy = llvm::ArrayType::get(sTy, ninits);
|
||||
llvm::Constant* arrInit = llvm::ConstantArray::get(arrTy, arrayInits);
|
||||
LLConstant* arrInit = llvm::ConstantArray::get(arrTy, arrayInits);
|
||||
|
||||
std::string name(cd->type->vtinfo->toChars());
|
||||
name.append("__OffsetTypeInfos");
|
||||
@@ -1338,10 +1338,10 @@ static llvm::Constant* build_offti_array(ClassDeclaration* cd, llvm::Constant* i
|
||||
return DtoConstSlice(size, ptr);
|
||||
}
|
||||
|
||||
static llvm::Constant* build_class_dtor(ClassDeclaration* cd)
|
||||
static LLConstant* build_class_dtor(ClassDeclaration* cd)
|
||||
{
|
||||
// construct the function
|
||||
std::vector<const llvm::Type*> paramTypes;
|
||||
std::vector<const LLType*> paramTypes;
|
||||
paramTypes.push_back(getPtrToType(cd->type->ir.type->get()));
|
||||
|
||||
const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy, paramTypes, false);
|
||||
@@ -1361,7 +1361,7 @@ static llvm::Constant* build_class_dtor(ClassDeclaration* cd)
|
||||
gname.append("12__destructorMFZv");
|
||||
|
||||
llvm::Function* func = llvm::Function::Create(fnTy, DtoInternalLinkage(cd), gname, gIR->module);
|
||||
llvm::Value* thisptr = func->arg_begin();
|
||||
LLValue* thisptr = func->arg_begin();
|
||||
thisptr->setName("this");
|
||||
|
||||
llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", func);
|
||||
@@ -1445,13 +1445,13 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
}
|
||||
|
||||
// holds the list of initializers for llvm
|
||||
std::vector<llvm::Constant*> inits;
|
||||
std::vector<LLConstant*> inits;
|
||||
|
||||
ClassDeclaration* cinfo = ClassDeclaration::classinfo;
|
||||
DtoForceConstInitDsymbol(cinfo);
|
||||
assert(cinfo->ir.irStruct->constInit);
|
||||
|
||||
llvm::Constant* c;
|
||||
LLConstant* c;
|
||||
|
||||
// own vtable
|
||||
c = cinfo->ir.irStruct->constInit->getOperand(0);
|
||||
@@ -1463,7 +1463,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
inits.push_back(c);
|
||||
|
||||
// byte[] init
|
||||
const llvm::Type* byteptrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
const LLType* byteptrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
|
||||
c = cinfo->ir.irStruct->constInit->getOperand(2);
|
||||
}
|
||||
@@ -1492,7 +1492,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
c = cinfo->ir.irStruct->constInit->getOperand(4);
|
||||
}
|
||||
else {
|
||||
const llvm::Type* byteptrptrty = getPtrToType(byteptrty);
|
||||
const LLType* byteptrptrty = getPtrToType(byteptrty);
|
||||
assert(!cd->ir.irStruct->vtbl->getType()->isAbstract());
|
||||
c = llvm::ConstantExpr::getBitCast(cd->ir.irStruct->vtbl, byteptrptrty);
|
||||
assert(!cd->ir.irStruct->constVtbl->getType()->isAbstract());
|
||||
@@ -1511,7 +1511,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
c = cinfo->ir.irStruct->constInit->getOperand(5);
|
||||
}
|
||||
else {
|
||||
const llvm::Type* t = cinfo->ir.irStruct->constInit->getOperand(5)->getType()->getContainedType(1);
|
||||
const LLType* t = cinfo->ir.irStruct->constInit->getOperand(5)->getType()->getContainedType(1);
|
||||
c = llvm::ConstantExpr::getBitCast(irstruct->interfaceInfos, t);
|
||||
size_t iisz = irstruct->interfaceInfosTy->getNumElements();
|
||||
c = DtoConstSlice(DtoConstSize_t(iisz), c);
|
||||
@@ -1573,7 +1573,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
if (cd->defaultCtor && !cd->isInterfaceDeclaration() && !cd->isAbstract()) {
|
||||
DtoForceDeclareDsymbol(cd->defaultCtor);
|
||||
c = isaConstant(cd->defaultCtor->ir.irFunc->func);
|
||||
const llvm::Type* toTy = cinfo->ir.irStruct->constInit->getOperand(12)->getType();
|
||||
const LLType* toTy = cinfo->ir.irStruct->constInit->getOperand(12)->getType();
|
||||
c = llvm::ConstantExpr::getBitCast(c, toTy);
|
||||
}
|
||||
else {
|
||||
@@ -1589,7 +1589,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
|
||||
// build the initializer
|
||||
const llvm::StructType* st = isaStruct(cinfo->ir.irStruct->constInit->getType());
|
||||
llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits);
|
||||
LLConstant* finalinit = llvm::ConstantStruct::get(st, inits);
|
||||
//Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n';
|
||||
|
||||
cd->ir.irStruct->constClassInfo = finalinit;
|
||||
|
||||
@@ -25,9 +25,9 @@ void DtoDeclareClassInfo(ClassDeclaration* cd);
|
||||
void DtoDefineClassInfo(ClassDeclaration* cd);
|
||||
|
||||
DValue* DtoNewClass(TypeClass* type, NewExp* newexp);
|
||||
void DtoInitClass(TypeClass* tc, llvm::Value* dst);
|
||||
DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, llvm::Value* mem);
|
||||
void DtoFinalizeClass(llvm::Value* inst);
|
||||
void DtoInitClass(TypeClass* tc, LLValue* dst);
|
||||
DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, LLValue* mem);
|
||||
void DtoFinalizeClass(LLValue* inst);
|
||||
|
||||
DValue* DtoCastClass(DValue* val, Type* to);
|
||||
DValue* DtoDynamicCastObject(DValue* val, Type* to);
|
||||
@@ -35,8 +35,8 @@ DValue* DtoDynamicCastObject(DValue* val, Type* to);
|
||||
DValue* DtoCastInterfaceToObject(DValue* val, Type* to);
|
||||
DValue* DtoDynamicCastInterface(DValue* val, Type* to);
|
||||
|
||||
llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsigned os, std::vector<unsigned>& idxs);
|
||||
LLValue* DtoIndexClass(LLValue* ptr, ClassDeclaration* cd, Type* t, unsigned os, std::vector<unsigned>& idxs);
|
||||
|
||||
llvm::Value* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl);
|
||||
LLValue* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,19 +14,19 @@ const llvm::StructType* DtoComplexType(Type* type)
|
||||
{
|
||||
Type* t = DtoDType(type);
|
||||
|
||||
const llvm::Type* base = DtoComplexBaseType(t);
|
||||
const LLType* base = DtoComplexBaseType(t);
|
||||
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(base);
|
||||
types.push_back(base);
|
||||
|
||||
return llvm::StructType::get(types);
|
||||
}
|
||||
|
||||
const llvm::Type* DtoComplexBaseType(Type* t)
|
||||
const LLType* DtoComplexBaseType(Type* t)
|
||||
{
|
||||
TY ty = DtoDType(t)->ty;
|
||||
const llvm::Type* base;
|
||||
const LLType* base;
|
||||
if (ty == Tcomplex32) {
|
||||
return llvm::Type::FloatTy;
|
||||
}
|
||||
@@ -40,12 +40,12 @@ const llvm::Type* DtoComplexBaseType(Type* t)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Constant* DtoConstComplex(Type* ty, llvm::Constant* re, llvm::Constant* im)
|
||||
LLConstant* DtoConstComplex(Type* ty, LLConstant* re, LLConstant* im)
|
||||
{
|
||||
assert(0);
|
||||
const llvm::Type* base = DtoComplexBaseType(ty);
|
||||
const LLType* base = DtoComplexBaseType(ty);
|
||||
|
||||
std::vector<llvm::Constant*> inits;
|
||||
std::vector<LLConstant*> inits;
|
||||
inits.push_back(re);
|
||||
inits.push_back(im);
|
||||
|
||||
@@ -53,14 +53,14 @@ llvm::Constant* DtoConstComplex(Type* ty, llvm::Constant* re, llvm::Constant* im
|
||||
return llvm::ConstantVector::get(vt, inits);
|
||||
}
|
||||
|
||||
llvm::Constant* DtoConstComplex(Type* _ty, long double re, long double im)
|
||||
LLConstant* DtoConstComplex(Type* _ty, long double re, long double im)
|
||||
{
|
||||
TY ty = DtoDType(_ty)->ty;
|
||||
|
||||
llvm::ConstantFP* fre;
|
||||
llvm::ConstantFP* fim;
|
||||
|
||||
const llvm::Type* base;
|
||||
const LLType* base;
|
||||
|
||||
if (ty == Tcomplex32) {
|
||||
fre = DtoConstFP(Type::tfloat32, re);
|
||||
@@ -75,17 +75,17 @@ llvm::Constant* DtoConstComplex(Type* _ty, long double re, long double im)
|
||||
else
|
||||
assert(0);
|
||||
|
||||
std::vector<llvm::Constant*> inits;
|
||||
std::vector<LLConstant*> inits;
|
||||
inits.push_back(fre);
|
||||
inits.push_back(fim);
|
||||
return llvm::ConstantStruct::get(DtoComplexType(_ty), inits);
|
||||
}
|
||||
|
||||
llvm::Constant* DtoUndefComplex(Type* _ty)
|
||||
LLConstant* DtoUndefComplex(Type* _ty)
|
||||
{
|
||||
assert(0);
|
||||
TY ty = DtoDType(_ty)->ty;
|
||||
const llvm::Type* base;
|
||||
const LLType* base;
|
||||
if (ty == Tcomplex32) {
|
||||
base = llvm::Type::FloatTy;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ llvm::Constant* DtoUndefComplex(Type* _ty)
|
||||
else
|
||||
assert(0);
|
||||
|
||||
std::vector<llvm::Constant*> inits;
|
||||
std::vector<LLConstant*> inits;
|
||||
inits.push_back(llvm::UndefValue::get(base));
|
||||
inits.push_back(llvm::UndefValue::get(base));
|
||||
|
||||
@@ -105,7 +105,7 @@ llvm::Constant* DtoUndefComplex(Type* _ty)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* DtoRealPart(DValue* val)
|
||||
LLValue* DtoRealPart(DValue* val)
|
||||
{
|
||||
assert(0);
|
||||
return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(0), "tmp");
|
||||
@@ -113,7 +113,7 @@ llvm::Value* DtoRealPart(DValue* val)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* DtoImagPart(DValue* val)
|
||||
LLValue* DtoImagPart(DValue* val)
|
||||
{
|
||||
assert(0);
|
||||
return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp");
|
||||
@@ -130,10 +130,10 @@ DValue* DtoComplex(Type* to, DValue* val)
|
||||
return DtoCastComplex(val, to);
|
||||
}
|
||||
|
||||
const llvm::Type* base = DtoComplexBaseType(to);
|
||||
const LLType* base = DtoComplexBaseType(to);
|
||||
|
||||
llvm::Constant* undef = llvm::UndefValue::get(base);
|
||||
llvm::Constant* zero;
|
||||
LLConstant* undef = llvm::UndefValue::get(base);
|
||||
LLConstant* zero;
|
||||
if (ty == Tfloat32 || ty == Timaginary32 || ty == Tcomplex32)
|
||||
zero = llvm::ConstantFP::get(llvm::APFloat(0.0f));
|
||||
else if (ty == Tfloat64 || ty == Timaginary64 || ty == Tcomplex64 || ty == Tfloat80 || ty == Timaginary80 || ty == Tcomplex80)
|
||||
@@ -151,13 +151,13 @@ DValue* DtoComplex(Type* to, DValue* val)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoComplexAssign(llvm::Value* l, llvm::Value* r)
|
||||
void DtoComplexAssign(LLValue* l, LLValue* r)
|
||||
{
|
||||
DtoStore(DtoLoad(DtoGEPi(r, 0,0, "tmp")), DtoGEPi(l,0,0,"tmp"));
|
||||
DtoStore(DtoLoad(DtoGEPi(r, 0,1, "tmp")), DtoGEPi(l,0,1,"tmp"));
|
||||
}
|
||||
|
||||
void DtoComplexSet(llvm::Value* c, llvm::Value* re, llvm::Value* im)
|
||||
void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im)
|
||||
{
|
||||
DtoStore(re, DtoGEPi(c,0,0,"tmp"));
|
||||
DtoStore(im, DtoGEPi(c,0,1,"tmp"));
|
||||
@@ -165,7 +165,7 @@ void DtoComplexSet(llvm::Value* c, llvm::Value* re, llvm::Value* im)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoGetComplexParts(DValue* c, llvm::Value*& re, llvm::Value*& im)
|
||||
void DtoGetComplexParts(DValue* c, LLValue*& re, LLValue*& im)
|
||||
{
|
||||
// lhs values
|
||||
if (DComplexValue* cx = c->isComplex()) {
|
||||
@@ -300,7 +300,7 @@ DValue* DtoComplexNeg(Type* type, DValue* val)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs)
|
||||
LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs)
|
||||
{
|
||||
Type* type = lhs->getType();
|
||||
|
||||
@@ -322,7 +322,7 @@ llvm::Value* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs)
|
||||
cmpop = llvm::FCmpInst::FCMP_UNE;
|
||||
|
||||
// (l.re==r.re && l.im==r.im)
|
||||
llvm::Value* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb());
|
||||
llvm::Value* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb());
|
||||
LLValue* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb());
|
||||
LLValue* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb());
|
||||
return gIR->ir->CreateAnd(b1,b2,"tmp");
|
||||
}
|
||||
|
||||
@@ -4,20 +4,20 @@
|
||||
const llvm::StructType* DtoComplexType(Type* t);
|
||||
const llvm::Type* DtoComplexBaseType(Type* t);
|
||||
|
||||
llvm::Constant* DtoConstComplex(Type* t, llvm::Constant* re, llvm::Constant* im);
|
||||
llvm::Constant* DtoConstComplex(Type* t, long double re, long double im);
|
||||
llvm::Constant* DtoUndefComplex(Type* _ty);
|
||||
LLConstant* DtoConstComplex(Type* t, LLConstant* re, LLConstant* im);
|
||||
LLConstant* DtoConstComplex(Type* t, long double re, long double im);
|
||||
LLConstant* DtoUndefComplex(Type* _ty);
|
||||
|
||||
llvm::Constant* DtoComplexShuffleMask(unsigned a, unsigned b);
|
||||
LLConstant* DtoComplexShuffleMask(unsigned a, unsigned b);
|
||||
|
||||
llvm::Value* DtoRealPart(DValue* val);
|
||||
llvm::Value* DtoImagPart(DValue* val);
|
||||
LLValue* DtoRealPart(DValue* val);
|
||||
LLValue* DtoImagPart(DValue* val);
|
||||
DValue* DtoComplex(Type* to, DValue* val);
|
||||
|
||||
void DtoComplexAssign(llvm::Value* l, llvm::Value* r);
|
||||
void DtoComplexSet(llvm::Value* c, llvm::Value* re, llvm::Value* im);
|
||||
void DtoComplexAssign(LLValue* l, LLValue* r);
|
||||
void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im);
|
||||
|
||||
void DtoGetComplexParts(DValue* c, llvm::Value*& re, llvm::Value*& im);
|
||||
void DtoGetComplexParts(DValue* c, LLValue*& re, LLValue*& im);
|
||||
|
||||
DValue* DtoComplexAdd(Type* type, DValue* lhs, DValue* rhs);
|
||||
DValue* DtoComplexSub(Type* type, DValue* lhs, DValue* rhs);
|
||||
@@ -25,6 +25,6 @@ DValue* DtoComplexMul(Type* type, DValue* lhs, DValue* rhs);
|
||||
DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs);
|
||||
DValue* DtoComplexNeg(Type* type, DValue* val);
|
||||
|
||||
llvm::Value* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs);
|
||||
LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs);
|
||||
|
||||
#endif // LLVMDC_GEN_COMPLEX_H
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DVarValue::DVarValue(VarDeclaration* vd, llvm::Value* llvmValue, bool lvalue)
|
||||
DVarValue::DVarValue(VarDeclaration* vd, LLValue* llvmValue, bool lvalue)
|
||||
{
|
||||
var = vd;
|
||||
val = llvmValue;
|
||||
@@ -19,7 +19,7 @@ DVarValue::DVarValue(VarDeclaration* vd, llvm::Value* llvmValue, bool lvalue)
|
||||
type = var->type;
|
||||
}
|
||||
|
||||
DVarValue::DVarValue(Type* t, llvm::Value* lv, llvm::Value* rv)
|
||||
DVarValue::DVarValue(Type* t, LLValue* lv, LLValue* rv)
|
||||
{
|
||||
var = 0;
|
||||
val = lv;
|
||||
@@ -28,7 +28,7 @@ DVarValue::DVarValue(Type* t, llvm::Value* lv, llvm::Value* rv)
|
||||
type = t;
|
||||
}
|
||||
|
||||
DVarValue::DVarValue(Type* t, llvm::Value* llvmValue, bool lvalue)
|
||||
DVarValue::DVarValue(Type* t, LLValue* llvmValue, bool lvalue)
|
||||
{
|
||||
var = 0;
|
||||
val = llvmValue;
|
||||
@@ -37,13 +37,13 @@ DVarValue::DVarValue(Type* t, llvm::Value* llvmValue, bool lvalue)
|
||||
type = t;
|
||||
}
|
||||
|
||||
llvm::Value* DVarValue::getLVal()
|
||||
LLValue* DVarValue::getLVal()
|
||||
{
|
||||
assert(val && lval);
|
||||
return val;
|
||||
}
|
||||
|
||||
llvm::Value* DVarValue::getRVal()
|
||||
LLValue* DVarValue::getRVal()
|
||||
{
|
||||
assert(rval || val);
|
||||
if (DtoIsPassedByRef(type)) {
|
||||
@@ -63,7 +63,7 @@ llvm::Value* DVarValue::getRVal()
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DFuncValue::DFuncValue(FuncDeclaration* fd, llvm::Value* v, llvm::Value* vt)
|
||||
DFuncValue::DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt)
|
||||
{
|
||||
func = fd;
|
||||
type = func->type;
|
||||
@@ -72,13 +72,13 @@ DFuncValue::DFuncValue(FuncDeclaration* fd, llvm::Value* v, llvm::Value* vt)
|
||||
cc = (unsigned)-1;
|
||||
}
|
||||
|
||||
llvm::Value* DFuncValue::getLVal()
|
||||
LLValue* DFuncValue::getLVal()
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
llvm::Value* DFuncValue::getRVal()
|
||||
LLValue* DFuncValue::getRVal()
|
||||
{
|
||||
assert(val);
|
||||
return val;
|
||||
@@ -87,7 +87,7 @@ llvm::Value* DFuncValue::getRVal()
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* DConstValue::getRVal()
|
||||
LLValue* DConstValue::getRVal()
|
||||
{
|
||||
assert(c);
|
||||
return c;
|
||||
|
||||
70
gen/dvalue.h
70
gen/dvalue.h
@@ -39,8 +39,8 @@ struct DValue : Object
|
||||
{
|
||||
virtual Type* getType() = 0;
|
||||
|
||||
virtual llvm::Value* getLVal() { assert(0); return 0; }
|
||||
virtual llvm::Value* getRVal() { assert(0); return 0; }
|
||||
virtual LLValue* getLVal() { assert(0); return 0; }
|
||||
virtual LLValue* getRVal() { assert(0); return 0; }
|
||||
|
||||
virtual DImValue* isIm() { return NULL; }
|
||||
virtual DConstValue* isConst() { return NULL; }
|
||||
@@ -66,12 +66,12 @@ protected:
|
||||
struct DImValue : DValue
|
||||
{
|
||||
Type* type;
|
||||
llvm::Value* val;
|
||||
LLValue* val;
|
||||
bool inplace;
|
||||
|
||||
DImValue(Type* t, llvm::Value* v, bool in_place = false) { type = t; val = v; inplace = in_place; }
|
||||
DImValue(Type* t, LLValue* v, bool in_place = false) { type = t; val = v; inplace = in_place; }
|
||||
|
||||
virtual llvm::Value* getRVal() { assert(val); return val; }
|
||||
virtual LLValue* getRVal() { assert(val); return val; }
|
||||
|
||||
virtual Type* getType() { assert(type); return type; }
|
||||
virtual DImValue* isIm() { return this; }
|
||||
@@ -83,11 +83,11 @@ struct DImValue : DValue
|
||||
struct DConstValue : DValue
|
||||
{
|
||||
Type* type;
|
||||
llvm::Constant* c;
|
||||
LLConstant* c;
|
||||
|
||||
DConstValue(Type* t, llvm::Constant* con) { type = t; c = con; }
|
||||
DConstValue(Type* t, LLConstant* con) { type = t; c = con; }
|
||||
|
||||
virtual llvm::Value* getRVal();
|
||||
virtual LLValue* getRVal();
|
||||
|
||||
virtual Type* getType() { assert(type); return type; }
|
||||
virtual DConstValue* isConst() { return this; }
|
||||
@@ -96,7 +96,7 @@ struct DConstValue : DValue
|
||||
// null d-value
|
||||
struct DNullValue : DConstValue
|
||||
{
|
||||
DNullValue(Type* t, llvm::Constant* con) : DConstValue(t,con) {}
|
||||
DNullValue(Type* t, LLConstant* con) : DConstValue(t,con) {}
|
||||
virtual DNullValue* isNull() { return this; }
|
||||
};
|
||||
|
||||
@@ -105,16 +105,16 @@ struct DVarValue : DValue
|
||||
{
|
||||
Type* type;
|
||||
VarDeclaration* var;
|
||||
llvm::Value* val;
|
||||
llvm::Value* rval;
|
||||
LLValue* val;
|
||||
LLValue* rval;
|
||||
bool lval;
|
||||
|
||||
DVarValue(VarDeclaration* vd, llvm::Value* llvmValue, bool lvalue);
|
||||
DVarValue(Type* vd, llvm::Value* lv, llvm::Value* rv);
|
||||
DVarValue(Type* t, llvm::Value* llvmValue, bool lvalue);
|
||||
DVarValue(VarDeclaration* vd, LLValue* llvmValue, bool lvalue);
|
||||
DVarValue(Type* vd, LLValue* lv, LLValue* rv);
|
||||
DVarValue(Type* t, LLValue* llvmValue, bool lvalue);
|
||||
|
||||
virtual llvm::Value* getLVal();
|
||||
virtual llvm::Value* getRVal();
|
||||
virtual LLValue* getLVal();
|
||||
virtual LLValue* getRVal();
|
||||
|
||||
virtual Type* getType() { assert(type); return type; }
|
||||
virtual DVarValue* isVar() { return this; }
|
||||
@@ -123,21 +123,21 @@ struct DVarValue : DValue
|
||||
// field d-value
|
||||
struct DFieldValue : DVarValue
|
||||
{
|
||||
DFieldValue(Type* t, llvm::Value* llvmValue, bool l) : DVarValue(t, llvmValue, l) {}
|
||||
DFieldValue(Type* t, LLValue* llvmValue, bool l) : DVarValue(t, llvmValue, l) {}
|
||||
virtual DFieldValue* isField() { return this; }
|
||||
};
|
||||
|
||||
// this d-value
|
||||
struct DThisValue : DVarValue
|
||||
{
|
||||
DThisValue(VarDeclaration* vd, llvm::Value* llvmValue) : DVarValue(vd, llvmValue, true) {}
|
||||
DThisValue(VarDeclaration* vd, LLValue* llvmValue) : DVarValue(vd, llvmValue, true) {}
|
||||
virtual DThisValue* isThis() { return this; }
|
||||
};
|
||||
|
||||
// array length d-value
|
||||
struct DArrayLenValue : DVarValue
|
||||
{
|
||||
DArrayLenValue(Type* t, llvm::Value* llvmValue) : DVarValue(t, llvmValue, true) {}
|
||||
DArrayLenValue(Type* t, LLValue* llvmValue) : DVarValue(t, llvmValue, true) {}
|
||||
virtual DArrayLenValue* isArrayLen() { return this; }
|
||||
};
|
||||
|
||||
@@ -145,10 +145,10 @@ struct DArrayLenValue : DVarValue
|
||||
struct DSliceValue : DValue
|
||||
{
|
||||
Type* type;
|
||||
llvm::Value* len;
|
||||
llvm::Value* ptr;
|
||||
LLValue* len;
|
||||
LLValue* ptr;
|
||||
|
||||
DSliceValue(Type* t, llvm::Value* l, llvm::Value* p) { type=t; ptr=p; len=l; }
|
||||
DSliceValue(Type* t, LLValue* l, LLValue* p) { type=t; ptr=p; len=l; }
|
||||
|
||||
virtual Type* getType() { assert(type); return type; }
|
||||
virtual DSliceValue* isSlice() { return this; }
|
||||
@@ -159,14 +159,14 @@ struct DFuncValue : DValue
|
||||
{
|
||||
Type* type;
|
||||
FuncDeclaration* func;
|
||||
llvm::Value* val;
|
||||
llvm::Value* vthis;
|
||||
LLValue* val;
|
||||
LLValue* vthis;
|
||||
unsigned cc;
|
||||
|
||||
DFuncValue(FuncDeclaration* fd, llvm::Value* v, llvm::Value* vt = 0);
|
||||
DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt = 0);
|
||||
|
||||
virtual llvm::Value* getLVal();
|
||||
virtual llvm::Value* getRVal();
|
||||
virtual LLValue* getLVal();
|
||||
virtual LLValue* getRVal();
|
||||
|
||||
virtual Type* getType() { assert(type); return type; }
|
||||
virtual DFuncValue* isFunc() { return this; }
|
||||
@@ -176,19 +176,19 @@ struct DFuncValue : DValue
|
||||
struct DLRValue : DValue
|
||||
{
|
||||
Type* ltype;
|
||||
llvm::Value* lval;
|
||||
LLValue* lval;
|
||||
Type* rtype;
|
||||
llvm::Value* rval;
|
||||
LLValue* rval;
|
||||
|
||||
DLRValue(Type* lt, llvm::Value* l, Type* rt, llvm::Value* r) {
|
||||
DLRValue(Type* lt, LLValue* l, Type* rt, LLValue* r) {
|
||||
ltype = lt;
|
||||
lval = l;
|
||||
rtype = rt;
|
||||
rval = r;
|
||||
}
|
||||
|
||||
virtual llvm::Value* getLVal() { assert(lval); return lval; }
|
||||
virtual llvm::Value* getRVal() { assert(rval); return rval; }
|
||||
virtual LLValue* getLVal() { assert(lval); return lval; }
|
||||
virtual LLValue* getRVal() { assert(rval); return rval; }
|
||||
|
||||
Type* getLType() { return ltype; }
|
||||
Type* getRType() { return rtype; }
|
||||
@@ -200,10 +200,10 @@ struct DLRValue : DValue
|
||||
struct DComplexValue : DValue
|
||||
{
|
||||
Type* type;
|
||||
llvm::Value* re;
|
||||
llvm::Value* im;
|
||||
LLValue* re;
|
||||
LLValue* im;
|
||||
|
||||
DComplexValue(Type* t, llvm::Value* r, llvm::Value* i) {
|
||||
DComplexValue(Type* t, LLValue* r, LLValue* i) {
|
||||
type = t;
|
||||
re = r;
|
||||
im = i;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "gen/classes.h"
|
||||
#include "gen/dvalue.h"
|
||||
|
||||
const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype, bool ismain)
|
||||
const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bool ismain)
|
||||
{
|
||||
TypeFunction* f = (TypeFunction*)type;
|
||||
assert(f != 0);
|
||||
@@ -38,8 +38,8 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype
|
||||
}
|
||||
|
||||
// return value type
|
||||
const llvm::Type* rettype;
|
||||
const llvm::Type* actualRettype;
|
||||
const LLType* rettype;
|
||||
const LLType* actualRettype;
|
||||
Type* rt = f->next;
|
||||
bool retinptr = false;
|
||||
bool usesthis = false;
|
||||
@@ -63,7 +63,7 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype
|
||||
}
|
||||
|
||||
// parameter types
|
||||
std::vector<const llvm::Type*> paramvec;
|
||||
std::vector<const LLType*> paramvec;
|
||||
|
||||
if (retinptr) {
|
||||
//Logger::cout() << "returning through pointer parameter: " << *rettype << '\n';
|
||||
@@ -80,10 +80,10 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype
|
||||
ti->toObjFile();
|
||||
DtoForceConstInitDsymbol(ti);
|
||||
assert(ti->ir.irStruct->constInit);
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(DtoSize_t());
|
||||
types.push_back(getPtrToType(getPtrToType(ti->ir.irStruct->constInit->getType())));
|
||||
const llvm::Type* t1 = llvm::StructType::get(types);
|
||||
const LLType* t1 = llvm::StructType::get(types);
|
||||
paramvec.push_back(getPtrToType(t1));
|
||||
paramvec.push_back(getPtrToType(llvm::Type::Int8Ty));
|
||||
}
|
||||
@@ -100,7 +100,7 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype
|
||||
Type* argT = DtoDType(arg->type);
|
||||
assert(argT);
|
||||
|
||||
const llvm::Type* at = DtoType(argT);
|
||||
const LLType* at = DtoType(argT);
|
||||
if (isaStruct(at)) {
|
||||
Logger::println("struct param");
|
||||
paramvec.push_back(getPtrToType(at));
|
||||
@@ -156,7 +156,7 @@ static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
|
||||
assert(f != 0);
|
||||
|
||||
const llvm::PointerType* i8pty = getPtrToType(llvm::Type::Int8Ty);
|
||||
std::vector<const llvm::Type*> args;
|
||||
std::vector<const LLType*> args;
|
||||
|
||||
if (fdecl->llvmInternal == LLVMva_start) {
|
||||
args.push_back(i8pty);
|
||||
@@ -187,7 +187,7 @@ const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
|
||||
|
||||
// unittest has null type, just build it manually
|
||||
/*if (fdecl->isUnitTestDeclaration()) {
|
||||
std::vector<const llvm::Type*> args;
|
||||
std::vector<const LLType*> args;
|
||||
return llvm::FunctionType::get(llvm::Type::VoidTy, args, false);
|
||||
}*/
|
||||
|
||||
@@ -196,7 +196,7 @@ const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
|
||||
return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
|
||||
}
|
||||
|
||||
const llvm::Type* thisty = NULL;
|
||||
const LLType* thisty = NULL;
|
||||
if (fdecl->needThis()) {
|
||||
if (AggregateDeclaration* ad = fdecl->isMember2()) {
|
||||
Logger::println("isMember = this is: %s", ad->type->toChars());
|
||||
@@ -225,7 +225,7 @@ static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
|
||||
{
|
||||
TypeFunction* f = (TypeFunction*)DtoDType(fdecl->type);
|
||||
const llvm::FunctionType* fty = DtoVaFunctionType(fdecl);
|
||||
llvm::Constant* fn = 0;
|
||||
LLConstant* fn = 0;
|
||||
|
||||
if (fdecl->llvmInternal == LLVMva_start) {
|
||||
fn = gIR->module->getOrInsertFunction("llvm.va_start", fty);
|
||||
@@ -499,7 +499,7 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
||||
gIR->scopes.push_back(IRScope(beginbb, endbb));
|
||||
|
||||
// create alloca point
|
||||
llvm::Instruction* allocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb());
|
||||
llvm::Instruction* allocaPoint = new llvm::AllocaInst(llvm::Type::Int32Ty, "alloca point", beginbb);
|
||||
gIR->func()->allocapoint = allocaPoint;
|
||||
|
||||
// need result variable? (not nested)
|
||||
@@ -522,13 +522,13 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
||||
if (!vd->needsStorage || vd->nestedref || vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))
|
||||
continue;
|
||||
|
||||
llvm::Value* a = vd->ir.irLocal->value;
|
||||
LLValue* a = vd->ir.irLocal->value;
|
||||
assert(a);
|
||||
std::string s(a->getName());
|
||||
Logger::println("giving argument '%s' storage", s.c_str());
|
||||
s.append("_storage");
|
||||
|
||||
llvm::Value* v = new llvm::AllocaInst(a->getType(),s,allocaPoint);
|
||||
LLValue* v = new llvm::AllocaInst(a->getType(),s,allocaPoint);
|
||||
gIR->ir->CreateStore(a,v);
|
||||
vd->ir.irLocal->value = v;
|
||||
}
|
||||
@@ -537,7 +537,7 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
||||
// debug info
|
||||
if (global.params.symdebug) DtoDwarfFuncStart(fd);
|
||||
|
||||
llvm::Value* parentNested = NULL;
|
||||
LLValue* parentNested = NULL;
|
||||
if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) {
|
||||
if (!fd->isStatic()) // huh?
|
||||
parentNested = fd2->ir.irFunc->nestedVar;
|
||||
@@ -551,7 +551,7 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
||||
|
||||
// construct nested variables struct
|
||||
if (!fd->nestedVars.empty() || parentNested) {
|
||||
std::vector<const llvm::Type*> nestTypes;
|
||||
std::vector<const LLType*> nestTypes;
|
||||
int j = 0;
|
||||
if (parentNested) {
|
||||
nestTypes.push_back(parentNested->getType());
|
||||
@@ -580,7 +580,7 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
||||
fd->ir.irFunc->nestedVar = new llvm::AllocaInst(nestSType,"nestedvars",allocaPoint);
|
||||
if (parentNested) {
|
||||
assert(fd->ir.irFunc->thisVar);
|
||||
llvm::Value* ptr = gIR->ir->CreateBitCast(fd->ir.irFunc->thisVar, parentNested->getType(), "tmp");
|
||||
LLValue* ptr = gIR->ir->CreateBitCast(fd->ir.irFunc->thisVar, parentNested->getType(), "tmp");
|
||||
gIR->ir->CreateStore(ptr, DtoGEPi(fd->ir.irFunc->nestedVar, 0,0, "tmp"));
|
||||
}
|
||||
for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) {
|
||||
@@ -596,7 +596,7 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
||||
// copy _argptr to a memory location
|
||||
if (f->linkage == LINKd && f->varargs == 1)
|
||||
{
|
||||
llvm::Value* argptrmem = new llvm::AllocaInst(fd->ir.irFunc->_argptr->getType(), "_argptrmem", gIR->topallocapoint());
|
||||
LLValue* argptrmem = new llvm::AllocaInst(fd->ir.irFunc->_argptr->getType(), "_argptrmem", gIR->topallocapoint());
|
||||
new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb());
|
||||
fd->ir.irFunc->_argptr = argptrmem;
|
||||
}
|
||||
@@ -665,12 +665,12 @@ void DtoMain()
|
||||
assert(ir.emitMain && ir.mainFunc);
|
||||
|
||||
// parameter types
|
||||
std::vector<const llvm::Type*> pvec;
|
||||
pvec.push_back((const llvm::Type*)llvm::Type::Int32Ty);
|
||||
const llvm::Type* chPtrType = (const llvm::Type*)getPtrToType(llvm::Type::Int8Ty);
|
||||
pvec.push_back((const llvm::Type*)getPtrToType(chPtrType));
|
||||
pvec.push_back((const llvm::Type*)getPtrToType(chPtrType));
|
||||
const llvm::Type* rettype = (const llvm::Type*)llvm::Type::Int32Ty;
|
||||
std::vector<const LLType*> pvec;
|
||||
pvec.push_back((const LLType*)llvm::Type::Int32Ty);
|
||||
const LLType* chPtrType = (const LLType*)getPtrToType(llvm::Type::Int8Ty);
|
||||
pvec.push_back((const LLType*)getPtrToType(chPtrType));
|
||||
pvec.push_back((const LLType*)getPtrToType(chPtrType));
|
||||
const LLType* rettype = (const LLType*)llvm::Type::Int32Ty;
|
||||
|
||||
llvm::FunctionType* functype = llvm::FunctionType::get(rettype, pvec, false);
|
||||
llvm::Function* func = llvm::Function::Create(functype,llvm::GlobalValue::ExternalLinkage,"main",ir.module);
|
||||
@@ -694,18 +694,18 @@ void DtoMain()
|
||||
{
|
||||
// main with arguments
|
||||
assert(mainty->getNumParams() == 1);
|
||||
std::vector<llvm::Value*> args;
|
||||
std::vector<LLValue*> args;
|
||||
llvm::Function* mfn = LLVM_D_GetRuntimeFunction(ir.module,"_d_main_args");
|
||||
|
||||
llvm::Function::arg_iterator argi = func->arg_begin();
|
||||
args.push_back(argi++);
|
||||
args.push_back(argi++);
|
||||
|
||||
const llvm::Type* at = mainty->getParamType(0)->getContainedType(0);
|
||||
llvm::Value* arr = new llvm::AllocaInst(at->getContainedType(1)->getContainedType(0), func->arg_begin(), "argstorage", apt);
|
||||
llvm::Value* a = new llvm::AllocaInst(at, "argarray", apt);
|
||||
llvm::Value* ptr = DtoGEPi(a,0,0,"tmp",bb);
|
||||
llvm::Value* v = args[0];
|
||||
const LLType* at = mainty->getParamType(0)->getContainedType(0);
|
||||
LLValue* arr = new llvm::AllocaInst(at->getContainedType(1)->getContainedType(0), func->arg_begin(), "argstorage", apt);
|
||||
LLValue* a = new llvm::AllocaInst(at, "argarray", apt);
|
||||
LLValue* ptr = DtoGEPi(a,0,0,"tmp",bb);
|
||||
LLValue* v = args[0];
|
||||
if (v->getType() != DtoSize_t())
|
||||
v = new llvm::ZExtInst(v, DtoSize_t(), "tmp", bb);
|
||||
new llvm::StoreInst(v,ptr,bb);
|
||||
@@ -778,7 +778,7 @@ DValue* DtoArgument(Argument* fnarg, Expression* argexp)
|
||||
// aggregate arg
|
||||
else if (DtoIsPassedByRef(argexp->type))
|
||||
{
|
||||
llvm::Value* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint());
|
||||
LLValue* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint());
|
||||
DVarValue* vv = new DVarValue(argexp->type, alloc, true);
|
||||
DtoAssign(vv, arg);
|
||||
arg = vv;
|
||||
@@ -794,7 +794,7 @@ DValue* DtoArgument(Argument* fnarg, Expression* argexp)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoVariadicArgument(Expression* argexp, llvm::Value* dst)
|
||||
void DtoVariadicArgument(Expression* argexp, LLValue* dst)
|
||||
{
|
||||
Logger::println("DtoVariadicArgument");
|
||||
LOG_SCOPE;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef LLVMDC_GEN_FUNCTIONS_H
|
||||
#define LLVMDC_GEN_FUNCTIONS_H
|
||||
|
||||
const llvm::FunctionType* DtoFunctionType(Type* t, const llvm::Type* thistype, bool ismain = false);
|
||||
const llvm::FunctionType* DtoFunctionType(Type* t, const LLType* thistype, bool ismain = false);
|
||||
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl);
|
||||
|
||||
const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl);
|
||||
@@ -11,7 +11,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl);
|
||||
void DtoDefineFunc(FuncDeclaration* fd);
|
||||
|
||||
DValue* DtoArgument(Argument* fnarg, Expression* argexp);
|
||||
void DtoVariadicArgument(Expression* argexp, llvm::Value* dst);
|
||||
void DtoVariadicArgument(Expression* argexp, LLValue* dst);
|
||||
|
||||
void DtoMain();
|
||||
|
||||
|
||||
@@ -53,11 +53,6 @@ IRState::IRState()
|
||||
emitMain = false;
|
||||
mainFunc = 0;
|
||||
ir.state = this;
|
||||
llvm_DeclareMemSet32 = NULL;
|
||||
llvm_DeclareMemSet64 = NULL;
|
||||
llvm_DeclareMemCpy32 = NULL;
|
||||
llvm_DeclareMemCpy64 = NULL;
|
||||
llvm_DeclareMemBarrier = NULL;
|
||||
}
|
||||
|
||||
IrFunction* IRState::func()
|
||||
|
||||
@@ -140,13 +140,6 @@ struct IRState
|
||||
FuncDeclVector ctors;
|
||||
FuncDeclVector dtors;
|
||||
FuncDeclVector unitTests;
|
||||
|
||||
// intrinsics
|
||||
llvm::Function* llvm_DeclareMemSet32;
|
||||
llvm::Function* llvm_DeclareMemSet64;
|
||||
llvm::Function* llvm_DeclareMemCpy32;
|
||||
llvm::Function* llvm_DeclareMemCpy64;
|
||||
llvm::Function* llvm_DeclareMemBarrier;
|
||||
};
|
||||
|
||||
#endif // LLVMDC_GEN_IRSTATE_H
|
||||
|
||||
@@ -16,4 +16,13 @@
|
||||
#include "llvm/Support/IRBuilder.h"
|
||||
using llvm::IRBuilder;
|
||||
|
||||
#define GET_INTRINSIC_DECL(_X) (llvm::Intrinsic::getDeclaration(gIR->module, llvm::Intrinsic:: _X ))
|
||||
|
||||
// shortcuts for the _very_ common llvm types
|
||||
typedef llvm::Type LLType;
|
||||
typedef llvm::Value LLValue;
|
||||
typedef llvm::Constant LLConstant;
|
||||
|
||||
#define LLSmallVector llvm::SmallVector
|
||||
|
||||
#endif // GEN_LLVM_H
|
||||
|
||||
146
gen/runtime.cpp
146
gen/runtime.cpp
@@ -132,49 +132,49 @@ llvm::GlobalVariable* LLVM_D_GetRuntimeGlobal(llvm::Module* target, const char*
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const llvm::Type* rt_ptr(const llvm::Type* t)
|
||||
static const LLType* rt_ptr(const LLType* t)
|
||||
{
|
||||
return getPtrToType(t);
|
||||
}
|
||||
|
||||
static const llvm::Type* rt_array(const llvm::Type* elemty)
|
||||
static const LLType* rt_array(const LLType* elemty)
|
||||
{
|
||||
std::vector<const llvm::Type*> t;
|
||||
std::vector<const LLType*> t;
|
||||
t.push_back(DtoSize_t());
|
||||
t.push_back(rt_ptr(elemty));
|
||||
return rt_ptr(llvm::StructType::get(t));
|
||||
}
|
||||
|
||||
static const llvm::Type* rt_array2(const llvm::Type* elemty)
|
||||
static const LLType* rt_array2(const LLType* elemty)
|
||||
{
|
||||
std::vector<const llvm::Type*> t;
|
||||
std::vector<const LLType*> t;
|
||||
t.push_back(DtoSize_t());
|
||||
t.push_back(rt_ptr(elemty));
|
||||
return llvm::StructType::get(t);
|
||||
}
|
||||
|
||||
static const llvm::Type* rt_dg1()
|
||||
static const LLType* rt_dg1()
|
||||
{
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_ptr(llvm::Type::Int8Ty));
|
||||
types.push_back(rt_ptr(llvm::Type::Int8Ty));
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::Int32Ty, types, false);
|
||||
|
||||
std::vector<const llvm::Type*> t;
|
||||
std::vector<const LLType*> t;
|
||||
t.push_back(rt_ptr(llvm::Type::Int8Ty));
|
||||
t.push_back(rt_ptr(fty));
|
||||
return rt_ptr(llvm::StructType::get(t));
|
||||
}
|
||||
|
||||
static const llvm::Type* rt_dg2()
|
||||
static const LLType* rt_dg2()
|
||||
{
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_ptr(llvm::Type::Int8Ty));
|
||||
types.push_back(rt_ptr(llvm::Type::Int8Ty));
|
||||
types.push_back(rt_ptr(llvm::Type::Int8Ty));
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::Int32Ty, types, false);
|
||||
|
||||
std::vector<const llvm::Type*> t;
|
||||
std::vector<const LLType*> t;
|
||||
t.push_back(rt_ptr(llvm::Type::Int8Ty));
|
||||
t.push_back(rt_ptr(fty));
|
||||
return rt_ptr(llvm::StructType::get(t));
|
||||
@@ -184,23 +184,23 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{
|
||||
M = new llvm::Module("llvmdc internal runtime");
|
||||
|
||||
const llvm::Type* voidTy = llvm::Type::VoidTy;
|
||||
const llvm::Type* boolTy = llvm::Type::Int1Ty;
|
||||
const llvm::Type* byteTy = llvm::Type::Int8Ty;
|
||||
const llvm::Type* shortTy = llvm::Type::Int16Ty;
|
||||
const llvm::Type* intTy = llvm::Type::Int32Ty;
|
||||
const llvm::Type* longTy = llvm::Type::Int64Ty;
|
||||
const llvm::Type* floatTy = llvm::Type::FloatTy;
|
||||
const llvm::Type* doubleTy = llvm::Type::DoubleTy;
|
||||
const llvm::Type* sizeTy = DtoSize_t();
|
||||
const llvm::Type* voidPtrTy = rt_ptr(byteTy);
|
||||
const llvm::Type* stringTy = rt_array(byteTy);
|
||||
const llvm::Type* wstringTy = rt_array(shortTy);
|
||||
const llvm::Type* dstringTy = rt_array(intTy);
|
||||
const llvm::Type* objectTy = rt_ptr(ClassDeclaration::object->type->ir.type->get());
|
||||
const llvm::Type* classInfoTy = rt_ptr(ClassDeclaration::classinfo->type->ir.type->get());
|
||||
const llvm::Type* typeInfoTy = rt_ptr(Type::typeinfo->type->ir.type->get());
|
||||
const llvm::Type* aaTy = rt_ptr(llvm::OpaqueType::get());
|
||||
const LLType* voidTy = llvm::Type::VoidTy;
|
||||
const LLType* boolTy = llvm::Type::Int1Ty;
|
||||
const LLType* byteTy = llvm::Type::Int8Ty;
|
||||
const LLType* shortTy = llvm::Type::Int16Ty;
|
||||
const LLType* intTy = llvm::Type::Int32Ty;
|
||||
const LLType* longTy = llvm::Type::Int64Ty;
|
||||
const LLType* floatTy = llvm::Type::FloatTy;
|
||||
const LLType* doubleTy = llvm::Type::DoubleTy;
|
||||
const LLType* sizeTy = DtoSize_t();
|
||||
const LLType* voidPtrTy = rt_ptr(byteTy);
|
||||
const LLType* stringTy = rt_array(byteTy);
|
||||
const LLType* wstringTy = rt_array(shortTy);
|
||||
const LLType* dstringTy = rt_array(intTy);
|
||||
const LLType* objectTy = rt_ptr(ClassDeclaration::object->type->ir.type->get());
|
||||
const LLType* classInfoTy = rt_ptr(ClassDeclaration::classinfo->type->ir.type->get());
|
||||
const LLType* typeInfoTy = rt_ptr(Type::typeinfo->type->ir.type->get());
|
||||
const LLType* aaTy = rt_ptr(llvm::OpaqueType::get());
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -213,7 +213,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
std::string fname("_d_assert");
|
||||
std::string fname2("_d_array_bounds");
|
||||
std::string fname3("_d_switch_error");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(stringTy);
|
||||
types.push_back(intTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
|
||||
@@ -225,7 +225,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void _d_assert_msg( char[] msg, char[] file, uint line )
|
||||
{
|
||||
std::string fname("_d_assert_msg");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(stringTy);
|
||||
types.push_back(stringTy);
|
||||
types.push_back(intTy);
|
||||
@@ -240,7 +240,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void* _d_allocmemoryT(TypeInfo ti)
|
||||
{
|
||||
std::string fname("_d_allocmemoryT");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(typeInfoTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
@@ -251,7 +251,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{
|
||||
std::string fname("_d_newarrayT");
|
||||
std::string fname2("_d_newarrayiT");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(typeInfoTy);
|
||||
types.push_back(sizeTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false);
|
||||
@@ -264,7 +264,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{
|
||||
std::string fname("_d_arraysetlengthT");
|
||||
std::string fname2("_d_arraysetlengthiT");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(typeInfoTy);
|
||||
types.push_back(sizeTy);
|
||||
types.push_back(sizeTy);
|
||||
@@ -277,7 +277,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Object _d_newclass(ClassInfo ci)
|
||||
{
|
||||
std::string fname("_d_newclass");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(classInfoTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
@@ -286,7 +286,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void _d_delarray(size_t plength, void* pdata)
|
||||
{
|
||||
std::string fname("_d_delarray");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(sizeTy);
|
||||
types.push_back(voidPtrTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
|
||||
@@ -300,7 +300,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
std::string fname("_d_delmemory");
|
||||
std::string fname2("_d_delinterface");
|
||||
std::string fname3("_d_callfinalizer");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(voidPtrTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
@@ -311,7 +311,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void _d_delclass(Object p)
|
||||
{
|
||||
std::string fname("_d_delclass");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(objectTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
@@ -325,7 +325,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{ \
|
||||
std::string fname("_d_array_init_"); \
|
||||
fname.append(suffix); \
|
||||
std::vector<const llvm::Type*> types; \
|
||||
std::vector<const LLType*> types; \
|
||||
types.push_back(rt_ptr(TY)); \
|
||||
types.push_back(sizeTy); \
|
||||
types.push_back(TY); \
|
||||
@@ -348,7 +348,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void _d_array_init_mem(void* a, size_t na, void* v, size_t nv)
|
||||
{
|
||||
std::string fname("_d_array_init_mem");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(voidPtrTy);
|
||||
types.push_back(sizeTy);
|
||||
types.push_back(voidPtrTy);
|
||||
@@ -365,7 +365,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{ \
|
||||
std::string fname(a); \
|
||||
std::string fname2(b); \
|
||||
std::vector<const llvm::Type*> types; \
|
||||
std::vector<const LLType*> types; \
|
||||
types.push_back(TY); \
|
||||
types.push_back(rt_dg1()); \
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \
|
||||
@@ -381,7 +381,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{ \
|
||||
std::string fname(a); \
|
||||
std::string fname2(b); \
|
||||
std::vector<const llvm::Type*> types; \
|
||||
std::vector<const LLType*> types; \
|
||||
types.push_back(TY); \
|
||||
types.push_back(rt_dg2()); \
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \
|
||||
@@ -397,7 +397,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{ \
|
||||
std::string fname(a); \
|
||||
std::string fname2(b); \
|
||||
std::vector<const llvm::Type*> types; \
|
||||
std::vector<const LLType*> types; \
|
||||
types.push_back(TY); \
|
||||
types.push_back(rt_dg1()); \
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \
|
||||
@@ -413,7 +413,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{ \
|
||||
std::string fname(a); \
|
||||
std::string fname2(b); \
|
||||
std::vector<const llvm::Type*> types; \
|
||||
std::vector<const LLType*> types; \
|
||||
types.push_back(TY); \
|
||||
types.push_back(rt_dg2()); \
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \
|
||||
@@ -433,7 +433,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// size_t _d_array_cast_len(size_t len, size_t elemsz, size_t newelemsz)
|
||||
{
|
||||
std::string fname("_d_array_cast_len");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(sizeTy);
|
||||
types.push_back(sizeTy);
|
||||
types.push_back(sizeTy);
|
||||
@@ -449,7 +449,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void _d_main_args(uint n, char** args, ref char[][] res)
|
||||
{
|
||||
std::string fname("_d_main_args");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(intTy);
|
||||
types.push_back(rt_ptr(rt_ptr(byteTy)));
|
||||
types.push_back(rt_array(stringTy->getContainedType(0)));
|
||||
@@ -465,7 +465,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Object _d_toObject(void* p)
|
||||
{
|
||||
std::string fname("_d_toObject");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(voidPtrTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
@@ -475,7 +475,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Object _d_interface_cast(void* p, ClassInfo c)
|
||||
{
|
||||
std::string fname("_d_interface_cast");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(voidPtrTy);
|
||||
types.push_back(classInfoTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false);
|
||||
@@ -486,7 +486,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Object _d_dynamic_cast(Object o, ClassInfo c)
|
||||
{
|
||||
std::string fname("_d_dynamic_cast");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(objectTy);
|
||||
types.push_back(classInfoTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false);
|
||||
@@ -502,7 +502,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{
|
||||
std::string fname("_adReverseChar");
|
||||
std::string fname2("_adSortChar");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(stringTy);
|
||||
types.push_back(stringTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
|
||||
@@ -515,7 +515,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{
|
||||
std::string fname("_adReverseWchar");
|
||||
std::string fname2("_adSortWchar");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(wstringTy);
|
||||
types.push_back(wstringTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
|
||||
@@ -526,7 +526,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Array _adReverse(Array a, size_t szelem)
|
||||
{
|
||||
std::string fname("_adReverse");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(sizeTy);
|
||||
@@ -537,7 +537,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Array _adDupT(TypeInfo ti, Array a)
|
||||
{
|
||||
std::string fname("_adDupT");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(typeInfoTy);
|
||||
types.push_back(rt_array(byteTy));
|
||||
@@ -550,7 +550,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{
|
||||
std::string fname("_adEq");
|
||||
std::string fname2("_adCmp");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(typeInfoTy);
|
||||
@@ -562,7 +562,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// int _adCmpChar(Array a1, Array a2)
|
||||
{
|
||||
std::string fname("_adCmpChar");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(rt_array(byteTy));
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false);
|
||||
@@ -572,7 +572,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Array _adSort(Array a, TypeInfo ti)
|
||||
{
|
||||
std::string fname("_adSort");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(typeInfoTy);
|
||||
@@ -587,7 +587,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// size_t _aaLen(AA aa)
|
||||
{
|
||||
std::string fname("_aaLen");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(aaTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(sizeTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
@@ -596,7 +596,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void* _aaGet(AA* aa, TypeInfo keyti, size_t valuesize, void* pkey)
|
||||
{
|
||||
std::string fname("_aaGet");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(aaTy);
|
||||
types.push_back(typeInfoTy);
|
||||
types.push_back(sizeTy);
|
||||
@@ -608,7 +608,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void* _aaGetRvalue(AA aa, TypeInfo keyti, size_t valuesize, void* pkey)
|
||||
{
|
||||
std::string fname("_aaGetRvalue");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(aaTy);
|
||||
types.push_back(typeInfoTy);
|
||||
types.push_back(sizeTy);
|
||||
@@ -620,7 +620,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void* _aaIn(AA aa, TypeInfo keyti, void* pkey)
|
||||
{
|
||||
std::string fname("_aaIn");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(aaTy);
|
||||
types.push_back(typeInfoTy);
|
||||
types.push_back(voidPtrTy);
|
||||
@@ -631,7 +631,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void _aaDel(AA aa, TypeInfo keyti, void* pkey)
|
||||
{
|
||||
std::string fname("_aaDel");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(aaTy);
|
||||
types.push_back(typeInfoTy);
|
||||
types.push_back(voidPtrTy);
|
||||
@@ -642,7 +642,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// ArrayRet_t _aaValues(AA aa, size_t keysize, size_t valuesize)
|
||||
{
|
||||
std::string fname("_aaValues");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(aaTy);
|
||||
types.push_back(sizeTy);
|
||||
@@ -654,7 +654,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void* _aaRehash(AA* paa, TypeInfo keyti)
|
||||
{
|
||||
std::string fname("_aaRehash");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(aaTy);
|
||||
types.push_back(typeInfoTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false);
|
||||
@@ -664,7 +664,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// ArrayRet_t _aaKeys(AA aa, size_t keysize)
|
||||
{
|
||||
std::string fname("_aaKeys");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(byteTy));
|
||||
types.push_back(aaTy);
|
||||
types.push_back(sizeTy);
|
||||
@@ -675,7 +675,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// int _aaApply(AA aa, size_t keysize, dg_t dg)
|
||||
{
|
||||
std::string fname("_aaApply");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(aaTy);
|
||||
types.push_back(sizeTy);
|
||||
types.push_back(rt_dg1());
|
||||
@@ -686,7 +686,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// int _aaApply2(AA aa, size_t keysize, dg2_t dg)
|
||||
{
|
||||
std::string fname("_aaApply2");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(aaTy);
|
||||
types.push_back(sizeTy);
|
||||
types.push_back(rt_dg1());
|
||||
@@ -703,7 +703,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
{
|
||||
std::string fname("_moduleCtor");
|
||||
std::string fname2("_moduleDtor");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M);
|
||||
@@ -716,7 +716,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Object _d_toObject(void* p)
|
||||
{
|
||||
std::string fname("_d_toObject");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(voidPtrTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
@@ -725,7 +725,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Object _d_dynamic_cast(Object o, ClassInfo c)
|
||||
{
|
||||
std::string fname("_d_dynamic_cast");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(objectTy);
|
||||
types.push_back(classInfoTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false);
|
||||
@@ -735,7 +735,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// Object _d_interface_cast(void* p, ClassInfo c)
|
||||
{
|
||||
std::string fname("_d_interface_cast");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(voidPtrTy);
|
||||
types.push_back(classInfoTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false);
|
||||
@@ -749,7 +749,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// void _d_throw_exception(Object e)
|
||||
{
|
||||
std::string fname("_d_throw_exception");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(objectTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
@@ -762,7 +762,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// int _d_switch_string(char[][] table, char[] ca)
|
||||
{
|
||||
std::string fname("_d_switch_string");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(rt_array2(byteTy)));
|
||||
types.push_back(stringTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false);
|
||||
@@ -772,7 +772,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// int _d_switch_ustring(wchar[][] table, wchar[] ca)
|
||||
{
|
||||
std::string fname("_d_switch_ustring");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(rt_array2(shortTy)));
|
||||
types.push_back(wstringTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false);
|
||||
@@ -782,7 +782,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
// int _d_switch_dstring(dchar[][] table, dchar[] ca)
|
||||
{
|
||||
std::string fname("_d_switch_dstring");
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(rt_array(rt_array2(intTy)));
|
||||
types.push_back(dstringTy);
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false);
|
||||
|
||||
@@ -104,7 +104,7 @@ void ReturnStatement::toIR(IRState* p)
|
||||
else {
|
||||
if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum);
|
||||
DValue* e = exp->toElem(p);
|
||||
llvm::Value* v = e->getRVal();
|
||||
LLValue* v = e->getRVal();
|
||||
delete e;
|
||||
Logger::cout() << "return value is '" <<*v << "'\n";
|
||||
|
||||
@@ -177,13 +177,13 @@ void IfStatement::toIR(IRState* p)
|
||||
|
||||
if (match)
|
||||
{
|
||||
llvm::Value* allocainst = new llvm::AllocaInst(DtoType(match->type), "._tmp_if_var", p->topallocapoint());
|
||||
LLValue* allocainst = new llvm::AllocaInst(DtoType(match->type), "._tmp_if_var", p->topallocapoint());
|
||||
match->ir.irLocal = new IrLocal(match);
|
||||
match->ir.irLocal->value = allocainst;
|
||||
}
|
||||
|
||||
DValue* cond_e = condition->toElem(p);
|
||||
llvm::Value* cond_val = cond_e->getRVal();
|
||||
LLValue* cond_val = cond_e->getRVal();
|
||||
delete cond_e;
|
||||
|
||||
llvm::BasicBlock* oldend = gIR->scopeend();
|
||||
@@ -196,7 +196,7 @@ void IfStatement::toIR(IRState* p)
|
||||
Logger::cout() << "if conditional: " << *cond_val << '\n';
|
||||
cond_val = DtoBoolean(cond_val);
|
||||
}
|
||||
llvm::Value* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb());
|
||||
LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb());
|
||||
|
||||
// replace current scope
|
||||
gIR->scope() = IRScope(ifbb,elsebb);
|
||||
@@ -274,11 +274,11 @@ void WhileStatement::toIR(IRState* p)
|
||||
|
||||
// create the condition
|
||||
DValue* cond_e = condition->toElem(p);
|
||||
llvm::Value* cond_val = DtoBoolean(cond_e->getRVal());
|
||||
LLValue* cond_val = DtoBoolean(cond_e->getRVal());
|
||||
delete cond_e;
|
||||
|
||||
// conditional branch
|
||||
llvm::Value* ifbreak = llvm::BranchInst::Create(whilebodybb, endbb, cond_val, p->scopebb());
|
||||
LLValue* ifbreak = llvm::BranchInst::Create(whilebodybb, endbb, cond_val, p->scopebb());
|
||||
|
||||
// rewrite scope
|
||||
gIR->scope() = IRScope(whilebodybb,endbb);
|
||||
@@ -322,11 +322,11 @@ void DoStatement::toIR(IRState* p)
|
||||
|
||||
// create the condition
|
||||
DValue* cond_e = condition->toElem(p);
|
||||
llvm::Value* cond_val = DtoBoolean(cond_e->getRVal());
|
||||
LLValue* cond_val = DtoBoolean(cond_e->getRVal());
|
||||
delete cond_e;
|
||||
|
||||
// conditional branch
|
||||
llvm::Value* ifbreak = llvm::BranchInst::Create(dowhilebb, endbb, cond_val, gIR->scopebb());
|
||||
LLValue* ifbreak = llvm::BranchInst::Create(dowhilebb, endbb, cond_val, gIR->scopebb());
|
||||
|
||||
// rewrite the scope
|
||||
gIR->scope() = IRScope(endbb,oldend);
|
||||
@@ -361,7 +361,7 @@ void ForStatement::toIR(IRState* p)
|
||||
|
||||
// create the condition
|
||||
DValue* cond_e = condition->toElem(p);
|
||||
llvm::Value* cond_val = DtoBoolean(cond_e->getRVal());
|
||||
LLValue* cond_val = DtoBoolean(cond_e->getRVal());
|
||||
delete cond_e;
|
||||
|
||||
// conditional branch
|
||||
@@ -571,7 +571,7 @@ void ThrowStatement::toIR(IRState* p)
|
||||
DValue* e = exp->toElem(p);
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_throw_exception");
|
||||
//Logger::cout() << "calling: " << *fn << '\n';
|
||||
llvm::Value* arg = DtoBitCast(e->getRVal(), fn->getFunctionType()->getParamType(0));
|
||||
LLValue* arg = DtoBitCast(e->getRVal(), fn->getFunctionType()->getParamType(0));
|
||||
//Logger::cout() << "arg: " << *arg << '\n';
|
||||
gIR->ir->CreateCall(fn, arg, "");
|
||||
gIR->ir->CreateUnreachable();
|
||||
@@ -596,7 +596,7 @@ struct Case : Object
|
||||
}
|
||||
};
|
||||
|
||||
static llvm::Value* call_string_switch_runtime(llvm::GlobalVariable* table, Expression* e)
|
||||
static LLValue* call_string_switch_runtime(llvm::GlobalVariable* table, Expression* e)
|
||||
{
|
||||
Type* dt = DtoDType(e->type);
|
||||
Type* dtnext = DtoDType(dt->next);
|
||||
@@ -616,14 +616,14 @@ static llvm::Value* call_string_switch_runtime(llvm::GlobalVariable* table, Expr
|
||||
}
|
||||
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
|
||||
std::vector<llvm::Value*> args;
|
||||
std::vector<LLValue*> args;
|
||||
Logger::cout() << *table->getType() << '\n';
|
||||
Logger::cout() << *fn->getFunctionType()->getParamType(0) << '\n';
|
||||
assert(table->getType() == fn->getFunctionType()->getParamType(0));
|
||||
args.push_back(table);
|
||||
|
||||
DValue* val = e->toElem(gIR);
|
||||
llvm::Value* llval;
|
||||
LLValue* llval;
|
||||
if (DSliceValue* sval = val->isSlice())
|
||||
{
|
||||
// give storage
|
||||
@@ -667,7 +667,7 @@ void SwitchStatement::toIR(IRState* p)
|
||||
do {
|
||||
// integral case
|
||||
if (cs->exp->type->isintegral()) {
|
||||
llvm::Constant* c = cs->exp->toConstElem(p);
|
||||
LLConstant* c = cs->exp->toConstElem(p);
|
||||
tmp.push_back(isaConstantInt(c));
|
||||
}
|
||||
// string case
|
||||
@@ -694,7 +694,7 @@ void SwitchStatement::toIR(IRState* p)
|
||||
// first sort it
|
||||
caseArray.sort();
|
||||
// iterate and add indices to cases
|
||||
std::vector<llvm::Constant*> inits;
|
||||
std::vector<LLConstant*> inits;
|
||||
for (size_t i=0; i<caseArray.dim; ++i)
|
||||
{
|
||||
Case* c = (Case*)caseArray.data[i];
|
||||
@@ -702,23 +702,23 @@ void SwitchStatement::toIR(IRState* p)
|
||||
inits.push_back(c->str->toConstElem(p));
|
||||
}
|
||||
// build static array for ptr or final array
|
||||
const llvm::Type* elemTy = DtoType(condition->type);
|
||||
const LLType* elemTy = DtoType(condition->type);
|
||||
const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size());
|
||||
llvm::Constant* arrInit = llvm::ConstantArray::get(arrTy, inits);
|
||||
LLConstant* arrInit = llvm::ConstantArray::get(arrTy, inits);
|
||||
llvm::GlobalVariable* arr = new llvm::GlobalVariable(arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, "string_switch_table_data", gIR->module);
|
||||
|
||||
const llvm::Type* elemPtrTy = getPtrToType(elemTy);
|
||||
llvm::Constant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy);
|
||||
const LLType* elemPtrTy = getPtrToType(elemTy);
|
||||
LLConstant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy);
|
||||
|
||||
// build the static table
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
types.push_back(DtoSize_t());
|
||||
types.push_back(elemPtrTy);
|
||||
const llvm::StructType* sTy = llvm::StructType::get(types);
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
sinits.push_back(DtoConstSize_t(inits.size()));
|
||||
sinits.push_back(arrPtr);
|
||||
llvm::Constant* sInit = llvm::ConstantStruct::get(sTy, sinits);
|
||||
LLConstant* sInit = llvm::ConstantStruct::get(sTy, sinits);
|
||||
|
||||
switchTable = new llvm::GlobalVariable(sTy, true, llvm::GlobalValue::InternalLinkage, sInit, "string_switch_table", gIR->module);
|
||||
}
|
||||
@@ -734,7 +734,7 @@ void SwitchStatement::toIR(IRState* p)
|
||||
llvm::BasicBlock* endbb = llvm::BasicBlock::Create("switchend", p->topfunc(), oldend);
|
||||
|
||||
// condition var
|
||||
llvm::Value* condVal;
|
||||
LLValue* condVal;
|
||||
// integral switch
|
||||
if (condition->type->isintegral()) {
|
||||
DValue* cond = condition->toElem(p);
|
||||
@@ -845,8 +845,8 @@ void ForeachStatement::toIR(IRState* p)
|
||||
Logger::println("aggr = %s", aggr->toChars());
|
||||
|
||||
// key
|
||||
const llvm::Type* keytype = key ? DtoType(key->type) : DtoSize_t();
|
||||
llvm::Value* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint());
|
||||
const LLType* keytype = key ? DtoType(key->type) : DtoSize_t();
|
||||
LLValue* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint());
|
||||
if (key)
|
||||
{
|
||||
//key->llvmValue = keyvar;
|
||||
@@ -854,12 +854,12 @@ void ForeachStatement::toIR(IRState* p)
|
||||
key->ir.irLocal = new IrLocal(key);
|
||||
key->ir.irLocal->value = keyvar;
|
||||
}
|
||||
llvm::Value* zerokey = llvm::ConstantInt::get(keytype,0,false);
|
||||
LLValue* zerokey = llvm::ConstantInt::get(keytype,0,false);
|
||||
|
||||
// value
|
||||
Logger::println("value = %s", value->toPrettyChars());
|
||||
const llvm::Type* valtype = DtoType(value->type);
|
||||
llvm::Value* valvar = NULL;
|
||||
const LLType* valtype = DtoType(value->type);
|
||||
LLValue* valvar = NULL;
|
||||
if (!value->isRef() && !value->isOut())
|
||||
valvar = new llvm::AllocaInst(valtype, "foreachval", p->topallocapoint());
|
||||
if (!value->ir.irLocal)
|
||||
@@ -870,8 +870,8 @@ void ForeachStatement::toIR(IRState* p)
|
||||
Type* aggrtype = DtoDType(aggr->type);
|
||||
|
||||
// get length and pointer
|
||||
llvm::Value* val = 0;
|
||||
llvm::Value* niters = 0;
|
||||
LLValue* val = 0;
|
||||
LLValue* niters = 0;
|
||||
|
||||
// static array
|
||||
if (aggrtype->ty == Tsarray)
|
||||
@@ -922,7 +922,7 @@ void ForeachStatement::toIR(IRState* p)
|
||||
niters = gIR->ir->CreateBitCast(niters, keytype, "foreachtrunckey");
|
||||
}
|
||||
|
||||
llvm::Constant* delta = 0;
|
||||
LLConstant* delta = 0;
|
||||
if (op == TOKforeach) {
|
||||
new llvm::StoreInst(zerokey, keyvar, p->scopebb());
|
||||
}
|
||||
@@ -941,8 +941,8 @@ void ForeachStatement::toIR(IRState* p)
|
||||
// condition
|
||||
p->scope() = IRScope(condbb,bodybb);
|
||||
|
||||
llvm::Value* done = 0;
|
||||
llvm::Value* load = new llvm::LoadInst(keyvar, "tmp", p->scopebb());
|
||||
LLValue* done = 0;
|
||||
LLValue* load = new llvm::LoadInst(keyvar, "tmp", p->scopebb());
|
||||
if (op == TOKforeach) {
|
||||
done = new llvm::ICmpInst(llvm::ICmpInst::ICMP_ULT, load, niters, "tmp", p->scopebb());
|
||||
}
|
||||
@@ -957,8 +957,8 @@ void ForeachStatement::toIR(IRState* p)
|
||||
p->scope() = IRScope(bodybb,nextbb);
|
||||
|
||||
// get value for this iteration
|
||||
llvm::Constant* zero = llvm::ConstantInt::get(keytype,0,false);
|
||||
llvm::Value* loadedKey = p->ir->CreateLoad(keyvar,"tmp");
|
||||
LLConstant* zero = llvm::ConstantInt::get(keytype,0,false);
|
||||
LLValue* loadedKey = p->ir->CreateLoad(keyvar,"tmp");
|
||||
if (aggrtype->ty == Tsarray)
|
||||
value->ir.irLocal->value = DtoGEP(val,zero,loadedKey,"tmp");
|
||||
else if (aggrtype->ty == Tarray)
|
||||
@@ -982,7 +982,7 @@ void ForeachStatement::toIR(IRState* p)
|
||||
// next
|
||||
p->scope() = IRScope(nextbb,endbb);
|
||||
if (op == TOKforeach) {
|
||||
llvm::Value* load = DtoLoad(keyvar);
|
||||
LLValue* load = DtoLoad(keyvar);
|
||||
load = p->ir->CreateAdd(load, llvm::ConstantInt::get(keytype, 1, false), "tmp");
|
||||
DtoStore(load, keyvar);
|
||||
}
|
||||
@@ -1141,7 +1141,7 @@ void AsmStatement::toIR(IRState* p)
|
||||
Logger::println("asm expr = '%s'", asmstr.c_str());
|
||||
|
||||
// create function type
|
||||
std::vector<const llvm::Type*> args;
|
||||
std::vector<const LLType*> args;
|
||||
const llvm::FunctionType* fty = llvm::FunctionType::get(DtoSize_t(), args, false);
|
||||
|
||||
// create inline asm callee
|
||||
|
||||
@@ -17,54 +17,55 @@
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::Type* DtoStructType(Type* t)
|
||||
const LLType* DtoStructType(Type* t)
|
||||
{
|
||||
assert(0);
|
||||
std::vector<const llvm::Type*> types;
|
||||
std::vector<const LLType*> types;
|
||||
return llvm::StructType::get(types);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* DtoStructZeroInit(llvm::Value* v)
|
||||
LLValue* DtoStructZeroInit(LLValue* v)
|
||||
{
|
||||
assert(gIR);
|
||||
uint64_t n = getTypeStoreSize(v->getType()->getContainedType(0));
|
||||
//llvm::Type* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
|
||||
const llvm::Type* sarrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
//LLType* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
|
||||
const LLType* sarrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
|
||||
llvm::Value* sarr = DtoBitCast(v, sarrty);
|
||||
LLValue* sarr = DtoBitCast(v, sarrty);
|
||||
|
||||
llvm::Function* fn = LLVM_DeclareMemSet32();
|
||||
std::vector<llvm::Value*> llargs;
|
||||
assert(fn);
|
||||
std::vector<LLValue*> llargs;
|
||||
llargs.resize(4);
|
||||
llargs[0] = sarr;
|
||||
llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false);
|
||||
llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
|
||||
llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
|
||||
|
||||
llvm::Value* ret = llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
|
||||
LLValue* ret = llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* DtoStructCopy(llvm::Value* dst, llvm::Value* src)
|
||||
LLValue* DtoStructCopy(LLValue* dst, LLValue* src)
|
||||
{
|
||||
Logger::cout() << "dst = " << *dst << " src = " << *src << '\n';
|
||||
assert(dst->getType() == src->getType());
|
||||
assert(gIR);
|
||||
|
||||
uint64_t n = getTypeStoreSize(dst->getType()->getContainedType(0));
|
||||
//llvm::Type* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
|
||||
const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
//LLType* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
|
||||
const LLType* arrty = getPtrToType(llvm::Type::Int8Ty);
|
||||
|
||||
llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
|
||||
llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb());
|
||||
LLValue* dstarr = DtoBitCast(dst,arrty);
|
||||
LLValue* srcarr = DtoBitCast(src,arrty);
|
||||
|
||||
llvm::Function* fn = LLVM_DeclareMemCpy32();
|
||||
std::vector<llvm::Value*> llargs;
|
||||
std::vector<LLValue*> llargs;
|
||||
llargs.resize(4);
|
||||
llargs[0] = dstarr;
|
||||
llargs[1] = srcarr;
|
||||
@@ -75,7 +76,7 @@ llvm::Value* DtoStructCopy(llvm::Value* dst, llvm::Value* src)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
llvm::Constant* DtoConstStructInitializer(StructInitializer* si)
|
||||
LLConstant* DtoConstStructInitializer(StructInitializer* si)
|
||||
{
|
||||
Logger::println("DtoConstStructInitializer: %s", si->toChars());
|
||||
LOG_SCOPE;
|
||||
@@ -94,7 +95,7 @@ llvm::Constant* DtoConstStructInitializer(StructInitializer* si)
|
||||
assert(ini);
|
||||
VarDeclaration* vd = (VarDeclaration*)si->vars.data[i];
|
||||
assert(vd);
|
||||
llvm::Constant* v = DtoConstInitializer(vd->type, ini);
|
||||
LLConstant* v = DtoConstInitializer(vd->type, ini);
|
||||
inits.push_back(DUnionIdx(vd->ir.irField->index, vd->ir.irField->indexOffset, v));
|
||||
}
|
||||
|
||||
@@ -104,7 +105,7 @@ llvm::Constant* DtoConstStructInitializer(StructInitializer* si)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs)
|
||||
LLValue* DtoIndexStruct(LLValue* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs)
|
||||
{
|
||||
Logger::println("checking for offset %u type %s:", os, t->toChars());
|
||||
LOG_SCOPE;
|
||||
@@ -112,8 +113,8 @@ llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, un
|
||||
if (idxs.empty())
|
||||
idxs.push_back(0);
|
||||
|
||||
const llvm::Type* llt = getPtrToType(DtoType(t));
|
||||
const llvm::Type* st = getPtrToType(DtoType(sd->type));
|
||||
const LLType* llt = getPtrToType(DtoType(t));
|
||||
const LLType* st = getPtrToType(DtoType(sd->type));
|
||||
if (ptr->getType() != st) {
|
||||
assert(sd->ir.irStruct->hasUnions);
|
||||
ptr = gIR->ir->CreateBitCast(ptr, st, "tmp");
|
||||
@@ -147,7 +148,7 @@ llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, un
|
||||
return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
|
||||
}
|
||||
else {
|
||||
const llvm::Type* sty = getPtrToType(DtoType(vd->type));
|
||||
const LLType* sty = getPtrToType(DtoType(vd->type));
|
||||
if (ptr->getType() != sty) {
|
||||
ptr = DtoBitCast(ptr, sty);
|
||||
std::vector<unsigned> tmp;
|
||||
@@ -221,7 +222,7 @@ void DtoResolveStruct(StructDeclaration* sd)
|
||||
Logger::println("doing struct fields");
|
||||
|
||||
const llvm::StructType* structtype = 0;
|
||||
std::vector<const llvm::Type*> fieldtypes;
|
||||
std::vector<const LLType*> fieldtypes;
|
||||
|
||||
if (irstruct->offsets.empty())
|
||||
{
|
||||
@@ -234,7 +235,7 @@ void DtoResolveStruct(StructDeclaration* sd)
|
||||
Logger::println("has fields");
|
||||
unsigned prevsize = (unsigned)-1;
|
||||
unsigned lastoffset = (unsigned)-1;
|
||||
const llvm::Type* fieldtype = NULL;
|
||||
const LLType* fieldtype = NULL;
|
||||
VarDeclaration* fieldinit = NULL;
|
||||
size_t fieldpad = 0;
|
||||
int idx = 0;
|
||||
@@ -361,7 +362,7 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
||||
for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i)
|
||||
{
|
||||
IrStruct::Offset* so = &i->second;
|
||||
llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
|
||||
LLConstant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
|
||||
so->init = finit;
|
||||
so->var->ir.irField->constInit = finit;
|
||||
}
|
||||
@@ -369,17 +370,17 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
||||
const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get());
|
||||
|
||||
// go through the field inits and build the default initializer
|
||||
std::vector<llvm::Constant*> fieldinits_ll;
|
||||
std::vector<LLConstant*> fieldinits_ll;
|
||||
size_t nfi = irstruct->defaultFields.size();
|
||||
for (size_t i=0; i<nfi; ++i) {
|
||||
llvm::Constant* c;
|
||||
LLConstant* c;
|
||||
if (irstruct->defaultFields[i] != NULL) {
|
||||
c = irstruct->defaultFields[i]->ir.irField->constInit;
|
||||
assert(c);
|
||||
}
|
||||
else {
|
||||
const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i));
|
||||
std::vector<llvm::Constant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
|
||||
std::vector<LLConstant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
|
||||
c = llvm::ConstantArray::get(arrty, vals);
|
||||
}
|
||||
fieldinits_ll.push_back(c);
|
||||
@@ -446,7 +447,7 @@ DUnion::DUnion()
|
||||
{
|
||||
unsigned o = i->first;
|
||||
IrStruct::Offset* so = &i->second;
|
||||
const llvm::Type* ft = so->init->getType();
|
||||
const LLType* ft = so->init->getType();
|
||||
size_t sz = getABITypeSize(ft);
|
||||
if (f == NULL) { // new field
|
||||
fields.push_back(DUnionField());
|
||||
@@ -494,17 +495,17 @@ DUnion::DUnion()
|
||||
}*/
|
||||
}
|
||||
|
||||
static void push_nulls(size_t nbytes, std::vector<llvm::Constant*>& out)
|
||||
static void push_nulls(size_t nbytes, std::vector<LLConstant*>& out)
|
||||
{
|
||||
assert(nbytes > 0);
|
||||
std::vector<llvm::Constant*> i(nbytes, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
|
||||
std::vector<LLConstant*> i(nbytes, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
|
||||
out.push_back(llvm::ConstantArray::get(llvm::ArrayType::get(llvm::Type::Int8Ty, nbytes), i));
|
||||
}
|
||||
|
||||
llvm::Constant* DUnion::getConst(std::vector<DUnionIdx>& in)
|
||||
LLConstant* DUnion::getConst(std::vector<DUnionIdx>& in)
|
||||
{
|
||||
std::sort(in.begin(), in.end());
|
||||
std::vector<llvm::Constant*> out;
|
||||
std::vector<LLConstant*> out;
|
||||
|
||||
size_t nin = in.size();
|
||||
size_t nfields = fields.size();
|
||||
@@ -561,7 +562,7 @@ llvm::Constant* DUnion::getConst(std::vector<DUnionIdx>& in)
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<const llvm::Type*> tys;
|
||||
std::vector<const LLType*> tys;
|
||||
size_t nout = out.size();
|
||||
for (size_t i=0; i<nout; ++i)
|
||||
tys.push_back(out[i]->getType());
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
struct StructInitializer;
|
||||
|
||||
const llvm::Type* DtoStructType(Type* t);
|
||||
const LLType* DtoStructType(Type* t);
|
||||
|
||||
llvm::Value* DtoStructZeroInit(llvm::Value* v);
|
||||
llvm::Value* DtoStructCopy(llvm::Value* dst, llvm::Value* src);
|
||||
LLValue* DtoStructZeroInit(LLValue* v);
|
||||
LLValue* DtoStructCopy(LLValue* dst, LLValue* src);
|
||||
|
||||
llvm::Constant* DtoConstStructInitializer(StructInitializer* si);
|
||||
LLConstant* DtoConstStructInitializer(StructInitializer* si);
|
||||
|
||||
/**
|
||||
* Resolves the llvm type for a struct
|
||||
@@ -30,14 +30,14 @@ void DtoConstInitStruct(StructDeclaration* sd);
|
||||
*/
|
||||
void DtoDefineStruct(StructDeclaration* sd);
|
||||
|
||||
llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs);
|
||||
LLValue* DtoIndexStruct(LLValue* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs);
|
||||
|
||||
struct DUnionField
|
||||
{
|
||||
unsigned offset;
|
||||
size_t size;
|
||||
std::vector<const llvm::Type*> types;
|
||||
llvm::Constant* init;
|
||||
std::vector<const LLType*> types;
|
||||
LLConstant* init;
|
||||
size_t initsize;
|
||||
|
||||
DUnionField() {
|
||||
@@ -51,11 +51,11 @@ struct DUnionField
|
||||
struct DUnionIdx
|
||||
{
|
||||
unsigned idx,idxos;
|
||||
llvm::Constant* c;
|
||||
LLConstant* c;
|
||||
|
||||
DUnionIdx()
|
||||
: idx(0), c(0) {}
|
||||
DUnionIdx(unsigned _idx, unsigned _idxos, llvm::Constant* _c)
|
||||
DUnionIdx(unsigned _idx, unsigned _idxos, LLConstant* _c)
|
||||
: idx(_idx), idxos(_idxos), c(_c) {}
|
||||
bool operator<(const DUnionIdx& i) const {
|
||||
return (idx < i.idx) || (idx == i.idx && idxos < i.idxos);
|
||||
@@ -67,7 +67,7 @@ class DUnion
|
||||
std::vector<DUnionField> fields;
|
||||
public:
|
||||
DUnion();
|
||||
llvm::Constant* getConst(std::vector<DUnionIdx>& in);
|
||||
LLConstant* getConst(std::vector<DUnionIdx>& in);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
|
||||
using namespace llvm::dwarf;
|
||||
|
||||
static const llvm::PointerType* ptrTy(const llvm::Type* t)
|
||||
static const llvm::PointerType* ptrTy(const LLType* t)
|
||||
{
|
||||
return llvm::PointerType::get(t, 0);
|
||||
}
|
||||
|
||||
static const llvm::PointerType* dbgArrTy()
|
||||
{
|
||||
std::vector<const llvm::Type*> t;
|
||||
std::vector<const LLType*> t;
|
||||
return ptrTy(llvm::StructType::get(t));
|
||||
}
|
||||
|
||||
static llvm::Constant* dbgToArrTy(llvm::Constant* c)
|
||||
static LLConstant* dbgToArrTy(LLConstant* c)
|
||||
{
|
||||
Logger::cout() << "casting: " << *c << '\n';
|
||||
return llvm::ConstantExpr::getBitCast(c, dbgArrTy());
|
||||
@@ -48,7 +48,7 @@ const llvm::StructType* GetDwarfAnchorType()
|
||||
uint ;; Tag of descriptors grouped by the anchor
|
||||
}
|
||||
*/
|
||||
std::vector<const llvm::Type*> elems(2, Ty(Int32Ty));
|
||||
std::vector<const LLType*> elems(2, Ty(Int32Ty));
|
||||
const llvm::StructType* t = isaStruct(gIR->module->getTypeByName("llvm.dbg.anchor.type"));
|
||||
|
||||
/*
|
||||
@@ -57,26 +57,26 @@ const llvm::StructType* GetDwarfAnchorType()
|
||||
%llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 46 } ;; DW_TAG_subprogram
|
||||
*/
|
||||
if (!gIR->module->getNamedGlobal("llvm.dbg.compile_units")) {
|
||||
std::vector<llvm::Constant*> vals;
|
||||
std::vector<LLConstant*> vals;
|
||||
vals.push_back(DtoConstUint(llvm::LLVMDebugVersion));
|
||||
vals.push_back(DtoConstUint(DW_TAG_compile_unit));
|
||||
llvm::Constant* i = llvm::ConstantStruct::get(t, vals);
|
||||
LLConstant* i = llvm::ConstantStruct::get(t, vals);
|
||||
dbg_compile_units = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.compile_units",gIR->module);
|
||||
dbg_compile_units->setSection("llvm.metadata");
|
||||
}
|
||||
if (!gIR->module->getNamedGlobal("llvm.dbg.global_variables")) {
|
||||
std::vector<llvm::Constant*> vals;
|
||||
std::vector<LLConstant*> vals;
|
||||
vals.push_back(DtoConstUint(llvm::LLVMDebugVersion));
|
||||
vals.push_back(DtoConstUint(DW_TAG_variable));
|
||||
llvm::Constant* i = llvm::ConstantStruct::get(t, vals);
|
||||
LLConstant* i = llvm::ConstantStruct::get(t, vals);
|
||||
dbg_global_variables = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.global_variables",gIR->module);
|
||||
dbg_global_variables->setSection("llvm.metadata");
|
||||
}
|
||||
if (!gIR->module->getNamedGlobal("llvm.dbg.subprograms")) {
|
||||
std::vector<llvm::Constant*> vals;
|
||||
std::vector<LLConstant*> vals;
|
||||
vals.push_back(DtoConstUint(llvm::LLVMDebugVersion));
|
||||
vals.push_back(DtoConstUint(DW_TAG_subprogram));
|
||||
llvm::Constant* i = llvm::ConstantStruct::get(t, vals);
|
||||
LLConstant* i = llvm::ConstantStruct::get(t, vals);
|
||||
dbg_subprograms = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.subprograms",gIR->module);
|
||||
dbg_subprograms->setSection("llvm.metadata");
|
||||
}
|
||||
@@ -84,7 +84,7 @@ const llvm::StructType* GetDwarfAnchorType()
|
||||
return t;
|
||||
}
|
||||
|
||||
llvm::Constant* GetDwarfAnchor(llvm::dwarf::dwarf_constants c)
|
||||
LLConstant* GetDwarfAnchor(llvm::dwarf::dwarf_constants c)
|
||||
{
|
||||
GetDwarfAnchorType();
|
||||
switch (c)
|
||||
@@ -124,9 +124,9 @@ llvm::GlobalVariable* DtoDwarfCompileUnit(Module* m)
|
||||
|
||||
// create a valid compile unit constant for the current module
|
||||
|
||||
llvm::Constant* c = NULL;
|
||||
LLConstant* c = NULL;
|
||||
|
||||
std::vector<llvm::Constant*> vals;
|
||||
std::vector<LLConstant*> vals;
|
||||
vals.push_back(llvm::ConstantExpr::getAdd(
|
||||
DtoConstUint(DW_TAG_compile_unit),
|
||||
DtoConstUint(llvm::LLVMDebugVersion)));
|
||||
@@ -156,7 +156,7 @@ llvm::GlobalVariable* DtoDwarfCompileUnit(Module* m)
|
||||
|
||||
llvm::GlobalVariable* DtoDwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariable* compileUnit)
|
||||
{
|
||||
std::vector<llvm::Constant*> vals;
|
||||
std::vector<LLConstant*> vals;
|
||||
vals.push_back(llvm::ConstantExpr::getAdd(
|
||||
DtoConstUint(DW_TAG_subprogram),
|
||||
DtoConstUint(llvm::LLVMDebugVersion)));
|
||||
@@ -172,7 +172,7 @@ llvm::GlobalVariable* DtoDwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariab
|
||||
vals.push_back(DtoConstBool(fd->protection == PROTprivate));
|
||||
vals.push_back(DtoConstBool(fd->getModule() == gIR->dmodule));
|
||||
|
||||
llvm::Constant* c = llvm::ConstantStruct::get(GetDwarfSubProgramType(), vals);
|
||||
LLConstant* c = llvm::ConstantStruct::get(GetDwarfSubProgramType(), vals);
|
||||
llvm::GlobalVariable* gv = new llvm::GlobalVariable(c->getType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.subprogram", gIR->module);
|
||||
gv->setSection("llvm.metadata");
|
||||
return gv;
|
||||
@@ -196,7 +196,7 @@ void DtoDwarfFuncEnd(FuncDeclaration* fd)
|
||||
|
||||
void DtoDwarfStopPoint(unsigned ln)
|
||||
{
|
||||
std::vector<llvm::Value*> args;
|
||||
std::vector<LLValue*> args;
|
||||
args.push_back(DtoConstUint(ln));
|
||||
args.push_back(DtoConstUint(0));
|
||||
FuncDeclaration* fd = gIR->func()->decl;
|
||||
|
||||
377
gen/toir.cpp
377
gen/toir.cpp
File diff suppressed because it is too large
Load Diff
382
gen/tollvm.cpp
382
gen/tollvm.cpp
File diff suppressed because it is too large
Load Diff
92
gen/tollvm.h
92
gen/tollvm.h
@@ -8,7 +8,7 @@
|
||||
#include "declaration.h"
|
||||
|
||||
// D->LLVM type handling stuff
|
||||
const llvm::Type* DtoType(Type* t);
|
||||
const LLType* DtoType(Type* t);
|
||||
bool DtoIsPassedByRef(Type* type);
|
||||
|
||||
// resolve typedefs to their real type.
|
||||
@@ -17,9 +17,9 @@ Type* DtoDType(Type* t);
|
||||
|
||||
// delegate helpers
|
||||
const llvm::StructType* DtoDelegateType(Type* t);
|
||||
llvm::Value* DtoDelegateToNull(llvm::Value* v);
|
||||
llvm::Value* DtoDelegateCopy(llvm::Value* dst, llvm::Value* src);
|
||||
llvm::Value* DtoDelegateCompare(TOK op, llvm::Value* lhs, llvm::Value* rhs);
|
||||
void DtoDelegateToNull(LLValue* v);
|
||||
void DtoDelegateCopy(LLValue* dst, LLValue* src);
|
||||
LLValue* DtoDelegateCompare(TOK op, LLValue* lhs, LLValue* rhs);
|
||||
|
||||
// return linkage type for symbol using the current ir state for context
|
||||
llvm::GlobalValue::LinkageTypes DtoLinkage(Dsymbol* sym);
|
||||
@@ -30,21 +30,21 @@ llvm::GlobalValue::LinkageTypes DtoExternalLinkage(Dsymbol* sym);
|
||||
unsigned DtoCallingConv(LINK l);
|
||||
|
||||
// TODO: this one should be removed!!!
|
||||
llvm::Value* DtoPointedType(llvm::Value* ptr, llvm::Value* val);
|
||||
LLValue* DtoPointedType(LLValue* ptr, LLValue* val);
|
||||
|
||||
// casts any value to a boolean
|
||||
llvm::Value* DtoBoolean(llvm::Value* val);
|
||||
LLValue* DtoBoolean(LLValue* val);
|
||||
|
||||
// some types
|
||||
const llvm::Type* DtoSize_t();
|
||||
const LLType* DtoSize_t();
|
||||
const llvm::StructType* DtoInterfaceInfoType();
|
||||
|
||||
// getting typeinfo of type
|
||||
llvm::Constant* DtoTypeInfoOf(Type* ty);
|
||||
// getting typeinfo of type, base=true casts to object.TypeInfo
|
||||
LLConstant* DtoTypeInfoOf(Type* ty, bool base=true);
|
||||
|
||||
// initializer helpers
|
||||
llvm::Constant* DtoConstInitializer(Type* type, Initializer* init);
|
||||
llvm::Constant* DtoConstFieldInitializer(Type* type, Initializer* init);
|
||||
LLConstant* DtoConstInitializer(Type* type, Initializer* init);
|
||||
LLConstant* DtoConstFieldInitializer(Type* type, Initializer* init);
|
||||
DValue* DtoInitializer(Initializer* init);
|
||||
|
||||
// declaration of memset/cpy intrinsics
|
||||
@@ -54,24 +54,24 @@ llvm::Function* LLVM_DeclareMemCpy32();
|
||||
llvm::Function* LLVM_DeclareMemCpy64();
|
||||
|
||||
// getelementptr helpers
|
||||
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);
|
||||
LLValue* DtoGEP(LLValue* ptr, LLValue* i0, LLValue* i1, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
LLValue* DtoGEP(LLValue* ptr, const std::vector<unsigned>& src, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
LLValue* DtoGEPi(LLValue* ptr, unsigned i0, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
LLValue* DtoGEPi(LLValue* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb=NULL);
|
||||
|
||||
// dynamic memory helpers
|
||||
llvm::Value* DtoNew(Type* newtype);
|
||||
void DtoDeleteMemory(llvm::Value* ptr);
|
||||
void DtoDeleteClass(llvm::Value* inst);
|
||||
void DtoDeleteInterface(llvm::Value* inst);
|
||||
LLValue* DtoNew(Type* newtype);
|
||||
void DtoDeleteMemory(LLValue* ptr);
|
||||
void DtoDeleteClass(LLValue* inst);
|
||||
void DtoDeleteInterface(LLValue* inst);
|
||||
void DtoDeleteArray(DValue* arr);
|
||||
|
||||
// assertion generator
|
||||
void DtoAssert(Loc* loc, DValue* msg);
|
||||
|
||||
// nested variable/class helpers
|
||||
llvm::Value* DtoNestedContext(FuncDeclaration* func);
|
||||
llvm::Value* DtoNestedVariable(VarDeclaration* vd);
|
||||
LLValue* DtoNestedContext(FuncDeclaration* func);
|
||||
LLValue* DtoNestedVariable(VarDeclaration* vd);
|
||||
|
||||
// annotation generator
|
||||
void DtoAnnotation(const char* str);
|
||||
@@ -82,15 +82,15 @@ llvm::ConstantInt* DtoConstUint(unsigned i);
|
||||
llvm::ConstantInt* DtoConstInt(int i);
|
||||
llvm::ConstantFP* DtoConstFP(Type* t, long double value);
|
||||
|
||||
llvm::Constant* DtoConstString(const char*);
|
||||
llvm::Constant* DtoConstStringPtr(const char* str, const char* section = 0);
|
||||
llvm::Constant* DtoConstBool(bool);
|
||||
LLConstant* DtoConstString(const char*);
|
||||
LLConstant* DtoConstStringPtr(const char* str, const char* section = 0);
|
||||
LLConstant* DtoConstBool(bool);
|
||||
|
||||
// is template instance check
|
||||
bool DtoIsTemplateInstance(Dsymbol* s);
|
||||
|
||||
// generates lazy static initialization code for a global variable
|
||||
void DtoLazyStaticInit(bool istempl, llvm::Value* gvar, Initializer* init, Type* t);
|
||||
void DtoLazyStaticInit(bool istempl, LLValue* gvar, Initializer* init, Type* t);
|
||||
|
||||
// these are all basically drivers for the codegeneration called by the main loop
|
||||
void DtoResolveDsymbol(Dsymbol* dsym);
|
||||
@@ -107,35 +107,35 @@ void DtoForceConstInitDsymbol(Dsymbol* dsym);
|
||||
void DtoForceDefineDsymbol(Dsymbol* dsym);
|
||||
|
||||
// llvm wrappers
|
||||
void DtoMemSetZero(llvm::Value* dst, llvm::Value* nbytes);
|
||||
void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes);
|
||||
void DtoMemSetZero(LLValue* dst, LLValue* nbytes);
|
||||
void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes);
|
||||
void DtoMemoryBarrier(bool ll, bool ls, bool sl, bool ss, bool device=false);
|
||||
bool DtoCanLoad(llvm::Value* ptr);
|
||||
llvm::Value* DtoLoad(llvm::Value* src);
|
||||
void DtoStore(llvm::Value* src, llvm::Value* dst);
|
||||
llvm::Value* DtoBitCast(llvm::Value* v, const llvm::Type* t, const char* name=0);
|
||||
bool DtoCanLoad(LLValue* ptr);
|
||||
LLValue* DtoLoad(LLValue* src, const char* name=0);
|
||||
void DtoStore(LLValue* src, LLValue* dst);
|
||||
LLValue* DtoBitCast(LLValue* v, const LLType* t, const char* name=0);
|
||||
|
||||
// llvm::dyn_cast wrappers
|
||||
const llvm::PointerType* isaPointer(llvm::Value* v);
|
||||
const llvm::PointerType* isaPointer(const llvm::Type* t);
|
||||
const llvm::ArrayType* isaArray(llvm::Value* v);
|
||||
const llvm::ArrayType* isaArray(const llvm::Type* t);
|
||||
const llvm::StructType* isaStruct(llvm::Value* v);
|
||||
const llvm::StructType* isaStruct(const llvm::Type* t);
|
||||
llvm::Constant* isaConstant(llvm::Value* v);
|
||||
llvm::ConstantInt* isaConstantInt(llvm::Value* v);
|
||||
llvm::Argument* isaArgument(llvm::Value* v);
|
||||
llvm::GlobalVariable* isaGlobalVar(llvm::Value* v);
|
||||
const llvm::PointerType* isaPointer(LLValue* v);
|
||||
const llvm::PointerType* isaPointer(const LLType* t);
|
||||
const llvm::ArrayType* isaArray(LLValue* v);
|
||||
const llvm::ArrayType* isaArray(const LLType* t);
|
||||
const llvm::StructType* isaStruct(LLValue* v);
|
||||
const llvm::StructType* isaStruct(const LLType* t);
|
||||
LLConstant* isaConstant(LLValue* v);
|
||||
llvm::ConstantInt* isaConstantInt(LLValue* v);
|
||||
llvm::Argument* isaArgument(LLValue* v);
|
||||
llvm::GlobalVariable* isaGlobalVar(LLValue* v);
|
||||
|
||||
// llvm::T::get(...) wrappers
|
||||
const llvm::PointerType* getPtrToType(const llvm::Type* t);
|
||||
const llvm::PointerType* getPtrToType(const LLType* t);
|
||||
const llvm::PointerType* getVoidPtrType();
|
||||
llvm::ConstantPointerNull* getNullPtr(const llvm::Type* t);
|
||||
llvm::ConstantPointerNull* getNullPtr(const LLType* t);
|
||||
|
||||
// type sizes
|
||||
size_t getTypeBitSize(const llvm::Type* t);
|
||||
size_t getTypeStoreSize(const llvm::Type* t);
|
||||
size_t getABITypeSize(const llvm::Type* t);
|
||||
size_t getTypeBitSize(const LLType* t);
|
||||
size_t getTypeStoreSize(const LLType* t);
|
||||
size_t getABITypeSize(const LLType* t);
|
||||
|
||||
// basic operations
|
||||
void DtoAssign(DValue* lhs, DValue* rhs);
|
||||
|
||||
@@ -187,7 +187,7 @@ static llvm::Function* build_module_ctor()
|
||||
name.append(gIR->dmodule->mangle());
|
||||
name.append("6__ctorZ");
|
||||
|
||||
std::vector<const llvm::Type*> argsTy;
|
||||
std::vector<const LLType*> argsTy;
|
||||
const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false);
|
||||
assert(gIR->module->getFunction(name) == NULL);
|
||||
llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
|
||||
@@ -221,7 +221,7 @@ static llvm::Function* build_module_dtor()
|
||||
name.append(gIR->dmodule->mangle());
|
||||
name.append("6__dtorZ");
|
||||
|
||||
std::vector<const llvm::Type*> argsTy;
|
||||
std::vector<const LLType*> argsTy;
|
||||
const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false);
|
||||
assert(gIR->module->getFunction(name) == NULL);
|
||||
llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
|
||||
@@ -255,7 +255,7 @@ static llvm::Function* build_module_unittest()
|
||||
name.append(gIR->dmodule->mangle());
|
||||
name.append("10__unittestZ");
|
||||
|
||||
std::vector<const llvm::Type*> argsTy;
|
||||
std::vector<const LLType*> argsTy;
|
||||
const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false);
|
||||
assert(gIR->module->getFunction(name) == NULL);
|
||||
llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
|
||||
@@ -302,8 +302,8 @@ void Module::genmoduleinfo()
|
||||
const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get());
|
||||
|
||||
// initializer vector
|
||||
std::vector<llvm::Constant*> initVec;
|
||||
llvm::Constant* c = 0;
|
||||
std::vector<LLConstant*> initVec;
|
||||
LLConstant* c = 0;
|
||||
|
||||
// vtable
|
||||
c = moduleinfo->ir.irStruct->vtbl;
|
||||
@@ -320,7 +320,7 @@ void Module::genmoduleinfo()
|
||||
|
||||
// importedModules[]
|
||||
int aimports_dim = aimports.dim;
|
||||
std::vector<llvm::Constant*> importInits;
|
||||
std::vector<LLConstant*> importInits;
|
||||
for (size_t i = 0; i < aimports.dim; i++)
|
||||
{
|
||||
Module *m = (Module *)aimports.data[i];
|
||||
@@ -365,7 +365,7 @@ void Module::genmoduleinfo()
|
||||
member->addLocalClass(&aclasses);
|
||||
}
|
||||
// fill inits
|
||||
std::vector<llvm::Constant*> classInits;
|
||||
std::vector<LLConstant*> classInits;
|
||||
for (size_t i = 0; i < aclasses.dim; i++)
|
||||
{
|
||||
ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i];
|
||||
@@ -433,7 +433,7 @@ void Module::genmoduleinfo()
|
||||
}*/
|
||||
|
||||
// create initializer
|
||||
llvm::Constant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec);
|
||||
LLConstant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec);
|
||||
|
||||
// create name
|
||||
std::string MIname("_D");
|
||||
@@ -449,9 +449,9 @@ void Module::genmoduleinfo()
|
||||
|
||||
// declare the appending array
|
||||
const llvm::ArrayType* appendArrTy = llvm::ArrayType::get(getPtrToType(llvm::Type::Int8Ty), 1);
|
||||
std::vector<llvm::Constant*> appendInits;
|
||||
std::vector<LLConstant*> appendInits;
|
||||
appendInits.push_back(llvm::ConstantExpr::getBitCast(gvar, getPtrToType(llvm::Type::Int8Ty)));
|
||||
llvm::Constant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits);
|
||||
LLConstant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits);
|
||||
std::string appendName("_d_moduleinfo_array");
|
||||
llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module);
|
||||
}
|
||||
@@ -545,7 +545,7 @@ void VarDeclaration::toObjFile()
|
||||
|
||||
Logger::println("Creating global variable");
|
||||
|
||||
const llvm::Type* _type = this->ir.irGlobal->type.get();
|
||||
const LLType* _type = this->ir.irGlobal->type.get();
|
||||
llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this);
|
||||
std::string _name(mangle());
|
||||
|
||||
@@ -565,7 +565,7 @@ void VarDeclaration::toObjFile()
|
||||
{
|
||||
Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset);
|
||||
|
||||
const llvm::Type* _type = DtoType(type);
|
||||
const LLType* _type = DtoType(type);
|
||||
this->ir.irField = new IrField(this);
|
||||
|
||||
// add the field in the IRStruct
|
||||
|
||||
@@ -233,7 +233,7 @@ int TypeDArray::builtinTypeInfo()
|
||||
|
||||
Expression *createTypeInfoArray(Scope *sc, Expression *exps[], int dim)
|
||||
{
|
||||
assert(0);
|
||||
assert(0); // done elsewhere in llvmdc
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -276,10 +276,10 @@ void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
|
||||
|
||||
// this is a declaration of a builtin __initZ var
|
||||
if (tid->tinfo->builtinTypeInfo()) {
|
||||
llvm::Value* found = gIR->module->getNamedGlobal(mangled);
|
||||
LLValue* found = gIR->module->getNamedGlobal(mangled);
|
||||
if (!found)
|
||||
{
|
||||
const llvm::Type* t = llvm::OpaqueType::get();
|
||||
const LLType* t = llvm::OpaqueType::get();
|
||||
llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module);
|
||||
assert(g);
|
||||
/*if (!tid->ir.irGlobal)
|
||||
@@ -371,7 +371,7 @@ void TypeInfoTypedefDeclaration::llvmDefine()
|
||||
Logger::cout() << "got stype: " << *stype << '\n';
|
||||
|
||||
// vtbl
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
sinits.push_back(base->ir.irStruct->vtbl);
|
||||
|
||||
// monitor
|
||||
@@ -393,7 +393,7 @@ void TypeInfoTypedefDeclaration::llvmDefine()
|
||||
|
||||
assert(sd->basetype->vtinfo->ir.irGlobal->value);
|
||||
assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->ir.irGlobal->value));
|
||||
llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->ir.irGlobal->value);
|
||||
LLConstant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->ir.irGlobal->value);
|
||||
castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
|
||||
sinits.push_back(castbase);
|
||||
|
||||
@@ -410,17 +410,17 @@ void TypeInfoTypedefDeclaration::llvmDefine()
|
||||
}
|
||||
else
|
||||
{
|
||||
llvm::Constant* ci = DtoConstInitializer(sd->basetype, sd->init);
|
||||
LLConstant* ci = DtoConstInitializer(sd->basetype, sd->init);
|
||||
std::string ciname(sd->mangle());
|
||||
ciname.append("__init");
|
||||
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);
|
||||
LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt);
|
||||
size_t cisize = getTypeStoreSize(DtoType(sd->basetype));
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
|
||||
}
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ void TypeInfoEnumDeclaration::llvmDefine()
|
||||
const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
|
||||
|
||||
// vtbl
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
sinits.push_back(base->ir.irStruct->vtbl);
|
||||
|
||||
// monitor
|
||||
@@ -477,7 +477,7 @@ void TypeInfoEnumDeclaration::llvmDefine()
|
||||
DtoForceDeclareDsymbol(sd->memtype->vtinfo);
|
||||
|
||||
assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->ir.irGlobal->value));
|
||||
llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->ir.irGlobal->value);
|
||||
LLConstant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->ir.irGlobal->value);
|
||||
castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
|
||||
sinits.push_back(castbase);
|
||||
|
||||
@@ -494,18 +494,18 @@ void TypeInfoEnumDeclaration::llvmDefine()
|
||||
}
|
||||
else
|
||||
{
|
||||
const llvm::Type* memty = DtoType(sd->memtype);
|
||||
llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned());
|
||||
const LLType* memty = DtoType(sd->memtype);
|
||||
LLConstant* 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);
|
||||
LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt);
|
||||
size_t cisize = getTypeStoreSize(memty);
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
|
||||
}
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
|
||||
}
|
||||
|
||||
@@ -516,7 +516,7 @@ void TypeInfoEnumDeclaration::toDt(dt_t **pdt)
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
static llvm::Constant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd)
|
||||
static LLConstant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd)
|
||||
{
|
||||
ClassDeclaration* base = cd;
|
||||
DtoResolveClass(base);
|
||||
@@ -527,7 +527,7 @@ static llvm::Constant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, Cla
|
||||
tid->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module);
|
||||
}
|
||||
|
||||
static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd)
|
||||
static LLConstant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd)
|
||||
{
|
||||
ClassDeclaration* base = cd;
|
||||
DtoForceConstInitDsymbol(base);
|
||||
@@ -535,7 +535,7 @@ static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclar
|
||||
const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
|
||||
|
||||
// vtbl
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
sinits.push_back(base->ir.irStruct->vtbl);
|
||||
|
||||
// monitor
|
||||
@@ -547,12 +547,12 @@ static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclar
|
||||
assert(basetype->vtinfo);
|
||||
DtoForceDeclareDsymbol(basetype->vtinfo);
|
||||
assert(llvm::isa<llvm::Constant>(basetype->vtinfo->ir.irGlobal->value));
|
||||
llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->ir.irGlobal->value);
|
||||
LLConstant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->ir.irGlobal->value);
|
||||
castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
|
||||
sinits.push_back(castbase);
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
isaGlobalVar(tid->ir.irGlobal->value)->setInitializer(tiInit);
|
||||
}
|
||||
|
||||
@@ -645,7 +645,7 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
|
||||
const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
|
||||
|
||||
// initializer vector
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
// first is always the vtable
|
||||
sinits.push_back(base->ir.irStruct->vtbl);
|
||||
|
||||
@@ -660,7 +660,7 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
|
||||
// get symbol
|
||||
assert(tc->next->vtinfo);
|
||||
DtoForceDeclareDsymbol(tc->next->vtinfo);
|
||||
llvm::Constant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value);
|
||||
LLConstant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value);
|
||||
castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
|
||||
sinits.push_back(castbase);
|
||||
|
||||
@@ -668,7 +668,7 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
|
||||
sinits.push_back(DtoConstSize_t(tc->dim->toInteger()));
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
|
||||
}
|
||||
|
||||
@@ -708,7 +708,7 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
|
||||
const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
|
||||
|
||||
// initializer vector
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
// first is always the vtable
|
||||
sinits.push_back(base->ir.irStruct->vtbl);
|
||||
|
||||
@@ -725,7 +725,7 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
|
||||
// get symbol
|
||||
assert(tc->next->vtinfo);
|
||||
DtoForceDeclareDsymbol(tc->next->vtinfo);
|
||||
llvm::Constant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value);
|
||||
LLConstant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value);
|
||||
castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
|
||||
sinits.push_back(castbase);
|
||||
|
||||
@@ -740,7 +740,7 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
|
||||
sinits.push_back(castbase);
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
|
||||
}
|
||||
|
||||
@@ -844,7 +844,7 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
|
||||
|
||||
// vtbl
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
sinits.push_back(base->ir.irStruct->vtbl);
|
||||
|
||||
// monitor
|
||||
@@ -858,14 +858,17 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
|
||||
// void[] init
|
||||
const llvm::PointerType* initpt = getPtrToType(llvm::Type::Int8Ty);
|
||||
#if 0
|
||||
// the implementation of TypeInfo_Struct uses this to determine size. :/
|
||||
if (sd->zeroInit) // 0 initializer, or the same as the base type
|
||||
{
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
size_t cisize = getTypeStoreSize(tc->ir.type->get());
|
||||
llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(sd->ir.irStruct->init, initpt);
|
||||
LLConstant* cicast = llvm::ConstantExpr::getBitCast(sd->ir.irStruct->init, initpt);
|
||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
|
||||
}
|
||||
|
||||
@@ -926,7 +929,7 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
if (fd) {
|
||||
DtoForceDeclareDsymbol(fd);
|
||||
assert(fd->ir.irFunc->func != 0);
|
||||
llvm::Constant* c = isaConstant(fd->ir.irFunc->func);
|
||||
LLConstant* c = isaConstant(fd->ir.irFunc->func);
|
||||
assert(c);
|
||||
c = llvm::ConstantExpr::getBitCast(c, ptty);
|
||||
sinits.push_back(c);
|
||||
@@ -952,7 +955,7 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
if (fd) {
|
||||
DtoForceDeclareDsymbol(fd);
|
||||
assert(fd->ir.irFunc->func != 0);
|
||||
llvm::Constant* c = isaConstant(fd->ir.irFunc->func);
|
||||
LLConstant* c = isaConstant(fd->ir.irFunc->func);
|
||||
assert(c);
|
||||
c = llvm::ConstantExpr::getBitCast(c, ptty);
|
||||
sinits.push_back(c);
|
||||
@@ -980,7 +983,7 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
if (fd) {
|
||||
DtoForceDeclareDsymbol(fd);
|
||||
assert(fd->ir.irFunc->func != 0);
|
||||
llvm::Constant* c = isaConstant(fd->ir.irFunc->func);
|
||||
LLConstant* c = isaConstant(fd->ir.irFunc->func);
|
||||
assert(c);
|
||||
c = llvm::ConstantExpr::getBitCast(c, ptty);
|
||||
sinits.push_back(c);
|
||||
@@ -998,7 +1001,7 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
sinits.push_back(DtoConstUint(tc->hasPointers()));
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module);
|
||||
|
||||
isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
|
||||
@@ -1042,7 +1045,7 @@ void TypeInfoClassDeclaration::llvmDefine()
|
||||
const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
|
||||
|
||||
// initializer vector
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
// first is always the vtable
|
||||
sinits.push_back(base->ir.irStruct->vtbl);
|
||||
|
||||
@@ -1057,7 +1060,7 @@ void TypeInfoClassDeclaration::llvmDefine()
|
||||
sinits.push_back(tc->sym->ir.irStruct->classInfo);
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
|
||||
}
|
||||
|
||||
@@ -1099,7 +1102,7 @@ void TypeInfoInterfaceDeclaration::llvmDefine()
|
||||
const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
|
||||
|
||||
// initializer vector
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
// first is always the vtable
|
||||
sinits.push_back(base->ir.irStruct->vtbl);
|
||||
|
||||
@@ -1113,7 +1116,7 @@ void TypeInfoInterfaceDeclaration::llvmDefine()
|
||||
sinits.push_back(tc->sym->ir.irStruct->classInfo);
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
|
||||
}
|
||||
|
||||
@@ -1155,7 +1158,7 @@ void TypeInfoTupleDeclaration::llvmDefine()
|
||||
const llvm::StructType* stype = isaStruct(base->type->ir.type->get());
|
||||
|
||||
// initializer vector
|
||||
std::vector<llvm::Constant*> sinits;
|
||||
std::vector<LLConstant*> sinits;
|
||||
// first is always the vtable
|
||||
sinits.push_back(base->ir.irStruct->vtbl);
|
||||
|
||||
@@ -1167,9 +1170,9 @@ void TypeInfoTupleDeclaration::llvmDefine()
|
||||
TypeTuple *tu = (TypeTuple *)tinfo;
|
||||
|
||||
size_t dim = tu->arguments->dim;
|
||||
std::vector<llvm::Constant*> arrInits;
|
||||
std::vector<LLConstant*> arrInits;
|
||||
|
||||
const llvm::Type* tiTy = Type::typeinfo->type->ir.type->get();
|
||||
const LLType* tiTy = Type::typeinfo->type->ir.type->get();
|
||||
tiTy = getPtrToType(tiTy);
|
||||
|
||||
for (size_t i = 0; i < dim; i++)
|
||||
@@ -1178,21 +1181,21 @@ void TypeInfoTupleDeclaration::llvmDefine()
|
||||
arg->type->getTypeInfo(NULL);
|
||||
DtoForceDeclareDsymbol(arg->type->vtinfo);
|
||||
assert(arg->type->vtinfo->ir.irGlobal->value);
|
||||
llvm::Constant* c = isaConstant(arg->type->vtinfo->ir.irGlobal->value);
|
||||
LLConstant* c = isaConstant(arg->type->vtinfo->ir.irGlobal->value);
|
||||
c = llvm::ConstantExpr::getBitCast(c, tiTy);
|
||||
arrInits.push_back(c);
|
||||
}
|
||||
|
||||
// build array type
|
||||
const llvm::ArrayType* arrTy = llvm::ArrayType::get(tiTy, dim);
|
||||
llvm::Constant* arrC = llvm::ConstantArray::get(arrTy, arrInits);
|
||||
LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits);
|
||||
|
||||
// build the slice
|
||||
llvm::Constant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC);
|
||||
LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC);
|
||||
sinits.push_back(slice);
|
||||
|
||||
// create the symbol
|
||||
llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
|
||||
isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
|
||||
}
|
||||
|
||||
|
||||
@@ -747,6 +747,7 @@ tango/tango/util/log/model/ILevel.d
|
||||
tangotests
|
||||
tangotests/a.d
|
||||
tangotests/aa1.d
|
||||
tangotests/aa2.d
|
||||
tangotests/b.d
|
||||
tangotests/c.d
|
||||
tangotests/classes1.d
|
||||
@@ -775,6 +776,7 @@ tangotests/t.d
|
||||
tangotests/templ1.d
|
||||
tangotests/vararg1.d
|
||||
tangotests/vararg2.d
|
||||
tangotests/vararg3.d
|
||||
test
|
||||
test/a.d
|
||||
test/aa1.d
|
||||
|
||||
@@ -37,11 +37,11 @@
|
||||
|
||||
module object;
|
||||
|
||||
//debug=PRINTF;
|
||||
//debug=PRINTF
|
||||
|
||||
private
|
||||
{
|
||||
import tango.stdc.string; // : memcmp, memcpy;
|
||||
import tango.stdc.string; // : memcmp, memcpy, memmove;
|
||||
import tango.stdc.stdlib; // : calloc, realloc, free;
|
||||
import util.string;
|
||||
debug(PRINTF) import tango.stdc.stdio; // : printf;
|
||||
@@ -126,7 +126,8 @@ class Object
|
||||
|
||||
/**
|
||||
* Information about an interface.
|
||||
* A pointer to this appears as the first entry in the interface's vtbl[].
|
||||
* When an object is accessed via an interface, an Interface* appears as the
|
||||
* first entry in its vtbl.
|
||||
*/
|
||||
struct Interface
|
||||
{
|
||||
@@ -436,7 +437,7 @@ class TypeInfo_Array : TypeInfo
|
||||
TypeInfo next()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
uint flags() { return 1; }
|
||||
}
|
||||
@@ -623,8 +624,7 @@ class TypeInfo_Class : TypeInfo
|
||||
hash_t getHash(void *p)
|
||||
{
|
||||
Object o = *cast(Object*)p;
|
||||
assert(o);
|
||||
return o.toHash();
|
||||
return o ? o.toHash() : 0;
|
||||
}
|
||||
|
||||
int equals(void *p1, void *p2)
|
||||
@@ -888,24 +888,38 @@ class TypeInfo_Tuple : TypeInfo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Exception
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class Exception : Object
|
||||
{
|
||||
interface TraceInfo
|
||||
{
|
||||
int opApply( int delegate( inout char[] ) );
|
||||
}
|
||||
|
||||
char[] msg;
|
||||
char[] file;
|
||||
size_t line;
|
||||
TraceInfo info;
|
||||
Exception next;
|
||||
|
||||
this(char[] msg, Exception next = null)
|
||||
this( char[] msg, Exception next = null )
|
||||
{
|
||||
this.msg = msg;
|
||||
this.next = next;
|
||||
this.info = traceContext();
|
||||
}
|
||||
|
||||
this(char[] msg, char[] file, size_t line, Exception next = null)
|
||||
this( char[] msg, char[] file, size_t line, Exception next = null )
|
||||
{
|
||||
this(msg, next);
|
||||
this.file = file;
|
||||
this.line = line;
|
||||
this.info = traceContext();
|
||||
}
|
||||
|
||||
char[] toString()
|
||||
@@ -915,6 +929,44 @@ class Exception : Object
|
||||
}
|
||||
|
||||
|
||||
alias Exception.TraceInfo function( void* ptr = null ) TraceHandler;
|
||||
private TraceHandler traceHandler = null;
|
||||
|
||||
|
||||
/**
|
||||
* Overrides the default trace hander with a user-supplied version.
|
||||
*
|
||||
* Params:
|
||||
* h = The new trace handler. Set to null to use the default handler.
|
||||
*/
|
||||
extern (C) void rt_setTraceHandler( TraceHandler h )
|
||||
{
|
||||
traceHandler = h;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function will be called when an Exception is constructed. The
|
||||
* user-supplied trace handler will be called if one has been supplied,
|
||||
* otherwise no trace will be generated.
|
||||
*
|
||||
* Params:
|
||||
* ptr = A pointer to the location from which to generate the trace, or null
|
||||
* if the trace should be generated from within the trace handler
|
||||
* itself.
|
||||
*
|
||||
* Returns:
|
||||
* An object describing the current calling context or null if no handler is
|
||||
* supplied.
|
||||
*/
|
||||
Exception.TraceInfo traceContext( void* ptr = null )
|
||||
{
|
||||
if( traceHandler is null )
|
||||
return null;
|
||||
return traceHandler( ptr );
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ModuleInfo
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1094,11 +1146,20 @@ extern (C) void _moduleDtor()
|
||||
// Monitor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
alias Object.Monitor IMonitor;
|
||||
alias Object.Monitor IMonitor;
|
||||
alias void delegate(Object) DEvent;
|
||||
|
||||
// NOTE: The dtor callback feature is only supported for monitors that are not
|
||||
// supplied by the user. The assumption is that any object with a user-
|
||||
// supplied monitor may have special storage or lifetime requirements and
|
||||
// that as a result, storing references to local objects within Monitor
|
||||
// may not be safe or desirable. Thus, devt is only valid if impl is
|
||||
// null.
|
||||
struct Monitor
|
||||
{
|
||||
IMonitor impl;
|
||||
/* internal */
|
||||
DEvent[] devt;
|
||||
/* stuff */
|
||||
}
|
||||
|
||||
@@ -1126,6 +1187,7 @@ extern (C) void _d_monitordelete(Object h, bool det)
|
||||
IMonitor i = m.impl;
|
||||
if (i is null)
|
||||
{
|
||||
_d_monitor_devt(m, h);
|
||||
_d_monitor_destroy(h);
|
||||
setMonitor(h, null);
|
||||
return;
|
||||
@@ -1168,3 +1230,71 @@ extern (C) void _d_monitorexit(Object h)
|
||||
}
|
||||
i.unlock();
|
||||
}
|
||||
|
||||
extern (C) void _d_monitor_devt(Monitor* m, Object h)
|
||||
{
|
||||
if (m.devt.length)
|
||||
{
|
||||
DEvent[] devt;
|
||||
|
||||
synchronized (h)
|
||||
{
|
||||
devt = m.devt;
|
||||
m.devt = null;
|
||||
}
|
||||
foreach (v; devt)
|
||||
{
|
||||
if (v)
|
||||
v(h);
|
||||
}
|
||||
free(devt.ptr);
|
||||
}
|
||||
}
|
||||
|
||||
extern (C) void rt_attachDisposeEvent(Object h, DEvent e)
|
||||
{
|
||||
synchronized (h)
|
||||
{
|
||||
Monitor* m = getMonitor(h);
|
||||
assert(m.impl is null);
|
||||
|
||||
foreach (inout v; m.devt)
|
||||
{
|
||||
if (v is null || v == e)
|
||||
{
|
||||
v = e;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto len = m.devt.length + 4; // grow by 4 elements
|
||||
auto pos = m.devt.length; // insert position
|
||||
auto p = realloc(m.devt.ptr, DEvent.sizeof * len);
|
||||
if (!p)
|
||||
onOutOfMemoryError();
|
||||
m.devt = (cast(DEvent*)p)[0 .. len];
|
||||
m.devt[pos+1 .. len] = null;
|
||||
m.devt[pos] = e;
|
||||
}
|
||||
}
|
||||
|
||||
extern (C) void rt_detachDisposeEvent(Object h, DEvent e)
|
||||
{
|
||||
synchronized (h)
|
||||
{
|
||||
Monitor* m = getMonitor(h);
|
||||
assert(m.impl is null);
|
||||
|
||||
foreach (p, v; m.devt)
|
||||
{
|
||||
if (v == e)
|
||||
{
|
||||
memmove(&m.devt[p],
|
||||
&m.devt[p+1],
|
||||
(m.devt.length - p - 1) * DEvent.sizeof);
|
||||
m.devt[$ - 1] = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ module typeinfo.ti_AC;
|
||||
|
||||
// Object[]
|
||||
|
||||
class TypeInfo_AC : TypeInfo
|
||||
class TypeInfo_AC : TypeInfo_Array
|
||||
{
|
||||
hash_t getHash(void *p)
|
||||
{ Object[] s = *cast(Object[]*)p;
|
||||
|
||||
@@ -27,7 +27,7 @@ private import typeinfo.ti_cdouble;
|
||||
|
||||
// cdouble[]
|
||||
|
||||
class TypeInfo_Ar : TypeInfo
|
||||
class TypeInfo_Ar : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "cdouble[]"; }
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private import typeinfo.ti_cfloat;
|
||||
|
||||
// cfloat[]
|
||||
|
||||
class TypeInfo_Aq : TypeInfo
|
||||
class TypeInfo_Aq : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "cfloat[]"; }
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private import typeinfo.ti_creal;
|
||||
|
||||
// creal[]
|
||||
|
||||
class TypeInfo_Ac : TypeInfo
|
||||
class TypeInfo_Ac : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "creal[]"; }
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private import typeinfo.ti_double;
|
||||
|
||||
// double[]
|
||||
|
||||
class TypeInfo_Ad : TypeInfo
|
||||
class TypeInfo_Ad : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "double[]"; }
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private import typeinfo.ti_float;
|
||||
|
||||
// float[]
|
||||
|
||||
class TypeInfo_Af : TypeInfo
|
||||
class TypeInfo_Af : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "float[]"; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ private import util.string;
|
||||
|
||||
// byte[]
|
||||
|
||||
class TypeInfo_Ag : TypeInfo
|
||||
class TypeInfo_Ag : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "byte[]"; }
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ private import tango.stdc.string;
|
||||
|
||||
// int[]
|
||||
|
||||
class TypeInfo_Ai : TypeInfo
|
||||
class TypeInfo_Ai : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "int[]"; }
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ private import tango.stdc.string;
|
||||
|
||||
// long[]
|
||||
|
||||
class TypeInfo_Al : TypeInfo
|
||||
class TypeInfo_Al : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "long[]"; }
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private import typeinfo.ti_real;
|
||||
|
||||
// real[]
|
||||
|
||||
class TypeInfo_Ae : TypeInfo
|
||||
class TypeInfo_Ae : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "real[]"; }
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ private import tango.stdc.string;
|
||||
|
||||
// short[]
|
||||
|
||||
class TypeInfo_As : TypeInfo
|
||||
class TypeInfo_As : TypeInfo_Array
|
||||
{
|
||||
char[] toString() { return "short[]"; }
|
||||
|
||||
|
||||
@@ -69,8 +69,15 @@ extern (C) void gc_term()
|
||||
//
|
||||
// NOTE: Due to popular demand, this has been re-enabled. It still has
|
||||
// the problems mentioned above though, so I guess we'll see.
|
||||
version(LLVMDC)
|
||||
{
|
||||
// currently crashes a lot
|
||||
}
|
||||
else
|
||||
{
|
||||
_gc.fullCollectNoStack(); // not really a 'collect all' -- still scans
|
||||
// static data area, roots, and ranges.
|
||||
}
|
||||
_gc.Dtor();
|
||||
}
|
||||
|
||||
|
||||
@@ -193,8 +193,26 @@ class Layout(T)
|
||||
assert (formatStr, "null format specifier");
|
||||
assert (arguments.length < 64, "too many args in Layout.convert");
|
||||
|
||||
version (X86_64)
|
||||
version (LLVMDC)
|
||||
{
|
||||
static va_list get_va_arg(TypeInfo ti, ref va_list vp)
|
||||
{
|
||||
auto tisize = ti.tsize;
|
||||
size_t size = tisize > size_t.sizeof ? size_t.sizeof : tisize;
|
||||
va_list vptmp = cast(va_list)((cast(size_t)vp + size - 1) & ~(size - 1));
|
||||
vp = vptmp + tisize;
|
||||
return vptmp;
|
||||
}
|
||||
|
||||
Arg[64] arglist = void;
|
||||
foreach (i, arg; arguments)
|
||||
{
|
||||
arglist[i] = get_va_arg(arg, args);
|
||||
}
|
||||
}
|
||||
else version (X86_64)
|
||||
{
|
||||
// code for x86-64 GDC
|
||||
Arg[64] arglist = void;
|
||||
int[64] intargs = void;
|
||||
byte[64] byteargs = void;
|
||||
@@ -265,25 +283,9 @@ class Layout(T)
|
||||
}
|
||||
}
|
||||
}
|
||||
else version (LLVMDC)
|
||||
{
|
||||
static va_list get_va_arg(TypeInfo ti, ref va_list vp)
|
||||
{
|
||||
auto tisize = ti.tsize;
|
||||
size_t size = tisize > size_t.sizeof ? size_t.sizeof : tisize;
|
||||
va_list vptmp = cast(va_list)((cast(size_t)vp + size - 1) & ~(size - 1));
|
||||
vp = vptmp + tisize;
|
||||
return vptmp;
|
||||
}
|
||||
|
||||
Arg[64] arglist = void;
|
||||
foreach (i, arg; arguments)
|
||||
{
|
||||
arglist[i] = get_va_arg(arg, args);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// code for DMD & x86 GDC (may also work on other 32-bit targets)
|
||||
Arg[64] arglist = void;
|
||||
foreach (i, arg; arguments)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user