Mercurial > projects > ldc
comparison gen/arrays.cpp @ 591:e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Adjust DtoNewDynArray to use DtoArrayInit for initialization of new arrays.
Make Type::tvoid->defaultInit() not error.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 14 Sep 2008 10:13:50 +0200 |
parents | 192b82878b78 |
children | 7042d912767e |
comparison
equal
deleted
inserted
replaced
590:1ecb43102d12 | 591:e6bcc4d9e5ff |
---|---|
397 LLConstant* values[2] = { dim, ptr }; | 397 LLConstant* values[2] = { dim, ptr }; |
398 return llvm::ConstantStruct::get(values, 2); | 398 return llvm::ConstantStruct::get(values, 2); |
399 } | 399 } |
400 | 400 |
401 ////////////////////////////////////////////////////////////////////////////////////////// | 401 ////////////////////////////////////////////////////////////////////////////////////////// |
402 DSliceValue* DtoNewDynArray(Type* arrayType, DValue* dim, bool defaultInit) | 402 DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool defaultInit) |
403 { | 403 { |
404 Logger::println("DtoNewDynArray : %s", arrayType->toChars()); | 404 Logger::println("DtoNewDynArray : %s", arrayType->toChars()); |
405 LOG_SCOPE; | 405 LOG_SCOPE; |
406 | 406 |
407 // typeinfo arg | 407 // typeinfo arg |
410 // dim arg | 410 // dim arg |
411 assert(DtoType(dim->getType()) == DtoSize_t()); | 411 assert(DtoType(dim->getType()) == DtoSize_t()); |
412 LLValue* arrayLen = dim->getRVal(); | 412 LLValue* arrayLen = dim->getRVal(); |
413 | 413 |
414 // get runtime function | 414 // get runtime function |
415 bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit(); | 415 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newarrayvT"); |
416 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarrayT" : "_d_newarrayiT" ); | |
417 | 416 |
418 // call allocator | 417 // call allocator |
419 LLValue* newptr = gIR->CreateCallOrInvoke2(fn, arrayTypeInfo, arrayLen, ".gc_mem")->get(); | 418 LLValue* newptr = gIR->CreateCallOrInvoke2(fn, arrayTypeInfo, arrayLen, ".gc_mem")->get(); |
420 | 419 |
421 // cast to wanted type | 420 // cast to wanted type |
423 if (newptr->getType() != dstType) | 422 if (newptr->getType() != dstType) |
424 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); | 423 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); |
425 | 424 |
426 Logger::cout() << "final ptr = " << *newptr << '\n'; | 425 Logger::cout() << "final ptr = " << *newptr << '\n'; |
427 | 426 |
428 #if 0 | 427 DSliceValue* ret = new DSliceValue(arrayType, arrayLen, newptr); |
428 | |
429 if (defaultInit) { | 429 if (defaultInit) { |
430 DValue* e = dty->defaultInit()->toElem(gIR); | 430 DValue* e = arrayType->nextOf()->defaultInit()->toElem(gIR); |
431 DtoArrayInit(newptr,dim,e->getRVal()); | 431 DtoArrayInit(loc, ret, e); |
432 } | 432 } |
433 #endif | 433 |
434 | 434 return ret; |
435 return new DSliceValue(arrayType, arrayLen, newptr); | 435 } |
436 } | 436 |
437 | 437 ////////////////////////////////////////////////////////////////////////////////////////// |
438 ////////////////////////////////////////////////////////////////////////////////////////// | 438 DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size_t ndims, bool defaultInit) |
439 DSliceValue* DtoNewMulDimDynArray(Type* arrayType, DValue** dims, size_t ndims, bool defaultInit) | |
440 { | 439 { |
441 Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars()); | 440 Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars()); |
442 LOG_SCOPE; | 441 LOG_SCOPE; |
443 | 442 |
444 // typeinfo arg | 443 // typeinfo arg |
472 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); | 471 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); |
473 | 472 |
474 Logger::cout() << "final ptr = " << *newptr << '\n'; | 473 Logger::cout() << "final ptr = " << *newptr << '\n'; |
475 | 474 |
476 #if 0 | 475 #if 0 |
476 // using this would reinit all arrays beyond the first level to [] | |
477 if (defaultInit) { | 477 if (defaultInit) { |
478 DValue* e = dty->defaultInit()->toElem(gIR); | 478 DValue* e = dty->defaultInit()->toElem(gIR); |
479 DtoArrayInit(newptr,dim,e->getRVal()); | 479 DtoArrayInit(newptr,dim,e->getRVal()); |
480 } | 480 } |
481 #endif | 481 #endif |
595 len1 = DtoArrayLen(e1); | 595 len1 = DtoArrayLen(e1); |
596 len2 = DtoArrayLen(e2); | 596 len2 = DtoArrayLen(e2); |
597 res = gIR->ir->CreateAdd(len1,len2,"tmp"); | 597 res = gIR->ir->CreateAdd(len1,len2,"tmp"); |
598 | 598 |
599 DValue* lenval = new DImValue(Type::tsize_t, res); | 599 DValue* lenval = new DImValue(Type::tsize_t, res); |
600 DSliceValue* slice = DtoNewDynArray(type, lenval, false); | 600 DSliceValue* slice = DtoNewDynArray(exp1->loc, type, lenval, false); |
601 LLValue* mem = slice->ptr; | 601 LLValue* mem = slice->ptr; |
602 | 602 |
603 src1 = DtoArrayPtr(e1); | 603 src1 = DtoArrayPtr(e1); |
604 src2 = DtoArrayPtr(e2); | 604 src2 = DtoArrayPtr(e2); |
605 | 605 |
635 { | 635 { |
636 len1 = DtoArrayLen(e2); | 636 len1 = DtoArrayLen(e2); |
637 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp"); | 637 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp"); |
638 | 638 |
639 DValue* lenval = new DImValue(Type::tsize_t, res); | 639 DValue* lenval = new DImValue(Type::tsize_t, res); |
640 DSliceValue* slice = DtoNewDynArray(type, lenval, false); | 640 DSliceValue* slice = DtoNewDynArray(exp1->loc, type, lenval, false); |
641 LLValue* mem = slice->ptr; | 641 LLValue* mem = slice->ptr; |
642 | 642 |
643 DVarValue* memval = new DVarValue(e1->getType(), mem); | 643 DVarValue* memval = new DVarValue(e1->getType(), mem); |
644 DtoAssign(exp1->loc, memval, e1); | 644 DtoAssign(exp1->loc, memval, e1); |
645 | 645 |
659 { | 659 { |
660 len1 = DtoArrayLen(e1); | 660 len1 = DtoArrayLen(e1); |
661 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp"); | 661 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp"); |
662 | 662 |
663 DValue* lenval = new DImValue(Type::tsize_t, res); | 663 DValue* lenval = new DImValue(Type::tsize_t, res); |
664 DSliceValue* slice = DtoNewDynArray(type, lenval, false); | 664 DSliceValue* slice = DtoNewDynArray(exp1->loc, type, lenval, false); |
665 LLValue* mem = slice->ptr; | 665 LLValue* mem = slice->ptr; |
666 | 666 |
667 src1 = DtoArrayPtr(e1); | 667 src1 = DtoArrayPtr(e1); |
668 | 668 |
669 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); | 669 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); |