Mercurial > projects > ldc
comparison 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 |
comparison
equal
deleted
inserted
replaced
108:288fe1029e1f | 109:5ab8e92611f9 |
---|---|
149 return 0; | 149 return 0; |
150 } | 150 } |
151 | 151 |
152 void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val) | 152 void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val) |
153 { | 153 { |
154 Logger::println("HELLO"); | |
155 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n'; | 154 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n'; |
156 const llvm::Type* pt = ptr->getType()->getContainedType(0); | 155 const llvm::Type* pt = ptr->getType()->getContainedType(0); |
157 const llvm::Type* t = val->getType(); | 156 const llvm::Type* t = val->getType(); |
158 const llvm::Type* finalTy; | 157 const llvm::Type* finalTy; |
158 size_t aggrsz = 0; | |
159 if (size_t arrsz = checkRectArrayInit(pt, finalTy)) { | 159 if (size_t arrsz = checkRectArrayInit(pt, finalTy)) { |
160 assert(finalTy == t); | 160 assert(finalTy == t); |
161 llvm::Constant* c = isaConstant(dim); | 161 llvm::Constant* c = isaConstant(dim); |
162 assert(c); | 162 assert(c); |
163 dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz)); | 163 dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz)); |
164 ptr = gIR->ir->CreateBitCast(ptr, llvm::PointerType::get(finalTy), "tmp"); | 164 ptr = gIR->ir->CreateBitCast(ptr, llvm::PointerType::get(finalTy), "tmp"); |
165 } | 165 } |
166 else if (isaStruct(t)) { | 166 else if (isaStruct(t)) { |
167 assert(0); | 167 aggrsz = gTargetData->getTypeSize(t); |
168 llvm::Constant* c = isaConstant(val); | |
169 if (c && c->isNullValue()) { | |
170 llvm::Value* nbytes; | |
171 if (aggrsz == 1) | |
172 nbytes = dim; | |
173 else | |
174 nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(aggrsz), "tmp"); | |
175 DtoMemSetZero(ptr,nbytes); | |
176 return; | |
177 } | |
178 else { | |
179 ptr = gIR->ir->CreateBitCast(ptr, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp"); | |
180 } | |
168 } | 181 } |
169 else { | 182 else { |
170 assert(t == pt); | 183 assert(t == pt); |
171 } | 184 } |
185 | |
186 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n'; | |
172 | 187 |
173 std::vector<llvm::Value*> args; | 188 std::vector<llvm::Value*> args; |
174 args.push_back(ptr); | 189 args.push_back(ptr); |
175 args.push_back(dim); | 190 args.push_back(dim); |
176 args.push_back(val); | 191 args.push_back(val); |
177 | 192 |
178 const char* funcname = NULL; | 193 const char* funcname = NULL; |
179 | 194 |
180 if (isaPointer(t)) { | 195 if (aggrsz) { |
196 funcname = "_d_array_init_mem"; | |
197 args.push_back(DtoConstSize_t(aggrsz)); | |
198 } | |
199 else if (isaPointer(t)) { | |
181 funcname = "_d_array_init_pointer"; | 200 funcname = "_d_array_init_pointer"; |
182 | 201 |
183 const llvm::Type* dstty = llvm::PointerType::get(llvm::PointerType::get(llvm::Type::Int8Ty)); | 202 const llvm::Type* dstty = llvm::PointerType::get(llvm::PointerType::get(llvm::Type::Int8Ty)); |
184 if (args[0]->getType() != dstty) | 203 if (args[0]->getType() != dstty) |
185 args[0] = new llvm::BitCastInst(args[0],dstty,"tmp",gIR->scopebb()); | 204 args[0] = new llvm::BitCastInst(args[0],dstty,"tmp",gIR->scopebb()); |