mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 07:30:43 +03:00
Adapt to new array-append frontend lowerings
This commit is contained in:
parent
fa8371558a
commit
b81c2b5510
5 changed files with 4 additions and 78 deletions
|
@ -37,15 +37,6 @@ LLValue *DtoSlice(LLValue *ptr, LLValue *length, LLType *elemType) {
|
|||
elemType = i1ToI8(voidToI8(elemType));
|
||||
return DtoAggrPair(length, DtoBitCast(ptr, elemType->getPointerTo()));
|
||||
}
|
||||
|
||||
LLValue *DtoSlice(Expression *e) {
|
||||
DValue *dval = toElem(e);
|
||||
if (dval->type->toBasetype()->ty == TY::Tsarray) {
|
||||
// Convert static array to slice
|
||||
return DtoSlice(DtoLVal(dval), DtoArrayLen(dval), DtoType(dval->type->nextOf()));
|
||||
}
|
||||
return DtoRVal(dval);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -787,57 +778,6 @@ DSliceValue *DtoResizeDynArray(const Loc &loc, Type *arrayType, DValue *array,
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoCatAssignElement(const Loc &loc, DValue *array, Expression *exp) {
|
||||
IF_LOG Logger::println("DtoCatAssignElement");
|
||||
LOG_SCOPE;
|
||||
|
||||
assert(array);
|
||||
|
||||
Type *arrayType = array->type->toBasetype();
|
||||
|
||||
// Evaluate the expression to be appended first; it may affect the array.
|
||||
DValue *expVal = toElem(exp);
|
||||
|
||||
// The druntime function extends the slice in-place (length += 1, ptr
|
||||
// potentially moved to a new block).
|
||||
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendcTX");
|
||||
gIR->CreateCallOrInvoke(
|
||||
fn, DtoTypeInfoOf(loc, arrayType),
|
||||
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(1)),
|
||||
DtoConstSize_t(1), ".appendedArray");
|
||||
|
||||
// Assign to the new last element.
|
||||
LLValue *newLength = DtoArrayLen(array);
|
||||
LLValue *ptr = DtoArrayPtr(array);
|
||||
LLType *ptrty = i1ToI8(DtoType(array->type->nextOf()));
|
||||
LLValue *lastIndex =
|
||||
gIR->ir->CreateSub(newLength, DtoConstSize_t(1), ".lastIndex");
|
||||
LLValue *lastElemPtr = DtoGEP1(ptrty, ptr, lastIndex, ".lastElem");
|
||||
DLValue lastElem(arrayType->nextOf(), lastElemPtr);
|
||||
DtoAssign(loc, &lastElem, expVal, EXP::blit);
|
||||
callPostblit(loc, exp, lastElemPtr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DSliceValue *DtoCatAssignArray(const Loc &loc, DValue *arr, Expression *exp) {
|
||||
IF_LOG Logger::println("DtoCatAssignArray");
|
||||
LOG_SCOPE;
|
||||
Type *arrayType = arr->type;
|
||||
|
||||
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendT");
|
||||
// Call _d_arrayappendT(TypeInfo ti, byte[] *px, byte[] y)
|
||||
LLValue *newArray = gIR->CreateCallOrInvoke(
|
||||
fn, DtoTypeInfoOf(loc, arrayType),
|
||||
DtoBitCast(DtoLVal(arr), fn->getFunctionType()->getParamType(1)),
|
||||
DtoSlicePaint(DtoSlice(exp), fn->getFunctionType()->getParamType(2)),
|
||||
".appendedArray");
|
||||
|
||||
return getSlice(arrayType, newArray);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static LLValue *DtoSlicePtr(DValue *dval) {
|
||||
Loc loc;
|
||||
Type *vt = dval->type->toBasetype();
|
||||
|
@ -868,7 +808,7 @@ static LLValue *DtoSlicePtr(Expression *e) {
|
|||
|
||||
DSliceValue *DtoCatArrays(const Loc &loc, Type *arrayType, Expression *exp1,
|
||||
Expression *exp2) {
|
||||
IF_LOG Logger::println("DtoCatAssignArray");
|
||||
IF_LOG Logger::println("DtoCatArrays");
|
||||
LOG_SCOPE;
|
||||
|
||||
llvm::SmallVector<llvm::Value *, 3> args;
|
||||
|
|
|
@ -67,8 +67,6 @@ DSliceValue *DtoNewMulDimDynArray(const Loc &loc, Type *arrayType,
|
|||
DSliceValue *DtoResizeDynArray(const Loc &loc, Type *arrayType, DValue *array,
|
||||
llvm::Value *newdim);
|
||||
|
||||
void DtoCatAssignElement(const Loc &loc, DValue *arr, Expression *exp);
|
||||
DSliceValue *DtoCatAssignArray(const Loc &loc, DValue *arr, Expression *exp);
|
||||
DSliceValue *DtoCatArrays(const Loc &loc, Type *type, Expression *e1,
|
||||
Expression *e2);
|
||||
DSliceValue *DtoAppendDCharToString(const Loc &loc, DValue *arr,
|
||||
|
|
|
@ -590,14 +590,6 @@ static void buildRuntimeModule() {
|
|||
{"_d_arraysetlengthT", "_d_arraysetlengthiT"},
|
||||
{typeInfoTy, sizeTy, voidArrayPtrTy}, {STCconst, 0, 0});
|
||||
|
||||
// byte[] _d_arrayappendcTX(const TypeInfo ti, ref byte[] px, size_t n)
|
||||
createFwdDecl(LINK::c, voidArrayTy, {"_d_arrayappendcTX"},
|
||||
{typeInfoTy, voidArrayTy, sizeTy}, {STCconst, STCref, 0});
|
||||
|
||||
// void[] _d_arrayappendT(const TypeInfo ti, ref byte[] x, byte[] y)
|
||||
createFwdDecl(LINK::c, voidArrayTy, {"_d_arrayappendT"},
|
||||
{typeInfoTy, voidArrayTy, voidArrayTy}, {STCconst, STCref, 0});
|
||||
|
||||
// void[] _d_arrayappendcd(ref byte[] x, dchar c)
|
||||
// void[] _d_arrayappendwd(ref byte[] x, dchar c)
|
||||
createFwdDecl(LINK::c, voidArrayTy, {"_d_arrayappendcd", "_d_arrayappendwd"},
|
||||
|
|
|
@ -2174,13 +2174,9 @@ public:
|
|||
// append dchar to wchar[]
|
||||
DtoAppendDCharToUnicodeString(e->loc, result, e->e2);
|
||||
}
|
||||
} else if (e1type->equals(e2type)) {
|
||||
// append array
|
||||
DSliceValue *slice = DtoCatAssignArray(e->loc, result, e->e2);
|
||||
DtoStore(DtoRVal(slice), DtoLVal(result));
|
||||
} else {
|
||||
// append element
|
||||
DtoCatAssignElement(e->loc, result, e->e2);
|
||||
e->error("ICE: array append should have been lowered to `_d_arrayappend{T,cTX}`!");
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ void func()
|
|||
int[] quux;
|
||||
//CHECK: dcompute.d([[@LINE+1]]): Error: can only call functions from other `@compute` modules in `@compute` code
|
||||
quux.length = 1;
|
||||
//CHECK: dcompute.d([[@LINE+1]]): Error: cannot use operator `~=` in `@compute` code
|
||||
//CHECK: dcompute.d([[@LINE+1]]): Error: can only call functions from other `@compute` modules in `@compute` code
|
||||
quux ~= 42;
|
||||
//CHECK: dcompute.d([[@LINE+1]]): Error: cannot use operator `~` in `@compute` code
|
||||
cast(void) (quux ~ 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue