Mercurial > projects > ldc
comparison gen/arrays.cpp @ 287:00eb2c967c3a trunk
[svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice.
author | lindquist |
---|---|
date | Sat, 21 Jun 2008 05:03:42 +0200 |
parents | a3b7c19c866c |
children | 068cb3c60afb |
comparison
equal
deleted
inserted
replaced
286:a3b7c19c866c | 287:00eb2c967c3a |
---|---|
490 bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit(); | 490 bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit(); |
491 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarraymT" : "_d_newarraymiT" ); | 491 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarraymT" : "_d_newarraymiT" ); |
492 | 492 |
493 // build dims | 493 // build dims |
494 LLValue* dimsArg = new llvm::AllocaInst(DtoSize_t(), DtoConstUint(ndims), ".newdims", gIR->topallocapoint()); | 494 LLValue* dimsArg = new llvm::AllocaInst(DtoSize_t(), DtoConstUint(ndims), ".newdims", gIR->topallocapoint()); |
495 LLValue* firstDim = NULL; | |
495 for (size_t i=0; i<ndims; ++i) | 496 for (size_t i=0; i<ndims; ++i) |
496 { | 497 { |
497 LLValue* dim = dims[i]->getRVal(); | 498 LLValue* dim = dims[i]->getRVal(); |
499 if (!firstDim) firstDim = dim; | |
498 DtoStore(dim, DtoGEPi1(dimsArg, i)); | 500 DtoStore(dim, DtoGEPi1(dimsArg, i)); |
499 } | 501 } |
500 | 502 |
501 // call allocator | 503 // call allocator |
502 LLConstant* arrayLen = DtoConstSize_t(ndims); | 504 LLValue* newptr = gIR->ir->CreateCall3(fn, arrayTypeInfo, DtoConstSize_t(ndims), dimsArg, ".gc_mem"); |
503 LLValue* newptr = gIR->ir->CreateCall3(fn, arrayTypeInfo, arrayLen, dimsArg, ".gc_mem"); | |
504 | 505 |
505 // cast to wanted type | 506 // cast to wanted type |
506 const LLType* dstType = DtoType(arrayType)->getContainedType(1); | 507 const LLType* dstType = DtoType(arrayType)->getContainedType(1); |
507 if (newptr->getType() != dstType) | 508 if (newptr->getType() != dstType) |
508 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); | 509 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); |
514 DValue* e = dty->defaultInit()->toElem(gIR); | 515 DValue* e = dty->defaultInit()->toElem(gIR); |
515 DtoArrayInit(newptr,dim,e->getRVal()); | 516 DtoArrayInit(newptr,dim,e->getRVal()); |
516 } | 517 } |
517 #endif | 518 #endif |
518 | 519 |
519 return new DSliceValue(arrayType, arrayLen, newptr); | 520 assert(firstDim); |
521 return new DSliceValue(arrayType, firstDim, newptr); | |
520 } | 522 } |
521 | 523 |
522 ////////////////////////////////////////////////////////////////////////////////////////// | 524 ////////////////////////////////////////////////////////////////////////////////////////// |
523 DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim) | 525 DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim) |
524 { | 526 { |