Mercurial > projects > ldc
diff gen/arrays.cpp @ 109:5ab8e92611f9 trunk
[svn r113] Added initial support for associative arrays (AAs).
Fixed some problems with the string runtime support functions.
Fixed initialization of array of structs.
Fixed slice assignment where LHS is slice but RHS is dynamic array.
Fixed problems with result of assignment expressions.
Fixed foreach problems with key type mismatches.
author | lindquist |
---|---|
date | Wed, 21 Nov 2007 04:13:15 +0100 |
parents | 288fe1029e1f |
children | fd7ad91fd713 |
line wrap: on
line diff
--- a/gen/arrays.cpp Tue Nov 20 05:29:20 2007 +0100 +++ b/gen/arrays.cpp Wed Nov 21 04:13:15 2007 +0100 @@ -151,11 +151,11 @@ void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val) { - Logger::println("HELLO"); 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; + size_t aggrsz = 0; if (size_t arrsz = checkRectArrayInit(pt, finalTy)) { assert(finalTy == t); llvm::Constant* c = isaConstant(dim); @@ -164,12 +164,27 @@ ptr = gIR->ir->CreateBitCast(ptr, llvm::PointerType::get(finalTy), "tmp"); } else if (isaStruct(t)) { - assert(0); + aggrsz = gTargetData->getTypeSize(t); + llvm::Constant* c = isaConstant(val); + if (c && c->isNullValue()) { + llvm::Value* nbytes; + if (aggrsz == 1) + nbytes = dim; + else + nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(aggrsz), "tmp"); + DtoMemSetZero(ptr,nbytes); + return; + } + else { + ptr = gIR->ir->CreateBitCast(ptr, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp"); + } } else { assert(t == pt); } + Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n'; + std::vector<llvm::Value*> args; args.push_back(ptr); args.push_back(dim); @@ -177,7 +192,11 @@ const char* funcname = NULL; - if (isaPointer(t)) { + if (aggrsz) { + funcname = "_d_array_init_mem"; + args.push_back(DtoConstSize_t(aggrsz)); + } + else if (isaPointer(t)) { funcname = "_d_array_init_pointer"; const llvm::Type* dstty = llvm::PointerType::get(llvm::PointerType::get(llvm::Type::Int8Ty));