Mercurial > projects > ldc
comparison gen/arrays.cpp @ 797:340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Fixed function literals in static initializers.
Changed alignment of delegates from 2*PTRSIZE to just PTRSIZE.
Changed errors to go to stderr instead of stdout.
Fairly major rewriting of struct/union/class handling, STILL A BIT BUGGY !!!
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sat, 29 Nov 2008 21:25:43 +0100 |
parents | 6e7a4c3b64d2 |
children | a70ddd449e7d |
comparison
equal
deleted
inserted
replaced
796:6e7a4c3b64d2 | 797:340acf1535d0 |
---|---|
206 DtoStore(dim, DtoGEPi(arr,0,0)); | 206 DtoStore(dim, DtoGEPi(arr,0,0)); |
207 DtoStore(ptr, DtoGEPi(arr,0,1)); | 207 DtoStore(ptr, DtoGEPi(arr,0,1)); |
208 } | 208 } |
209 | 209 |
210 ////////////////////////////////////////////////////////////////////////////////////////// | 210 ////////////////////////////////////////////////////////////////////////////////////////// |
211 | |
212 // FIXME: this looks like it could use a cleanup | |
213 | |
211 LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit) | 214 LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit) |
212 { | 215 { |
213 Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars()); | 216 Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars()); |
214 LOG_SCOPE; | 217 LOG_SCOPE; |
215 | 218 |
238 | 241 |
239 std::vector<LLConstant*> inits(tdim, NULL); | 242 std::vector<LLConstant*> inits(tdim, NULL); |
240 | 243 |
241 Type* arrnext = arrinittype->nextOf(); | 244 Type* arrnext = arrinittype->nextOf(); |
242 const LLType* elemty = DtoType(arrinittype->nextOf()); | 245 const LLType* elemty = DtoType(arrinittype->nextOf()); |
246 | |
247 // true if there is a mismatch with one of the initializers | |
248 bool mismatch = false; | |
243 | 249 |
244 assert(arrinit->index.dim == arrinit->value.dim); | 250 assert(arrinit->index.dim == arrinit->value.dim); |
245 for (unsigned i=0,j=0; i < tdim; ++i) | 251 for (unsigned i=0,j=0; i < tdim; ++i) |
246 { | 252 { |
247 Initializer* init = 0; | 253 Initializer* init = 0; |
290 | 296 |
291 if (!v) | 297 if (!v) |
292 v = DtoConstInitializer(arrinit->loc, t->nextOf(), init); | 298 v = DtoConstInitializer(arrinit->loc, t->nextOf(), init); |
293 assert(v); | 299 assert(v); |
294 | 300 |
301 // global arrays of unions might have type mismatch for each element | |
302 // if there is any mismatch at all, we need to use a struct instead :/ | |
303 if (v->getType() != elemty) | |
304 mismatch = true; | |
305 | |
295 inits[i] = v; | 306 inits[i] = v; |
296 if (Logger::enabled()) | 307 if (Logger::enabled()) |
297 Logger::cout() << "llval: " << *v << '\n'; | 308 Logger::cout() << "llval: " << *v << '\n'; |
298 } | 309 } |
299 | 310 |
300 Logger::println("building constant array"); | 311 Logger::println("building constant array"); |
312 | |
313 LLConstant* constarr; | |
301 const LLArrayType* arrty = LLArrayType::get(elemty,tdim); | 314 const LLArrayType* arrty = LLArrayType::get(elemty,tdim); |
302 LLConstant* constarr = LLConstantArray::get(arrty, inits); | 315 |
316 if (mismatch) | |
317 { | |
318 constarr = LLConstantStruct::get(inits); | |
319 } | |
320 else | |
321 { | |
322 constarr = LLConstantArray::get(arrty, inits); | |
323 } | |
324 | |
325 #if 0 | |
326 if (Logger::enabled()) | |
327 { | |
328 Logger::cout() << "array type: " << *arrty << '\n'; | |
329 size_t n = inits.size(); | |
330 for (size_t i=0; i<n; i++) | |
331 Logger::cout() << " init " << i << " = " << *inits[i] << '\n'; | |
332 } | |
333 #endif | |
303 | 334 |
304 if (arrinittype->ty == Tsarray) | 335 if (arrinittype->ty == Tsarray) |
305 return constarr; | 336 return constarr; |
306 else | 337 else |
307 assert(arrinittype->ty == Tarray); | 338 assert(arrinittype->ty == Tarray); |
308 | 339 |
309 LLGlobalVariable* gvar = new LLGlobalVariable(arrty,true,LLGlobalValue::InternalLinkage,constarr,".constarray",gIR->module); | 340 LLGlobalVariable* gvar = new LLGlobalVariable(constarr->getType(),true,LLGlobalValue::InternalLinkage,constarr,".constarray",gIR->module); |
310 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; | 341 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; |
342 | |
311 LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); | 343 LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); |
344 gep = llvm::ConstantExpr::getBitCast(gvar, getPtrToType(elemty)); | |
345 | |
312 return DtoConstSlice(DtoConstSize_t(tdim),gep); | 346 return DtoConstSlice(DtoConstSize_t(tdim),gep); |
313 } | 347 } |
314 | 348 |
315 ////////////////////////////////////////////////////////////////////////////////////////// | 349 ////////////////////////////////////////////////////////////////////////////////////////// |
316 static LLValue* get_slice_ptr(DSliceValue* e, LLValue*& sz) | 350 static LLValue* get_slice_ptr(DSliceValue* e, LLValue*& sz) |
790 // combine | 824 // combine |
791 LLValue* res = gIR->ir->CreateAnd(b1,b2,"tmp"); | 825 LLValue* res = gIR->ir->CreateAnd(b1,b2,"tmp"); |
792 | 826 |
793 // return result | 827 // return result |
794 return (op == TOKnotidentity) ? gIR->ir->CreateNot(res) : res; | 828 return (op == TOKnotidentity) ? gIR->ir->CreateNot(res) : res; |
795 } | |
796 | |
797 ////////////////////////////////////////////////////////////////////////////////////////// | |
798 LLConstant* DtoConstStaticArray(const LLType* t, LLConstant* c) | |
799 { | |
800 const LLArrayType* at = isaArray(t); | |
801 assert(at); | |
802 | |
803 if (isaArray(at->getElementType())) | |
804 { | |
805 c = DtoConstStaticArray(at->getElementType(), c); | |
806 } | |
807 else { | |
808 assert(at->getElementType() == c->getType()); | |
809 } | |
810 std::vector<LLConstant*> initvals; | |
811 initvals.resize(at->getNumElements(), c); | |
812 return llvm::ConstantArray::get(at, initvals); | |
813 } | 829 } |
814 | 830 |
815 ////////////////////////////////////////////////////////////////////////////////////////// | 831 ////////////////////////////////////////////////////////////////////////////////////////// |
816 LLValue* DtoArrayLen(DValue* v) | 832 LLValue* DtoArrayLen(DValue* v) |
817 { | 833 { |