diff --git a/gen/aa.cpp b/gen/aa.cpp index e0a8f471e7..2fd570e96d 100644 --- a/gen/aa.cpp +++ b/gen/aa.cpp @@ -14,7 +14,7 @@ // makes sure the key value lives in memory so it can be passed to the runtime functions without problems // returns the pointer -static LLValue* to_pkey(DValue* key) +static LLValue* to_pkey(Loc& loc, DValue* key) { Type* keytype = key->getType(); bool needmem = !DtoIsPassedByRef(keytype); @@ -38,7 +38,7 @@ static LLValue* to_pkey(DValue* key) else { LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint()); DVarValue* var = new DVarValue(keytype, tmp, true); - DtoAssign(var, key); + DtoAssign(loc, var, key); return tmp; } @@ -62,7 +62,7 @@ static LLValue* to_keyti(DValue* key) ///////////////////////////////////////////////////////////////////////////////////// -DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key) +DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key) { // call: // extern(C) void* _aaGet(AA* aa, TypeInfo keyti, void* pkey, size_t valuesize) @@ -83,7 +83,7 @@ DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key) LLValue* valsize = DtoConstSize_t(getABITypeSize(DtoType(type))); // pkey param - LLValue* pkey = to_pkey(key); + LLValue* pkey = to_pkey(loc, key); pkey = DtoBitCast(pkey, funcTy->getParamType(3)); // call runtime @@ -99,7 +99,7 @@ DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key) ///////////////////////////////////////////////////////////////////////////////////// -DValue* DtoAAIn(Type* type, DValue* aa, DValue* key) +DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key) { // call: // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey) @@ -121,7 +121,7 @@ DValue* DtoAAIn(Type* type, DValue* aa, DValue* key) keyti = DtoBitCast(keyti, funcTy->getParamType(1)); // pkey param - LLValue* pkey = to_pkey(key); + LLValue* pkey = to_pkey(loc, key); pkey = DtoBitCast(pkey, funcTy->getParamType(2)); // call runtime @@ -137,7 +137,7 @@ DValue* DtoAAIn(Type* type, DValue* aa, DValue* key) ///////////////////////////////////////////////////////////////////////////////////// -void DtoAARemove(DValue* aa, DValue* key) +void DtoAARemove(Loc& loc, DValue* aa, DValue* key) { // call: // extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey) @@ -159,7 +159,7 @@ void DtoAARemove(DValue* aa, DValue* key) keyti = DtoBitCast(keyti, funcTy->getParamType(1)); // pkey param - LLValue* pkey = to_pkey(key); + LLValue* pkey = to_pkey(loc, key); pkey = DtoBitCast(pkey, funcTy->getParamType(2)); // build arg vector diff --git a/gen/aa.h b/gen/aa.h index 482ff8e814..f9ababca5d 100644 --- a/gen/aa.h +++ b/gen/aa.h @@ -1,8 +1,8 @@ #ifndef LLVMDC_GEN_AA_H #define LLVMDC_GEN_AA_H -DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key); -DValue* DtoAAIn(Type* type, DValue* aa, DValue* key); -void DtoAARemove(DValue* aa, DValue* key); +DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key); +DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key); +void DtoAARemove(Loc& loc, DValue* aa, DValue* key); #endif // LLVMDC_GEN_AA_H diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 1310bfd71d..e71f84655e 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -106,7 +106,7 @@ void DtoArrayAssign(LLValue* dst, LLValue* src) ////////////////////////////////////////////////////////////////////////////////////////// -void DtoArrayInit(DValue* array, DValue* value) +void DtoArrayInit(Loc& loc, DValue* array, DValue* value) { Logger::println("DtoArrayInit"); LOG_SCOPE; @@ -120,7 +120,7 @@ void DtoArrayInit(DValue* array, DValue* value) { val = new llvm::AllocaInst(DtoType(value->getType()), ".tmpparam", gIR->topallocapoint()); DVarValue lval(value->getType(), val, true); - DtoAssign(&lval, value); + DtoAssign(loc, &lval, value); } else { @@ -531,7 +531,7 @@ DSliceValue* DtoCatAssignElement(DValue* array, Expression* exp) DValue* e = exp->toElem(gIR); if (!e->inPlace()) - DtoAssign(dptr, e); + DtoAssign(exp->loc, dptr, e); return slice; } @@ -633,7 +633,7 @@ DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2) LLValue* mem = slice->ptr; DVarValue* memval = new DVarValue(e1->getType(), mem, true); - DtoAssign(memval, e1); + DtoAssign(exp1->loc, memval, e1); src1 = DtoArrayPtr(e2); @@ -664,7 +664,7 @@ DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2) mem = gIR->ir->CreateGEP(mem,len1,"tmp"); DVarValue* memval = new DVarValue(e2->getType(), mem, true); - DtoAssign(memval, e2); + DtoAssign(exp1->loc, memval, e2); return slice; } diff --git a/gen/arrays.h b/gen/arrays.h index 2510dbfe45..11f1eddd1d 100644 --- a/gen/arrays.h +++ b/gen/arrays.h @@ -14,7 +14,7 @@ LLConstant* DtoConstStaticArray(const LLType* t, LLConstant* c); void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src); void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src); -void DtoArrayInit(DValue* array, DValue* value); +void DtoArrayInit(Loc& loc, DValue* array, DValue* value); void DtoArrayAssign(LLValue* l, LLValue* r); void DtoSetArray(LLValue* arr, LLValue* dim, LLValue* ptr); void DtoSetArrayToNull(LLValue* v); diff --git a/gen/complex.cpp b/gen/complex.cpp index 4717e193ee..627e8df255 100644 --- a/gen/complex.cpp +++ b/gen/complex.cpp @@ -101,12 +101,12 @@ LLValue* DtoImagPart(DValue* val) ////////////////////////////////////////////////////////////////////////////////////////// -DValue* DtoComplex(Type* to, DValue* val) +DValue* DtoComplex(Loc& loc, Type* to, DValue* val) { Type* t = DtoDType(val->getType()); if (val->isComplex() || t->iscomplex()) { - return DtoCastComplex(val, to); + return DtoCastComplex(loc, val, to); } const LLType* base = DtoComplexBaseType(to); @@ -126,13 +126,13 @@ DValue* DtoComplex(Type* to, DValue* val) } if (t->isimaginary()) { - return new DComplexValue(to, LLConstant::getNullValue(DtoType(baserety)), DtoCastFloat(val, baseimty)->getRVal()); + return new DComplexValue(to, LLConstant::getNullValue(DtoType(baserety)), DtoCastFloat(loc, val, baseimty)->getRVal()); } else if (t->isfloating()) { - return new DComplexValue(to, DtoCastFloat(val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); + return new DComplexValue(to, DtoCastFloat(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); } else if (t->isintegral()) { - return new DComplexValue(to, DtoCastInt(val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); + return new DComplexValue(to, DtoCastInt(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); } assert(0); } @@ -179,10 +179,10 @@ DValue* resolveLR(DValue* val, bool getlval) ////////////////////////////////////////////////////////////////////////////////////////// -DValue* DtoComplexAdd(Type* type, DValue* lhs, DValue* rhs) +DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs) { - lhs = DtoComplex(type, resolveLR(lhs, true)); - rhs = DtoComplex(type, resolveLR(rhs, false)); + lhs = DtoComplex(loc, type, resolveLR(lhs, true)); + rhs = DtoComplex(loc, type, resolveLR(rhs, false)); llvm::Value *a, *b, *c, *d, *re, *im; @@ -200,10 +200,10 @@ DValue* DtoComplexAdd(Type* type, DValue* lhs, DValue* rhs) ////////////////////////////////////////////////////////////////////////////////////////// -DValue* DtoComplexSub(Type* type, DValue* lhs, DValue* rhs) +DValue* DtoComplexSub(Loc& loc, Type* type, DValue* lhs, DValue* rhs) { - lhs = DtoComplex(type, resolveLR(lhs, true)); - rhs = DtoComplex(type, resolveLR(rhs, false)); + lhs = DtoComplex(loc, type, resolveLR(lhs, true)); + rhs = DtoComplex(loc, type, resolveLR(rhs, false)); llvm::Value *a, *b, *c, *d, *re, *im; @@ -221,10 +221,10 @@ DValue* DtoComplexSub(Type* type, DValue* lhs, DValue* rhs) ////////////////////////////////////////////////////////////////////////////////////////// -DValue* DtoComplexMul(Type* type, DValue* lhs, DValue* rhs) +DValue* DtoComplexMul(Loc& loc, Type* type, DValue* lhs, DValue* rhs) { - lhs = DtoComplex(type, resolveLR(lhs, true)); - rhs = DtoComplex(type, resolveLR(rhs, false)); + lhs = DtoComplex(loc, type, resolveLR(lhs, true)); + rhs = DtoComplex(loc, type, resolveLR(rhs, false)); llvm::Value *a, *b, *c, *d; @@ -248,10 +248,10 @@ DValue* DtoComplexMul(Type* type, DValue* lhs, DValue* rhs) ////////////////////////////////////////////////////////////////////////////////////////// -DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs) +DValue* DtoComplexDiv(Loc& loc, Type* type, DValue* lhs, DValue* rhs) { - lhs = DtoComplex(type, resolveLR(lhs, true)); - rhs = DtoComplex(type, resolveLR(rhs, false)); + lhs = DtoComplex(loc, type, resolveLR(lhs, true)); + rhs = DtoComplex(loc, type, resolveLR(rhs, false)); llvm::Value *a, *b, *c, *d; @@ -281,9 +281,9 @@ DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs) ////////////////////////////////////////////////////////////////////////////////////////// -DValue* DtoComplexNeg(Type* type, DValue* val) +DValue* DtoComplexNeg(Loc& loc, Type* type, DValue* val) { - val = DtoComplex(type, resolveLR(val, false)); + val = DtoComplex(loc, type, resolveLR(val, false)); llvm::Value *a, *b, *re, *im; @@ -299,12 +299,12 @@ DValue* DtoComplexNeg(Type* type, DValue* val) ////////////////////////////////////////////////////////////////////////////////////////// -LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs) +LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs) { Type* type = lhs->getType(); - lhs = DtoComplex(type, resolveLR(lhs, false)); - rhs = DtoComplex(type, resolveLR(rhs, false)); + lhs = DtoComplex(loc, type, resolveLR(lhs, false)); + rhs = DtoComplex(loc, type, resolveLR(rhs, false)); llvm::Value *a, *b, *c, *d; @@ -332,7 +332,7 @@ LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs) ////////////////////////////////////////////////////////////////////////////////////////// -DValue* DtoCastComplex(DValue* val, Type* _to) +DValue* DtoCastComplex(Loc& loc, DValue* val, Type* _to) { Type* to = DtoDType(_to); Type* vty = val->getType(); @@ -370,14 +370,14 @@ DValue* DtoCastComplex(DValue* val, Type* _to) return new DImValue(to, val->isComplex()->im); LLValue* v = val->getRVal(); DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp"))); - return DtoCastFloat(im, to); + return DtoCastFloat(loc, im, to); } else if (to->isfloating()) { if (val->isComplex()) return new DImValue(to, val->isComplex()->re); LLValue* v = val->getRVal(); DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp"))); - return DtoCastFloat(re, to); + return DtoCastFloat(loc, re, to); } else assert(0); diff --git a/gen/complex.h b/gen/complex.h index 0fd10a8e95..6fb1c58513 100644 --- a/gen/complex.h +++ b/gen/complex.h @@ -11,21 +11,21 @@ LLConstant* DtoComplexShuffleMask(unsigned a, unsigned b); LLValue* DtoRealPart(DValue* val); LLValue* DtoImagPart(DValue* val); -DValue* DtoComplex(Type* to, DValue* val); +DValue* DtoComplex(Loc& loc, Type* to, DValue* val); void DtoComplexAssign(LLValue* l, LLValue* r); void DtoComplexSet(LLValue* c, LLValue* re, LLValue* 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); -DValue* DtoComplexMul(Type* type, DValue* lhs, DValue* rhs); -DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs); -DValue* DtoComplexNeg(Type* type, DValue* val); +DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs); +DValue* DtoComplexSub(Loc& loc, Type* type, DValue* lhs, DValue* rhs); +DValue* DtoComplexMul(Loc& loc, Type* type, DValue* lhs, DValue* rhs); +DValue* DtoComplexDiv(Loc& loc, Type* type, DValue* lhs, DValue* rhs); +DValue* DtoComplexNeg(Loc& loc, Type* type, DValue* val); -LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs); +LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs); -DValue* DtoCastComplex(DValue* val, Type* to); +DValue* DtoCastComplex(Loc& loc, DValue* val, Type* to); #endif // LLVMDC_GEN_COMPLEX_H diff --git a/gen/functions.cpp b/gen/functions.cpp index 61a269b155..aa194f99ff 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -793,7 +793,7 @@ DValue* DtoArgument(Argument* fnarg, Expression* argexp) { LLValue* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint()); DVarValue* vv = new DVarValue(argexp->type, alloc, true); - DtoAssign(vv, arg); + DtoAssign(argexp->loc, vv, arg); arg = vv; } @@ -807,7 +807,7 @@ void DtoVariadicArgument(Expression* argexp, LLValue* dst) Logger::println("DtoVariadicArgument"); LOG_SCOPE; DVarValue vv(argexp->type, dst, true); - DtoAssign(&vv, argexp->toElem(gIR)); + DtoAssign(argexp->loc, &vv, argexp->toElem(gIR)); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 21a7f0e0c0..cb7c093515 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -512,7 +512,7 @@ LLValue* DtoNestedVariable(VarDeclaration* vd) // ASSIGNMENT HELPER (store this in that) ////////////////////////////////////////////////////////////////////////////////////////*/ -void DtoAssign(DValue* lhs, DValue* rhs) +void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs) { Logger::cout() << "DtoAssign(...);\n"; LOG_SCOPE; @@ -536,7 +536,7 @@ void DtoAssign(DValue* lhs, DValue* rhs) DtoArrayCopySlices(s, s2); } else if (t->next->toBasetype()->equals(t2)) { - DtoArrayInit(s, rhs); + DtoArrayInit(loc, s, rhs); } else { DtoArrayCopyToSlice(s, rhs); @@ -561,7 +561,7 @@ void DtoAssign(DValue* lhs, DValue* rhs) DtoStaticArrayCopy(lhs->getLVal(), rhs->getRVal()); } else { - DtoArrayInit(lhs, rhs); + DtoArrayInit(loc, lhs, rhs); } } else if (t->ty == Tdelegate) { @@ -596,7 +596,7 @@ void DtoAssign(DValue* lhs, DValue* rhs) LLValue* dst; if (DLRValue* lr = lhs->isLRValue()) { dst = lr->getLVal(); - rhs = DtoCastComplex(rhs, lr->getLType()); + rhs = DtoCastComplex(loc, rhs, lr->getLType()); } else { dst = lhs->getRVal(); @@ -616,10 +616,10 @@ void DtoAssign(DValue* lhs, DValue* rhs) // handle lvalue cast assignments if (DLRValue* lr = lhs->isLRValue()) { Logger::println("lvalue cast!"); - r = DtoCast(rhs, lr->getLType())->getRVal(); + r = DtoCast(loc, rhs, lr->getLType())->getRVal(); } else { - r = DtoCast(rhs, lhs->getType())->getRVal(); + r = DtoCast(loc, rhs, lhs->getType())->getRVal(); } Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n'; assert(r->getType() == l->getType()->getContainedType(0)); @@ -676,7 +676,7 @@ DValue* DtoNullValue(Type* type) // CASTING HELPERS ////////////////////////////////////////////////////////////////////////////////////////*/ -DValue* DtoCastInt(DValue* val, Type* _to) +DValue* DtoCastInt(Loc& loc, DValue* val, Type* _to) { const LLType* tolltype = DtoType(_to); @@ -709,7 +709,7 @@ DValue* DtoCastInt(DValue* val, Type* _to) } } else if (to->iscomplex()) { - return DtoComplex(to, val); + return DtoComplex(loc, to, val); } else if (to->isfloating()) { if (from->isunsigned()) { @@ -724,13 +724,14 @@ DValue* DtoCastInt(DValue* val, Type* _to) rval = gIR->ir->CreateIntToPtr(rval, tolltype, "tmp"); } else { - assert(0 && "bad int cast"); + error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), _to->toChars()); + fatal(); } return new DImValue(_to, rval); } -DValue* DtoCastPtr(DValue* val, Type* to) +DValue* DtoCastPtr(Loc& loc, DValue* val, Type* to) { const LLType* tolltype = DtoType(to); @@ -749,14 +750,14 @@ DValue* DtoCastPtr(DValue* val, Type* to) rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); } else { - Logger::println("invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); - assert(0); + error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); + fatal(); } return new DImValue(to, rval); } -DValue* DtoCastFloat(DValue* val, Type* to) +DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to) { if (val->getType() == to) return val; @@ -773,7 +774,7 @@ DValue* DtoCastFloat(DValue* val, Type* to) LLValue* rval; if (totype->iscomplex()) { - return DtoComplex(to, val); + return DtoComplex(loc, to, val); } else if (totype->isfloating()) { if ((fromtype->ty == Tfloat80 || fromtype->ty == Tfloat64) && (totype->ty == Tfloat80 || totype->ty == Tfloat64)) { @@ -789,7 +790,8 @@ DValue* DtoCastFloat(DValue* val, Type* to) rval = new llvm::FPTruncInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); } else { - assert(0 && "bad float cast"); + error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); + fatal(); } } else if (totype->isintegral()) { @@ -801,24 +803,25 @@ DValue* DtoCastFloat(DValue* val, Type* to) } } else { - assert(0 && "bad float cast"); + error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); + fatal(); } return new DImValue(to, rval); } -DValue* DtoCast(DValue* val, Type* to) +DValue* DtoCast(Loc& loc, DValue* val, Type* to) { Type* fromtype = DtoDType(val->getType()); Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars()); if (fromtype->isintegral()) { - return DtoCastInt(val, to); + return DtoCastInt(loc, val, to); } else if (fromtype->iscomplex()) { - return DtoCastComplex(val, to); + return DtoCastComplex(loc, val, to); } else if (fromtype->isfloating()) { - return DtoCastFloat(val, to); + return DtoCastFloat(loc, val, to); } else if (fromtype->ty == Tclass) { return DtoCastClass(val, to); @@ -827,10 +830,11 @@ DValue* DtoCast(DValue* val, Type* to) return DtoCastArray(val, to); } else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) { - return DtoCastPtr(val, to); + return DtoCastPtr(loc, val, to); } else { - assert(0); + error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); + fatal(); } } @@ -872,7 +876,7 @@ void DtoLazyStaticInit(bool istempl, LLValue* gvar, Initializer* init, Type* t) DValue* ie = DtoInitializer(init); if (!ie->inPlace()) { DValue* dst = new DVarValue(t, gvar, true); - DtoAssign(dst, ie); + DtoAssign(init->loc, dst, ie); } gIR->ir->CreateStore(DtoConstBool(true), gflag); gIR->ir->CreateBr(endinitbb); @@ -1359,7 +1363,7 @@ void findDefaultTarget() ////////////////////////////////////////////////////////////////////////////////////////// -LLValue* DtoBoolean(DValue* dval) +LLValue* DtoBoolean(Loc& loc, DValue* dval) { Type* dtype = dval->getType()->toBasetype(); TY ty = dtype->ty; @@ -1378,7 +1382,7 @@ LLValue* DtoBoolean(DValue* dval) // complex else if (dtype->iscomplex()) { - return DtoComplexEquals(TOKnotequal, dval, DtoNullValue(dtype)); + return DtoComplexEquals(loc, TOKnotequal, dval, DtoNullValue(dtype)); } // floating point else if (dtype->isfloating()) diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index 989d0bffce..92a64ec468 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -39,16 +39,16 @@ LLValue* DtoNestedContext(FuncDeclaration* func); LLValue* DtoNestedVariable(VarDeclaration* vd); // basic operations -void DtoAssign(DValue* lhs, DValue* rhs); +void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs); // create a null dvalue DValue* DtoNullValue(Type* t); // casts -DValue* DtoCastInt(DValue* val, Type* to); -DValue* DtoCastPtr(DValue* val, Type* to); -DValue* DtoCastFloat(DValue* val, Type* to); -DValue* DtoCast(DValue* val, Type* to); +DValue* DtoCastInt(Loc& loc, DValue* val, Type* to); +DValue* DtoCastPtr(Loc& loc, DValue* val, Type* to); +DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to); +DValue* DtoCast(Loc& loc, DValue* val, Type* to); // is template instance check bool DtoIsTemplateInstance(Dsymbol* s); @@ -102,6 +102,6 @@ void findDefaultTarget(); DValue* DtoCallDFunc(FuncDeclaration* fdecl, Array* arguments, TypeClass* type=0, LLValue* thismem=0); /// Converts any value to a boolean (llvm i1) -LLValue* DtoBoolean(DValue* dval); +LLValue* DtoBoolean(Loc& loc, DValue* dval); #endif diff --git a/gen/statements.cpp b/gen/statements.cpp index ba758bb9c9..21e68da675 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -67,7 +67,7 @@ void ReturnStatement::toIR(IRState* p) DValue* e = exp->toElem(p); if (!e->inPlace()) - DtoAssign(rvar, e); + DtoAssign(loc, rvar, e); DtoEnclosingHandlers(enclosinghandler, NULL); @@ -160,7 +160,7 @@ void IfStatement::toIR(IRState* p) if (cond_val->getType() != LLType::Int1Ty) { Logger::cout() << "if conditional: " << *cond_val << '\n'; - cond_val = DtoBoolean(cond_e); + cond_val = DtoBoolean(loc, cond_e); } LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb()); @@ -248,7 +248,7 @@ void WhileStatement::toIR(IRState* p) // create the condition DValue* cond_e = condition->toElem(p); - LLValue* cond_val = DtoBoolean(cond_e); + LLValue* cond_val = DtoBoolean(loc, cond_e); delete cond_e; // conditional branch @@ -299,7 +299,7 @@ void DoStatement::toIR(IRState* p) // create the condition DValue* cond_e = condition->toElem(p); - LLValue* cond_val = DtoBoolean(cond_e); + LLValue* cond_val = DtoBoolean(loc, cond_e); delete cond_e; // conditional branch @@ -341,7 +341,7 @@ void ForStatement::toIR(IRState* p) // create the condition DValue* cond_e = condition->toElem(p); - LLValue* cond_val = DtoBoolean(cond_e); + LLValue* cond_val = DtoBoolean(loc, cond_e); delete cond_e; // conditional branch @@ -677,7 +677,7 @@ static LLValue* call_string_switch_runtime(llvm::GlobalVariable* table, Expressi // give storage llval = new llvm::AllocaInst(DtoType(e->type), "tmp", gIR->topallocapoint()); DVarValue* vv = new DVarValue(e->type, llval, true); - DtoAssign(vv, val); + DtoAssign(e->loc, vv, val); } else { @@ -994,7 +994,7 @@ void ForeachStatement::toIR(IRState* p) if (!value->isRef() && !value->isOut()) { DValue* dst = new DVarValue(value->type, valvar, true); DValue* src = new DVarValue(value->type, value->ir.irLocal->value, true); - DtoAssign(dst, src); + DtoAssign(loc, dst, src); value->ir.irLocal->value = valvar; } diff --git a/gen/toir.cpp b/gen/toir.cpp index f2077740b0..13a26d7c94 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -568,7 +568,7 @@ DValue* AssignExp::toElem(IRState* p) DVarValue arrval(ale->e1->type, arr->getLVal(), true); DValue* newlen = e2->toElem(p); DSliceValue* slice = DtoResizeDynArray(arrval.getType(), &arrval, newlen); - DtoAssign(&arrval, slice); + DtoAssign(loc, &arrval, slice); return newlen; } @@ -576,7 +576,7 @@ DValue* AssignExp::toElem(IRState* p) DValue* l = e1->toElem(p); DValue* r = e2->toElem(p); - DtoAssign(l, r); + DtoAssign(loc, l, r); if (l->isSlice() || l->isComplex()) return l; @@ -630,12 +630,12 @@ DValue* AddExp::toElem(IRState* p) return new DImValue(type, v); } else if (t->iscomplex()) { - return DtoComplexAdd(type, l, r); + return DtoComplexAdd(loc, type, l, r); } assert(0); } else if (t->iscomplex()) { - return DtoComplexAdd(type, l, r); + return DtoComplexAdd(loc, type, l, r); } else { return DtoBinAdd(l,r); @@ -660,12 +660,12 @@ DValue* AddAssignExp::toElem(IRState* p) res = new DImValue(type, gep); } else if (t->iscomplex()) { - res = DtoComplexAdd(e1->type, l, r); + res = DtoComplexAdd(loc, e1->type, l, r); } else { res = DtoBinAdd(l,r); } - DtoAssign(l, res); + DtoAssign(loc, l, res); return res; } @@ -701,7 +701,7 @@ DValue* MinExp::toElem(IRState* p) return new DImValue(type, v); } else if (t->iscomplex()) { - return DtoComplexSub(type, l, r); + return DtoComplexSub(loc, type, l, r); } else { return DtoBinSub(l,r); @@ -731,13 +731,13 @@ DValue* MinAssignExp::toElem(IRState* p) } else if (t->iscomplex()) { Logger::println("complex"); - res = DtoComplexSub(type, l, r); + res = DtoComplexSub(loc, type, l, r); } else { Logger::println("basic"); res = DtoBinSub(l,r); } - DtoAssign(l, res); + DtoAssign(loc, l, res); return res; } @@ -753,7 +753,7 @@ DValue* MulExp::toElem(IRState* p) DValue* r = e2->toElem(p); if (type->iscomplex()) { - return DtoComplexMul(type, l, r); + return DtoComplexMul(loc, type, l, r); } return DtoBinMul(l,r); @@ -771,12 +771,12 @@ DValue* MulAssignExp::toElem(IRState* p) DValue* res; if (type->iscomplex()) { - res = DtoComplexMul(type, l, r); + res = DtoComplexMul(loc, type, l, r); } else { res = DtoBinMul(l,r); } - DtoAssign(l, res); + DtoAssign(loc, l, res); return res; } @@ -792,7 +792,7 @@ DValue* DivExp::toElem(IRState* p) DValue* r = e2->toElem(p); if (type->iscomplex()) { - return DtoComplexDiv(type, l, r); + return DtoComplexDiv(loc, type, l, r); } return DtoBinDiv(l, r); @@ -810,12 +810,12 @@ DValue* DivAssignExp::toElem(IRState* p) DValue* res; if (type->iscomplex()) { - res = DtoComplexDiv(type, l, r); + res = DtoComplexDiv(loc, type, l, r); } else { res = DtoBinDiv(l,r); } - DtoAssign(l, res); + DtoAssign(loc, l, res); return res; } @@ -844,7 +844,7 @@ DValue* ModAssignExp::toElem(IRState* p) DValue* r = e2->toElem(p); DValue* res = DtoBinRem(l, r); - DtoAssign(l, res); + DtoAssign(loc, l, res); return res; } @@ -933,7 +933,7 @@ DValue* CallExp::toElem(IRState* p) Expression* exp = (Expression*)arguments->data[0]; DValue* expv = exp->toElem(p); if (expv->getType()->toBasetype()->ty != Tint32) - expv = DtoCast(expv, Type::tint32); + expv = DtoCast(loc, expv, Type::tint32); LLValue* alloc = new llvm::AllocaInst(LLType::Int8Ty, expv->getRVal(), "alloca", p->scopebb()); // done return new DImValue(type, alloc); @@ -1208,7 +1208,7 @@ DValue* CastExp::toElem(IRState* p) LOG_SCOPE; DValue* u = e1->toElem(p); - DValue* v = DtoCast(u, to); + DValue* v = DtoCast(loc, u, to); // force d type to this->type v->getType() = type; @@ -1437,7 +1437,7 @@ DValue* IndexExp::toElem(IRState* p) arrptr = DtoGEP1(arrptr,r->getRVal()); } else if (e1type->ty == Taarray) { - return DtoAAIndex(type, l, r); + return DtoAAIndex(loc, type, l, r); } else { Logger::println("invalid index exp! e1type: %s", e1type->toChars()); @@ -1671,7 +1671,7 @@ DValue* EqualExp::toElem(IRState* p) else if (t->iscomplex()) { Logger::println("complex"); - eval = DtoComplexEquals(op, l, r); + eval = DtoComplexEquals(loc, op, l, r); } else if (t->isfloating()) { @@ -1837,7 +1837,7 @@ DValue* NewExp::toElem(IRState* p) // default initialize Expression* exp = newtype->defaultInit(loc); DValue* iv = exp->toElem(gIR); - DtoAssign(&tmpvar, iv); + DtoAssign(loc, &tmpvar, iv); // return as pointer-to return new DImValue(type, mem, false); @@ -1934,7 +1934,7 @@ DValue* AssertExp::toElem(IRState* p) llvm::BasicBlock* endbb = llvm::BasicBlock::Create("noassert", p->topfunc(), oldend); // test condition - LLValue* condval = DtoBoolean(cond); + LLValue* condval = DtoBoolean(loc, cond); // branch llvm::BranchInst::Create(endbb, assertbb, condval, p->scopebb()); @@ -1963,7 +1963,7 @@ DValue* NotExp::toElem(IRState* p) DValue* u = e1->toElem(p); - LLValue* b = DtoBoolean(u); + LLValue* b = DtoBoolean(loc, u); LLConstant* zero = DtoConstBool(false); b = p->ir->CreateICmpEQ(b,zero); @@ -1989,14 +1989,14 @@ DValue* AndAndExp::toElem(IRState* p) llvm::BasicBlock* andand = llvm::BasicBlock::Create("andand", gIR->topfunc(), oldend); llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend); - LLValue* ubool = DtoBoolean(u); + LLValue* ubool = DtoBoolean(loc, u); DtoStore(ubool,resval); llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb()); p->scope() = IRScope(andand, andandend); DValue* v = e2->toElem(p); - LLValue* vbool = DtoBoolean(v); + LLValue* vbool = DtoBoolean(loc, v); LLValue* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); DtoStore(uandvbool,resval); llvm::BranchInst::Create(andandend,p->scopebb()); @@ -2025,14 +2025,14 @@ DValue* OrOrExp::toElem(IRState* p) llvm::BasicBlock* oror = llvm::BasicBlock::Create("oror", gIR->topfunc(), oldend); llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend); - LLValue* ubool = DtoBoolean(u); + LLValue* ubool = DtoBoolean(loc, u); DtoStore(ubool,resval); llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb()); p->scope() = IRScope(oror, ororend); DValue* v = e2->toElem(p); - LLValue* vbool = DtoBoolean(v); + LLValue* vbool = DtoBoolean(loc, v); DtoStore(vbool,resval); llvm::BranchInst::Create(ororend,p->scopebb()); @@ -2289,17 +2289,17 @@ DValue* CondExp::toElem(IRState* p) llvm::BasicBlock* condend = llvm::BasicBlock::Create("condend", gIR->topfunc(), oldend); DValue* c = econd->toElem(p); - LLValue* cond_val = DtoBoolean(c); + LLValue* cond_val = DtoBoolean(loc, c); llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb()); p->scope() = IRScope(condtrue, condfalse); DValue* u = e1->toElem(p); - DtoAssign(dvv, u); + DtoAssign(loc, dvv, u); llvm::BranchInst::Create(condend,p->scopebb()); p->scope() = IRScope(condfalse, condend); DValue* v = e2->toElem(p); - DtoAssign(dvv, v); + DtoAssign(loc, dvv, v); llvm::BranchInst::Create(condend,p->scopebb()); p->scope() = IRScope(condend, oldend); @@ -2332,7 +2332,7 @@ DValue* NegExp::toElem(IRState* p) DValue* l = e1->toElem(p); if (type->iscomplex()) { - return DtoComplexNeg(type, l); + return DtoComplexNeg(loc, type, l); } LLValue* val = l->getRVal(); @@ -2390,11 +2390,11 @@ DValue* CatAssignExp::toElem(IRState* p) if (e2type == elemtype) { DSliceValue* slice = DtoCatAssignElement(l,e2); - DtoAssign(l, slice); + DtoAssign(loc, l, slice); } else if (e1type == e2type) { DSliceValue* slice = DtoCatAssignArray(l,e2); - DtoAssign(l, slice); + DtoAssign(loc, l, slice); } else assert(0 && "only one element at a time right now"); @@ -2481,7 +2481,7 @@ DValue* ArrayLiteralExp::toElem(IRState* p) DValue* e = expr->toElem(p); DImValue* im = e->isIm(); if (!im || !im->inPlace()) { - DtoAssign(vv, e); + DtoAssign(loc, vv, e); } } @@ -2566,7 +2566,7 @@ DValue* StructLiteralExp::toElem(IRState* p) DValue* ve = vx->toElem(p); if (!ve->inPlace()) - DtoAssign(darrptr, ve); + DtoAssign(loc, darrptr, ve); j++; } @@ -2606,7 +2606,7 @@ DValue* InExp::toElem(IRState* p) DValue* key = e1->toElem(p); DValue* aa = e2->toElem(p); - return DtoAAIn(type, aa, key); + return DtoAAIn(loc, type, aa, key); } DValue* RemoveExp::toElem(IRState* p) @@ -2617,7 +2617,7 @@ DValue* RemoveExp::toElem(IRState* p) DValue* aa = e1->toElem(p); DValue* key = e2->toElem(p); - DtoAARemove(aa, key); + DtoAARemove(loc, aa, key); return NULL; // does not produce anything useful } @@ -2652,11 +2652,11 @@ DValue* AssocArrayLiteralExp::toElem(IRState* p) // index DValue* key = ekey->toElem(p); - DValue* mem = DtoAAIndex(vtype, aa, key); + DValue* mem = DtoAAIndex(loc, vtype, aa, key); // store DValue* val = eval->toElem(p); - DtoAssign(mem, val); + DtoAssign(loc, mem, val); } return aa;