Mercurial > projects > ldc
comparison gen/toir.c @ 81:3587401b6eeb trunk
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
Changed: Renamed all the LLVM_Dto... helper function to just Dto...
author | lindquist |
---|---|
date | Thu, 01 Nov 2007 17:27:18 +0100 |
parents | 2332006e1fa4 |
children | d8dd47ef3973 |
comparison
equal
deleted
inserted
replaced
80:7299ff502248 | 81:3587401b6eeb |
---|---|
57 assert(vd->llvmNestedIndex >= 0); | 57 assert(vd->llvmNestedIndex >= 0); |
58 } | 58 } |
59 // normal stack variable | 59 // normal stack variable |
60 else { | 60 else { |
61 // allocate storage on the stack | 61 // allocate storage on the stack |
62 const llvm::Type* lltype = LLVM_DtoType(vd->type); | 62 const llvm::Type* lltype = DtoType(vd->type); |
63 llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); | 63 llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); |
64 //allocainst->setAlignment(vd->type->alignsize()); // TODO | 64 //allocainst->setAlignment(vd->type->alignsize()); // TODO |
65 vd->llvmValue = allocainst; | 65 vd->llvmValue = allocainst; |
66 } | 66 } |
67 LLVM_DtoInitializer(vd->init); | 67 DtoInitializer(vd->init); |
68 } | 68 } |
69 } | 69 } |
70 // struct declaration | 70 // struct declaration |
71 else if (StructDeclaration* s = declaration->isStructDeclaration()) | 71 else if (StructDeclaration* s = declaration->isStructDeclaration()) |
72 { | 72 { |
134 // _dollar | 134 // _dollar |
135 else if (vd->ident == Id::dollar) | 135 else if (vd->ident == Id::dollar) |
136 { | 136 { |
137 Logger::println("Id::dollar"); | 137 Logger::println("Id::dollar"); |
138 assert(!p->arrays.empty()); | 138 assert(!p->arrays.empty()); |
139 llvm::Value* tmp = LLVM_DtoGEPi(p->arrays.back(),0,0,"tmp",p->scopebb()); | 139 llvm::Value* tmp = DtoGEPi(p->arrays.back(),0,0,"tmp",p->scopebb()); |
140 e->val = new llvm::LoadInst(tmp,"tmp",p->scopebb()); | 140 e->val = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
141 e->type = elem::VAL; | 141 e->type = elem::VAL; |
142 } | 142 } |
143 // typeinfo | 143 // typeinfo |
144 else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration()) | 144 else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration()) |
145 { | 145 { |
146 Logger::println("TypeInfoDeclaration"); | 146 Logger::println("TypeInfoDeclaration"); |
147 tid->toObjFile(); | 147 tid->toObjFile(); |
148 assert(tid->llvmValue); | 148 assert(tid->llvmValue); |
149 const llvm::Type* vartype = LLVM_DtoType(type); | 149 const llvm::Type* vartype = DtoType(type); |
150 if (tid->llvmValue->getType() != llvm::PointerType::get(vartype)) | 150 if (tid->llvmValue->getType() != llvm::PointerType::get(vartype)) |
151 e->mem = p->ir->CreateBitCast(tid->llvmValue, vartype, "tmp"); | 151 e->mem = p->ir->CreateBitCast(tid->llvmValue, vartype, "tmp"); |
152 else | 152 else |
153 e->mem = tid->llvmValue; | 153 e->mem = tid->llvmValue; |
154 e->type = elem::VAR; | 154 e->type = elem::VAR; |
155 } | 155 } |
156 // nested variable | 156 // nested variable |
157 else if (vd->nestedref) { | 157 else if (vd->nestedref) { |
158 Logger::println("nested variable"); | 158 Logger::println("nested variable"); |
159 e->mem = LLVM_DtoNestedVariable(vd); | 159 e->mem = DtoNestedVariable(vd); |
160 e->type = elem::VAR; | 160 e->type = elem::VAR; |
161 e->vardecl = vd; | 161 e->vardecl = vd; |
162 } | 162 } |
163 // function parameter | 163 // function parameter |
164 else if (vd->isParameter()) { | 164 else if (vd->isParameter()) { |
171 if (vd->isRef() || vd->isOut()) { | 171 if (vd->isRef() || vd->isOut()) { |
172 e->mem = vd->llvmValue; | 172 e->mem = vd->llvmValue; |
173 e->type = elem::VAR; | 173 e->type = elem::VAR; |
174 } | 174 } |
175 else { | 175 else { |
176 if (LLVM_DtoIsPassedByRef(vd->type)) { | 176 if (DtoIsPassedByRef(vd->type)) { |
177 e->mem = vd->llvmValue; | 177 e->mem = vd->llvmValue; |
178 e->type = elem::VAR; | 178 e->type = elem::VAR; |
179 } | 179 } |
180 else { | 180 else { |
181 if (llvm::isa<llvm::Argument>(vd->llvmValue)) { | 181 if (llvm::isa<llvm::Argument>(vd->llvmValue)) { |
214 e->funcdecl = fdecl; | 214 e->funcdecl = fdecl; |
215 } | 215 } |
216 else if (SymbolDeclaration* sdecl = var->isSymbolDeclaration()) | 216 else if (SymbolDeclaration* sdecl = var->isSymbolDeclaration()) |
217 { | 217 { |
218 // this seems to be the static initialiser for structs | 218 // this seems to be the static initialiser for structs |
219 Type* sdecltype = LLVM_DtoDType(sdecl->type); | 219 Type* sdecltype = DtoDType(sdecl->type); |
220 Logger::print("Sym: type=%s\n", sdecltype->toChars()); | 220 Logger::print("Sym: type=%s\n", sdecltype->toChars()); |
221 assert(sdecltype->ty == Tstruct); | 221 assert(sdecltype->ty == Tstruct); |
222 TypeStruct* ts = (TypeStruct*)sdecltype; | 222 TypeStruct* ts = (TypeStruct*)sdecltype; |
223 e->mem = ts->llvmInit; | 223 e->mem = ts->llvmInit; |
224 assert(e->mem); | 224 assert(e->mem); |
239 Logger::print("VarExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | 239 Logger::print("VarExp::toConstElem: %s | %s\n", toChars(), type->toChars()); |
240 LOG_SCOPE; | 240 LOG_SCOPE; |
241 if (SymbolDeclaration* sdecl = var->isSymbolDeclaration()) | 241 if (SymbolDeclaration* sdecl = var->isSymbolDeclaration()) |
242 { | 242 { |
243 // this seems to be the static initialiser for structs | 243 // this seems to be the static initialiser for structs |
244 Type* sdecltype = LLVM_DtoDType(sdecl->type); | 244 Type* sdecltype = DtoDType(sdecl->type); |
245 Logger::print("Sym: type=%s\n", sdecltype->toChars()); | 245 Logger::print("Sym: type=%s\n", sdecltype->toChars()); |
246 assert(sdecltype->ty == Tstruct); | 246 assert(sdecltype->ty == Tstruct); |
247 TypeStruct* ts = (TypeStruct*)sdecltype; | 247 TypeStruct* ts = (TypeStruct*)sdecltype; |
248 assert(ts->sym->llvmInitZ); | 248 assert(ts->sym->llvmInitZ); |
249 return ts->sym->llvmInitZ; | 249 return ts->sym->llvmInitZ; |
268 | 268 |
269 llvm::Constant* IntegerExp::toConstElem(IRState* p) | 269 llvm::Constant* IntegerExp::toConstElem(IRState* p) |
270 { | 270 { |
271 Logger::print("IntegerExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | 271 Logger::print("IntegerExp::toConstElem: %s | %s\n", toChars(), type->toChars()); |
272 LOG_SCOPE; | 272 LOG_SCOPE; |
273 const llvm::Type* t = LLVM_DtoType(type); | 273 const llvm::Type* t = DtoType(type); |
274 if (llvm::isa<llvm::PointerType>(t)) { | 274 if (llvm::isa<llvm::PointerType>(t)) { |
275 llvm::Constant* i = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)value,false); | 275 llvm::Constant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false); |
276 return llvm::ConstantExpr::getIntToPtr(i, t); | 276 return llvm::ConstantExpr::getIntToPtr(i, t); |
277 } | 277 } |
278 else if (llvm::isa<llvm::IntegerType>(t)) { | 278 else if (llvm::isa<llvm::IntegerType>(t)) { |
279 return llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned()); | 279 return llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned()); |
280 } | 280 } |
298 | 298 |
299 llvm::Constant* RealExp::toConstElem(IRState* p) | 299 llvm::Constant* RealExp::toConstElem(IRState* p) |
300 { | 300 { |
301 Logger::print("RealExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | 301 Logger::print("RealExp::toConstElem: %s | %s\n", toChars(), type->toChars()); |
302 LOG_SCOPE; | 302 LOG_SCOPE; |
303 Type* t = LLVM_DtoDType(type); | 303 Type* t = DtoDType(type); |
304 const llvm::Type* fty = LLVM_DtoType(t); | 304 const llvm::Type* fty = DtoType(t); |
305 if (t->ty == Tfloat32 || t->ty == Timaginary32) | 305 if (t->ty == Tfloat32 || t->ty == Timaginary32) |
306 return llvm::ConstantFP::get(fty,float(value)); | 306 return llvm::ConstantFP::get(fty,float(value)); |
307 else if (t->ty == Tfloat64 || t->ty == Timaginary64 || t->ty == Tfloat80 || t->ty == Timaginary80) | 307 else if (t->ty == Tfloat64 || t->ty == Timaginary64 || t->ty == Tfloat80 || t->ty == Timaginary80) |
308 return llvm::ConstantFP::get(fty,double(value)); | 308 return llvm::ConstantFP::get(fty,double(value)); |
309 assert(0); | 309 assert(0); |
327 | 327 |
328 llvm::Constant* NullExp::toConstElem(IRState* p) | 328 llvm::Constant* NullExp::toConstElem(IRState* p) |
329 { | 329 { |
330 Logger::print("NullExp::toConstElem(type=%s): %s\n", type->toChars(),toChars()); | 330 Logger::print("NullExp::toConstElem(type=%s): %s\n", type->toChars(),toChars()); |
331 LOG_SCOPE; | 331 LOG_SCOPE; |
332 const llvm::Type* t = LLVM_DtoType(type); | 332 const llvm::Type* t = DtoType(type); |
333 if (type->ty == Tarray) { | 333 if (type->ty == Tarray) { |
334 assert(llvm::isa<llvm::StructType>(t)); | 334 assert(llvm::isa<llvm::StructType>(t)); |
335 return llvm::ConstantAggregateZero::get(t); | 335 return llvm::ConstantAggregateZero::get(t); |
336 } | 336 } |
337 else { | 337 else { |
346 elem* StringExp::toElem(IRState* p) | 346 elem* StringExp::toElem(IRState* p) |
347 { | 347 { |
348 Logger::print("StringExp::toElem: %s | %s\n", toChars(), type->toChars()); | 348 Logger::print("StringExp::toElem: %s | %s\n", toChars(), type->toChars()); |
349 LOG_SCOPE; | 349 LOG_SCOPE; |
350 | 350 |
351 Type* dtype = LLVM_DtoDType(type); | 351 Type* dtype = DtoDType(type); |
352 | 352 |
353 assert(dtype->next->ty == Tchar && "Only char is supported"); | 353 assert(dtype->next->ty == Tchar && "Only char is supported"); |
354 assert(sz == 1); | 354 assert(sz == 1); |
355 | 355 |
356 const llvm::Type* ct = LLVM_DtoType(dtype->next); | 356 const llvm::Type* ct = DtoType(dtype->next); |
357 //printf("ct = %s\n", type->next->toChars()); | 357 //printf("ct = %s\n", type->next->toChars()); |
358 const llvm::ArrayType* at = llvm::ArrayType::get(ct,len+1); | 358 const llvm::ArrayType* at = llvm::ArrayType::get(ct,len+1); |
359 | 359 |
360 uint8_t* str = (uint8_t*)string; | 360 uint8_t* str = (uint8_t*)string; |
361 std::string cont((char*)str, len); | 361 std::string cont((char*)str, len); |
370 llvm::Constant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); | 370 llvm::Constant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); |
371 | 371 |
372 elem* e = new elem; | 372 elem* e = new elem; |
373 | 373 |
374 if (dtype->ty == Tarray) { | 374 if (dtype->ty == Tarray) { |
375 llvm::Constant* clen = llvm::ConstantInt::get(LLVM_DtoSize_t(),len,false); | 375 llvm::Constant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); |
376 if (!p->topexp() || p->topexp()->e2 != this) { | 376 if (!p->topexp() || p->topexp()->e2 != this) { |
377 llvm::Value* tmpmem = new llvm::AllocaInst(LLVM_DtoType(dtype),"tmp",p->topallocapoint()); | 377 llvm::Value* tmpmem = new llvm::AllocaInst(DtoType(dtype),"tmp",p->topallocapoint()); |
378 LLVM_DtoSetArray(tmpmem, clen, arrptr); | 378 DtoSetArray(tmpmem, clen, arrptr); |
379 e->mem = tmpmem; | 379 e->mem = tmpmem; |
380 } | 380 } |
381 else if (p->topexp()->e2 == this) { | 381 else if (p->topexp()->e2 == this) { |
382 llvm::Value* arr = p->topexp()->v; | 382 llvm::Value* arr = p->topexp()->v; |
383 assert(arr); | 383 assert(arr); |
384 LLVM_DtoSetArray(arr, clen, arrptr); | 384 DtoSetArray(arr, clen, arrptr); |
385 e->inplace = true; | 385 e->inplace = true; |
386 } | 386 } |
387 else | 387 else |
388 assert(0); | 388 assert(0); |
389 } | 389 } |
411 LOG_SCOPE; | 411 LOG_SCOPE; |
412 | 412 |
413 uint8_t* str = (uint8_t*)string; | 413 uint8_t* str = (uint8_t*)string; |
414 std::string cont((char*)str, len); | 414 std::string cont((char*)str, len); |
415 | 415 |
416 Type* t = LLVM_DtoDType(type); | 416 Type* t = DtoDType(type); |
417 | 417 |
418 if (t->ty == Tsarray) { | 418 if (t->ty == Tsarray) { |
419 return llvm::ConstantArray::get(cont,false); | 419 return llvm::ConstantArray::get(cont,false); |
420 } | 420 } |
421 llvm::Constant* _init = llvm::ConstantArray::get(cont,true); | 421 llvm::Constant* _init = llvm::ConstantArray::get(cont,true); |
430 if (t->ty == Tpointer) { | 430 if (t->ty == Tpointer) { |
431 return arrptr; | 431 return arrptr; |
432 } | 432 } |
433 | 433 |
434 if (t->ty == Tarray) { | 434 if (t->ty == Tarray) { |
435 llvm::Constant* clen = llvm::ConstantInt::get(LLVM_DtoSize_t(),len,false); | 435 llvm::Constant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); |
436 return LLVM_DtoConstSlice(clen, arrptr); | 436 return DtoConstSlice(clen, arrptr); |
437 } | 437 } |
438 | 438 |
439 assert(0); | 439 assert(0); |
440 return NULL; | 440 return NULL; |
441 } | 441 } |
455 | 455 |
456 p->exps.pop_back(); | 456 p->exps.pop_back(); |
457 | 457 |
458 if (l->type == elem::ARRAYLEN) | 458 if (l->type == elem::ARRAYLEN) |
459 { | 459 { |
460 LLVM_DtoResizeDynArray(l->mem, r->getValue()); | 460 DtoResizeDynArray(l->mem, r->getValue()); |
461 delete r; | 461 delete r; |
462 delete l; | 462 delete l; |
463 return 0; | 463 return 0; |
464 } | 464 } |
465 | 465 |
466 // handle function argument - allocate temp storage for it :/ annoying | 466 // handle function argument - allocate temp storage for it :/ annoying |
467 if (l->mem == 0) { | 467 if (l->mem == 0) { |
468 assert(l->val); | 468 assert(l->val); |
469 if (llvm::isa<llvm::Argument>(l->val)) | 469 if (llvm::isa<llvm::Argument>(l->val)) |
470 LLVM_DtoGiveArgumentStorage(l); | 470 DtoGiveArgumentStorage(l); |
471 else { | 471 else { |
472 Logger::cout() << "here it comes... " << *l->val << '\n'; | 472 Logger::cout() << "here it comes... " << *l->val << '\n'; |
473 assert(0); | 473 assert(0); |
474 } | 474 } |
475 } | 475 } |
476 //e->val = l->store(r->getValue()); | 476 //e->val = l->store(r->getValue()); |
477 | 477 |
478 Type* e1type = LLVM_DtoDType(e1->type); | 478 Type* e1type = DtoDType(e1->type); |
479 Type* e2type = LLVM_DtoDType(e2->type); | 479 Type* e2type = DtoDType(e2->type); |
480 TY e1ty = e1type->ty; | 480 TY e1ty = e1type->ty; |
481 TY e2ty = e2type->ty; | 481 TY e2ty = e2type->ty; |
482 | 482 |
483 elem* e = new elem; | 483 elem* e = new elem; |
484 e->type = elem::VAR; | 484 e->type = elem::VAR; |
488 e->mem = l->mem; | 488 e->mem = l->mem; |
489 // struct + struct | 489 // struct + struct |
490 if (e2ty == Tstruct) { | 490 if (e2ty == Tstruct) { |
491 // struct literals do the assignment themselvs (in place) | 491 // struct literals do the assignment themselvs (in place) |
492 if (!r->inplace) { | 492 if (!r->inplace) { |
493 LLVM_DtoStructCopy(l->mem,r->getValue()); | 493 DtoStructCopy(l->mem,r->getValue()); |
494 } | 494 } |
495 else { | 495 else { |
496 e->inplace = true; | 496 e->inplace = true; |
497 } | 497 } |
498 } | 498 } |
499 // struct + const int | 499 // struct + const int |
500 else if (e2type->isintegral()){ | 500 else if (e2type->isintegral()){ |
501 IntegerExp* iexp = (IntegerExp*)e2; | 501 IntegerExp* iexp = (IntegerExp*)e2; |
502 assert(iexp->value == 0 && "Only integral struct initializer allowed is zero"); | 502 assert(iexp->value == 0 && "Only integral struct initializer allowed is zero"); |
503 LLVM_DtoStructZeroInit(l->mem); | 503 DtoStructZeroInit(l->mem); |
504 } | 504 } |
505 // :x | 505 // :x |
506 else | 506 else |
507 assert(0 && "struct = unknown"); | 507 assert(0 && "struct = unknown"); |
508 } | 508 } |
509 else if (e1ty == Tsarray) { | 509 else if (e1ty == Tsarray) { |
510 assert(0 && "static array not supported"); | 510 assert(0 && "static array not supported"); |
511 } | 511 } |
512 else if (e1ty == Tarray) { | 512 else if (e1ty == Tarray) { |
513 if (e2type->isscalar() || e2type->ty == Tclass){ | 513 if (e2type->isscalar() || e2type->ty == Tclass){ |
514 LLVM_DtoArrayInit(l->mem, r->getValue()); | 514 DtoArrayInit(l->mem, r->getValue()); |
515 } | 515 } |
516 else if (e2ty == Tarray) { | 516 else if (e2ty == Tarray) { |
517 //new llvm::StoreInst(r->val,l->val,p->scopebb()); | 517 //new llvm::StoreInst(r->val,l->val,p->scopebb()); |
518 if (r->type == elem::NUL) { | 518 if (r->type == elem::NUL) { |
519 llvm::Constant* c = llvm::cast<llvm::Constant>(r->val); | 519 llvm::Constant* c = llvm::cast<llvm::Constant>(r->val); |
520 assert(c->isNullValue()); | 520 assert(c->isNullValue()); |
521 LLVM_DtoNullArray(l->mem); | 521 DtoNullArray(l->mem); |
522 e->mem = l->mem; | 522 e->mem = l->mem; |
523 } | 523 } |
524 else if (r->type == elem::SLICE) { | 524 else if (r->type == elem::SLICE) { |
525 if (l->type == elem::SLICE) { | 525 if (l->type == elem::SLICE) { |
526 LLVM_DtoArrayCopy(l,r); | 526 DtoArrayCopy(l,r); |
527 e->type = elem::SLICE; | 527 e->type = elem::SLICE; |
528 e->mem = l->mem; | 528 e->mem = l->mem; |
529 e->arg = l->arg; | 529 e->arg = l->arg; |
530 } | 530 } |
531 else { | 531 else { |
532 LLVM_DtoSetArray(l->mem,r->arg,r->mem); | 532 DtoSetArray(l->mem,r->arg,r->mem); |
533 e->mem = l->mem; | 533 e->mem = l->mem; |
534 } | 534 } |
535 } | 535 } |
536 else { | 536 else { |
537 // new expressions write directly to the array reference | 537 // new expressions write directly to the array reference |
538 // so do string literals | 538 // so do string literals |
539 e->mem = l->mem; | 539 e->mem = l->mem; |
540 if (!r->inplace) { | 540 if (!r->inplace) { |
541 assert(r->mem); | 541 assert(r->mem); |
542 LLVM_DtoArrayAssign(l->mem, r->mem); | 542 DtoArrayAssign(l->mem, r->mem); |
543 } | 543 } |
544 else { | 544 else { |
545 e->inplace = true; | 545 e->inplace = true; |
546 } | 546 } |
547 } | 547 } |
585 Logger::println("Assigning to delegate"); | 585 Logger::println("Assigning to delegate"); |
586 if (e2ty == Tdelegate) { | 586 if (e2ty == Tdelegate) { |
587 if (r->type == elem::NUL) { | 587 if (r->type == elem::NUL) { |
588 llvm::Constant* c = llvm::cast<llvm::Constant>(r->val); | 588 llvm::Constant* c = llvm::cast<llvm::Constant>(r->val); |
589 if (c->isNullValue()) { | 589 if (c->isNullValue()) { |
590 LLVM_DtoNullDelegate(l->mem); | 590 DtoNullDelegate(l->mem); |
591 e->mem = l->mem; | 591 e->mem = l->mem; |
592 } | 592 } |
593 else | 593 else |
594 assert(0); | 594 assert(0); |
595 } | 595 } |
597 // do nothing | 597 // do nothing |
598 e->inplace = true; | 598 e->inplace = true; |
599 e->mem = l->mem; | 599 e->mem = l->mem; |
600 } | 600 } |
601 else { | 601 else { |
602 LLVM_DtoDelegateCopy(l->mem, r->getValue()); | 602 DtoDelegateCopy(l->mem, r->getValue()); |
603 e->mem = l->mem; | 603 e->mem = l->mem; |
604 } | 604 } |
605 } | 605 } |
606 else | 606 else |
607 assert(0); | 607 assert(0); |
627 LOG_SCOPE; | 627 LOG_SCOPE; |
628 elem* e = new elem; | 628 elem* e = new elem; |
629 elem* l = e1->toElem(p); | 629 elem* l = e1->toElem(p); |
630 elem* r = e2->toElem(p); | 630 elem* r = e2->toElem(p); |
631 | 631 |
632 Type* t = LLVM_DtoDType(type); | 632 Type* t = DtoDType(type); |
633 Type* e1type = LLVM_DtoDType(e1->type); | 633 Type* e1type = DtoDType(e1->type); |
634 Type* e2type = LLVM_DtoDType(e2->type); | 634 Type* e2type = DtoDType(e2->type); |
635 | 635 |
636 if (e1type != e2type) { | 636 if (e1type != e2type) { |
637 if (e1type->ty == Tpointer && e1type->next->ty == Tstruct) { | 637 if (e1type->ty == Tpointer && e1type->next->ty == Tstruct) { |
638 //assert(l->field); | 638 //assert(l->field); |
639 assert(r->type == elem::CONST); | 639 assert(r->type == elem::CONST); |
640 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val); | 640 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val); |
641 | 641 |
642 TypeStruct* ts = (TypeStruct*)e1type->next; | 642 TypeStruct* ts = (TypeStruct*)e1type->next; |
643 std::vector<unsigned> offsets; | 643 std::vector<unsigned> offsets; |
644 e->mem = LLVM_DtoIndexStruct(l->getValue(), ts->sym, t->next, cofs->getZExtValue(), offsets); | 644 e->mem = DtoIndexStruct(l->getValue(), ts->sym, t->next, cofs->getZExtValue(), offsets); |
645 e->type = elem::VAR; | 645 e->type = elem::VAR; |
646 e->field = true; | 646 e->field = true; |
647 } | 647 } |
648 else if (e1->type->ty == Tpointer) { | 648 else if (e1->type->ty == Tpointer) { |
649 e->val = new llvm::GetElementPtrInst(l->getValue(), r->getValue(), "tmp", p->scopebb()); | 649 e->val = new llvm::GetElementPtrInst(l->getValue(), r->getValue(), "tmp", p->scopebb()); |
670 LOG_SCOPE; | 670 LOG_SCOPE; |
671 | 671 |
672 elem* l = e1->toElem(p); | 672 elem* l = e1->toElem(p); |
673 elem* r = e2->toElem(p); | 673 elem* r = e2->toElem(p); |
674 | 674 |
675 Type* e1type = LLVM_DtoDType(e1->type); | 675 Type* e1type = DtoDType(e1->type); |
676 | 676 |
677 elem* e = new elem; | 677 elem* e = new elem; |
678 llvm::Value* val = 0; | 678 llvm::Value* val = 0; |
679 if (e1type->ty == Tpointer) { | 679 if (e1type->ty == Tpointer) { |
680 val = e->mem = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); | 680 val = e->mem = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
684 } | 684 } |
685 | 685 |
686 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | 686 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; |
687 if (llvm::isa<llvm::PointerType>(storeVal->getType()) && storeVal->getType()->getContainedType(0) != tmp->getType()) | 687 if (llvm::isa<llvm::PointerType>(storeVal->getType()) && storeVal->getType()->getContainedType(0) != tmp->getType()) |
688 { | 688 { |
689 tmp = LLVM_DtoPointedType(storeVal, tmp); | 689 tmp = DtoPointedType(storeVal, tmp); |
690 }*/ | 690 }*/ |
691 | 691 |
692 if (l->mem == 0) | 692 if (l->mem == 0) |
693 LLVM_DtoGiveArgumentStorage(l); | 693 DtoGiveArgumentStorage(l); |
694 new llvm::StoreInst(val,l->mem,p->scopebb()); | 694 new llvm::StoreInst(val,l->mem,p->scopebb()); |
695 e->type = elem::VAR; | 695 e->type = elem::VAR; |
696 | 696 |
697 delete l; | 697 delete l; |
698 delete r; | 698 delete r; |
709 elem* l = e1->toElem(p); | 709 elem* l = e1->toElem(p); |
710 elem* r = e2->toElem(p); | 710 elem* r = e2->toElem(p); |
711 | 711 |
712 llvm::Value* left = l->getValue(); | 712 llvm::Value* left = l->getValue(); |
713 if (llvm::isa<llvm::PointerType>(left->getType())) | 713 if (llvm::isa<llvm::PointerType>(left->getType())) |
714 left = new llvm::PtrToIntInst(left,LLVM_DtoSize_t(),"tmp",p->scopebb()); | 714 left = new llvm::PtrToIntInst(left,DtoSize_t(),"tmp",p->scopebb()); |
715 | 715 |
716 llvm::Value* right = r->getValue(); | 716 llvm::Value* right = r->getValue(); |
717 if (llvm::isa<llvm::PointerType>(right->getType())) | 717 if (llvm::isa<llvm::PointerType>(right->getType())) |
718 right = new llvm::PtrToIntInst(right,LLVM_DtoSize_t(),"tmp",p->scopebb()); | 718 right = new llvm::PtrToIntInst(right,DtoSize_t(),"tmp",p->scopebb()); |
719 | 719 |
720 e->val = llvm::BinaryOperator::createSub(left,right,"tmp",p->scopebb()); | 720 e->val = llvm::BinaryOperator::createSub(left,right,"tmp",p->scopebb()); |
721 e->type = elem::VAL; | 721 e->type = elem::VAL; |
722 | 722 |
723 const llvm::Type* totype = LLVM_DtoType(type); | 723 const llvm::Type* totype = DtoType(type); |
724 if (e->val->getType() != totype) { | 724 if (e->val->getType() != totype) { |
725 assert(0); | 725 assert(0); |
726 assert(llvm::isa<llvm::PointerType>(e->val->getType())); | 726 assert(llvm::isa<llvm::PointerType>(e->val->getType())); |
727 assert(llvm::isa<llvm::IntegerType>(totype)); | 727 assert(llvm::isa<llvm::IntegerType>(totype)); |
728 e->val = new llvm::IntToPtrInst(e->val,totype,"tmp",p->scopebb()); | 728 e->val = new llvm::IntToPtrInst(e->val,totype,"tmp",p->scopebb()); |
741 LOG_SCOPE; | 741 LOG_SCOPE; |
742 | 742 |
743 elem* l = e1->toElem(p); | 743 elem* l = e1->toElem(p); |
744 elem* r = e2->toElem(p); | 744 elem* r = e2->toElem(p); |
745 | 745 |
746 Type* e1type = LLVM_DtoDType(e1->type); | 746 Type* e1type = DtoDType(e1->type); |
747 | 747 |
748 llvm::Value* tmp = 0; | 748 llvm::Value* tmp = 0; |
749 if (e1type->ty == Tpointer) { | 749 if (e1type->ty == Tpointer) { |
750 tmp = r->getValue(); | 750 tmp = r->getValue(); |
751 llvm::Value* zero = llvm::ConstantInt::get(tmp->getType(),0,false); | 751 llvm::Value* zero = llvm::ConstantInt::get(tmp->getType(),0,false); |
757 } | 757 } |
758 | 758 |
759 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | 759 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; |
760 if (storeVal->getType()->getContainedType(0) != tmp->getType()) | 760 if (storeVal->getType()->getContainedType(0) != tmp->getType()) |
761 { | 761 { |
762 tmp = LLVM_DtoPointedType(storeVal, tmp); | 762 tmp = DtoPointedType(storeVal, tmp); |
763 }*/ | 763 }*/ |
764 | 764 |
765 if (l->mem == 0) | 765 if (l->mem == 0) |
766 LLVM_DtoGiveArgumentStorage(l); | 766 DtoGiveArgumentStorage(l); |
767 new llvm::StoreInst(tmp, l->mem, p->scopebb()); | 767 new llvm::StoreInst(tmp, l->mem, p->scopebb()); |
768 | 768 |
769 delete l; | 769 delete l; |
770 delete r; | 770 delete r; |
771 | 771 |
809 llvm::Value* tmp = llvm::BinaryOperator::createMul(vl,vr,"tmp",p->scopebb()); | 809 llvm::Value* tmp = llvm::BinaryOperator::createMul(vl,vr,"tmp",p->scopebb()); |
810 | 810 |
811 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | 811 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; |
812 if (storeVal->getType()->getContainedType(0) != tmp->getType()) | 812 if (storeVal->getType()->getContainedType(0) != tmp->getType()) |
813 { | 813 { |
814 tmp = LLVM_DtoPointedType(storeVal, tmp); | 814 tmp = DtoPointedType(storeVal, tmp); |
815 }*/ | 815 }*/ |
816 | 816 |
817 if (l->mem == 0) | 817 if (l->mem == 0) |
818 LLVM_DtoGiveArgumentStorage(l); | 818 DtoGiveArgumentStorage(l); |
819 new llvm::StoreInst(tmp,l->mem,p->scopebb()); | 819 new llvm::StoreInst(tmp,l->mem,p->scopebb()); |
820 | 820 |
821 delete l; | 821 delete l; |
822 delete r; | 822 delete r; |
823 | 823 |
835 LOG_SCOPE; | 835 LOG_SCOPE; |
836 elem* e = new elem; | 836 elem* e = new elem; |
837 elem* l = e1->toElem(p); | 837 elem* l = e1->toElem(p); |
838 elem* r = e2->toElem(p); | 838 elem* r = e2->toElem(p); |
839 | 839 |
840 Type* t = LLVM_DtoDType(type); | 840 Type* t = DtoDType(type); |
841 | 841 |
842 if (t->isunsigned()) | 842 if (t->isunsigned()) |
843 e->val = llvm::BinaryOperator::createUDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); | 843 e->val = llvm::BinaryOperator::createUDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
844 else if (t->isintegral()) | 844 else if (t->isintegral()) |
845 e->val = llvm::BinaryOperator::createSDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); | 845 e->val = llvm::BinaryOperator::createSDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
861 LOG_SCOPE; | 861 LOG_SCOPE; |
862 | 862 |
863 elem* l = e1->toElem(p); | 863 elem* l = e1->toElem(p); |
864 elem* r = e2->toElem(p); | 864 elem* r = e2->toElem(p); |
865 | 865 |
866 Type* t = LLVM_DtoDType(type); | 866 Type* t = DtoDType(type); |
867 | 867 |
868 llvm::Value* tmp; | 868 llvm::Value* tmp; |
869 if (t->isunsigned()) | 869 if (t->isunsigned()) |
870 tmp = llvm::BinaryOperator::createUDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); | 870 tmp = llvm::BinaryOperator::createUDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
871 else if (t->isintegral()) | 871 else if (t->isintegral()) |
876 assert(0); | 876 assert(0); |
877 | 877 |
878 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | 878 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; |
879 if (storeVal->getType()->getContainedType(0) != tmp->getType()) | 879 if (storeVal->getType()->getContainedType(0) != tmp->getType()) |
880 { | 880 { |
881 tmp = LLVM_DtoPointedType(storeVal, tmp); | 881 tmp = DtoPointedType(storeVal, tmp); |
882 }*/ | 882 }*/ |
883 | 883 |
884 if (l->mem == 0) | 884 if (l->mem == 0) |
885 LLVM_DtoGiveArgumentStorage(l); | 885 DtoGiveArgumentStorage(l); |
886 new llvm::StoreInst(tmp,l->mem,p->scopebb()); | 886 new llvm::StoreInst(tmp,l->mem,p->scopebb()); |
887 | 887 |
888 delete l; | 888 delete l; |
889 delete r; | 889 delete r; |
890 | 890 |
902 LOG_SCOPE; | 902 LOG_SCOPE; |
903 elem* e = new elem; | 903 elem* e = new elem; |
904 elem* l = e1->toElem(p); | 904 elem* l = e1->toElem(p); |
905 elem* r = e2->toElem(p); | 905 elem* r = e2->toElem(p); |
906 | 906 |
907 Type* t = LLVM_DtoDType(type); | 907 Type* t = DtoDType(type); |
908 | 908 |
909 if (t->isunsigned()) | 909 if (t->isunsigned()) |
910 e->val = llvm::BinaryOperator::createURem(l->getValue(),r->getValue(),"tmp",p->scopebb()); | 910 e->val = llvm::BinaryOperator::createURem(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
911 else if (t->isintegral()) | 911 else if (t->isintegral()) |
912 e->val = llvm::BinaryOperator::createSRem(l->getValue(),r->getValue(),"tmp",p->scopebb()); | 912 e->val = llvm::BinaryOperator::createSRem(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
928 LOG_SCOPE; | 928 LOG_SCOPE; |
929 | 929 |
930 elem* l = e1->toElem(p); | 930 elem* l = e1->toElem(p); |
931 elem* r = e2->toElem(p); | 931 elem* r = e2->toElem(p); |
932 | 932 |
933 Type* t = LLVM_DtoDType(type); | 933 Type* t = DtoDType(type); |
934 | 934 |
935 llvm::Value* tmp; | 935 llvm::Value* tmp; |
936 if (t->isunsigned()) | 936 if (t->isunsigned()) |
937 tmp = llvm::BinaryOperator::createURem(l->getValue(),r->getValue(),"tmp",p->scopebb()); | 937 tmp = llvm::BinaryOperator::createURem(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
938 else if (t->isintegral()) | 938 else if (t->isintegral()) |
943 assert(0); | 943 assert(0); |
944 | 944 |
945 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | 945 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; |
946 if (storeVal->getType()->getContainedType(0) != tmp->getType()) | 946 if (storeVal->getType()->getContainedType(0) != tmp->getType()) |
947 { | 947 { |
948 tmp = LLVM_DtoPointedType(storeVal, tmp); | 948 tmp = DtoPointedType(storeVal, tmp); |
949 }*/ | 949 }*/ |
950 | 950 |
951 if (l->mem == 0) | 951 if (l->mem == 0) |
952 LLVM_DtoGiveArgumentStorage(l); | 952 DtoGiveArgumentStorage(l); |
953 new llvm::StoreInst(tmp,l->mem,p->scopebb()); | 953 new llvm::StoreInst(tmp,l->mem,p->scopebb()); |
954 | 954 |
955 delete l; | 955 delete l; |
956 delete r; | 956 delete r; |
957 | 957 |
970 | 970 |
971 elem* e = new elem; | 971 elem* e = new elem; |
972 elem* fn = e1->toElem(p); | 972 elem* fn = e1->toElem(p); |
973 | 973 |
974 TypeFunction* tf = 0; | 974 TypeFunction* tf = 0; |
975 Type* e1type = LLVM_DtoDType(e1->type); | 975 Type* e1type = DtoDType(e1->type); |
976 | 976 |
977 bool delegateCall = false; | 977 bool delegateCall = false; |
978 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false); | 978 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false); |
979 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty,1,false); | 979 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty,1,false); |
980 LINK dlink = LINKdefault; | 980 LINK dlink = LINKdefault; |
1023 Argument* fnarg = Argument::getNth(tf->parameters, 0); | 1023 Argument* fnarg = Argument::getNth(tf->parameters, 0); |
1024 Expression* exp = (Expression*)arguments->data[0]; | 1024 Expression* exp = (Expression*)arguments->data[0]; |
1025 elem* expelem = exp->toElem(p); | 1025 elem* expelem = exp->toElem(p); |
1026 assert(expelem->mem); | 1026 assert(expelem->mem); |
1027 elem* e = new elem; | 1027 elem* e = new elem; |
1028 Type* t = LLVM_DtoDType(type); | 1028 Type* t = DtoDType(type); |
1029 const llvm::Type* llt = LLVM_DtoType(type); | 1029 const llvm::Type* llt = DtoType(type); |
1030 if (LLVM_DtoIsPassedByRef(t)) | 1030 if (DtoIsPassedByRef(t)) |
1031 llt = llvm::PointerType::get(llt); | 1031 llt = llvm::PointerType::get(llt); |
1032 e->type = elem::VAL; | 1032 e->type = elem::VAL; |
1033 e->val = p->ir->CreateVAArg(expelem->mem,llt,"tmp"); | 1033 e->val = p->ir->CreateVAArg(expelem->mem,llt,"tmp"); |
1034 delete expelem; | 1034 delete expelem; |
1035 return e; | 1035 return e; |
1067 //Logger::cout() << "function pointer type:\n" << *funcval << '\n'; | 1067 //Logger::cout() << "function pointer type:\n" << *funcval << '\n'; |
1068 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0)); | 1068 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0)); |
1069 } | 1069 } |
1070 // struct pointer - delegate | 1070 // struct pointer - delegate |
1071 else if (llvm::isa<llvm::StructType>(funcval->getType()->getContainedType(0))) { | 1071 else if (llvm::isa<llvm::StructType>(funcval->getType()->getContainedType(0))) { |
1072 funcval = LLVM_DtoGEP(funcval,zero,one,"tmp",p->scopebb()); | 1072 funcval = DtoGEP(funcval,zero,one,"tmp",p->scopebb()); |
1073 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); | 1073 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
1074 const llvm::Type* ty = funcval->getType()->getContainedType(0); | 1074 const llvm::Type* ty = funcval->getType()->getContainedType(0); |
1075 llfnty = llvm::cast<llvm::FunctionType>(ty); | 1075 llfnty = llvm::cast<llvm::FunctionType>(ty); |
1076 } | 1076 } |
1077 // unknown | 1077 // unknown |
1095 if (retinptr) { | 1095 if (retinptr) { |
1096 if (topexp && topexp->e2 == this) { | 1096 if (topexp && topexp->e2 == this) { |
1097 assert(topexp->v); | 1097 assert(topexp->v); |
1098 assert(llvm::isa<llvm::StructType>(topexp->v->getType()->getContainedType(0))); | 1098 assert(llvm::isa<llvm::StructType>(topexp->v->getType()->getContainedType(0))); |
1099 llargs[j] = topexp->v; | 1099 llargs[j] = topexp->v; |
1100 if (LLVM_DtoIsPassedByRef(tf->next)) { | 1100 if (DtoIsPassedByRef(tf->next)) { |
1101 e->inplace = true; | 1101 e->inplace = true; |
1102 } | 1102 } |
1103 else | 1103 else |
1104 assert(0); | 1104 assert(0); |
1105 } | 1105 } |
1128 ++argiter; | 1128 ++argiter; |
1129 } | 1129 } |
1130 // delegate context arguments | 1130 // delegate context arguments |
1131 else if (delegateCall) { | 1131 else if (delegateCall) { |
1132 Logger::println("Delegate Call"); | 1132 Logger::println("Delegate Call"); |
1133 llvm::Value* contextptr = LLVM_DtoGEP(fn->mem,zero,zero,"tmp",p->scopebb()); | 1133 llvm::Value* contextptr = DtoGEP(fn->mem,zero,zero,"tmp",p->scopebb()); |
1134 llargs[j] = new llvm::LoadInst(contextptr,"tmp",p->scopebb()); | 1134 llargs[j] = new llvm::LoadInst(contextptr,"tmp",p->scopebb()); |
1135 ++j; | 1135 ++j; |
1136 ++argiter; | 1136 ++argiter; |
1137 } | 1137 } |
1138 // nested call | 1138 // nested call |
1169 std::vector<llvm::Value*> vtypeinfos; | 1169 std::vector<llvm::Value*> vtypeinfos; |
1170 | 1170 |
1171 for (int i=0; i<arguments->dim; i++) { | 1171 for (int i=0; i<arguments->dim; i++) { |
1172 Argument* fnarg = Argument::getNth(tf->parameters, i); | 1172 Argument* fnarg = Argument::getNth(tf->parameters, i); |
1173 Expression* argexp = (Expression*)arguments->data[i]; | 1173 Expression* argexp = (Expression*)arguments->data[i]; |
1174 vvalues.push_back(LLVM_DtoArgument(NULL, fnarg, argexp)); | 1174 vvalues.push_back(DtoArgument(NULL, fnarg, argexp)); |
1175 vtypes.push_back(vvalues.back()->getType()); | 1175 vtypes.push_back(vvalues.back()->getType()); |
1176 | 1176 |
1177 TypeInfoDeclaration* tidecl = argexp->type->getTypeInfoDeclaration(); | 1177 TypeInfoDeclaration* tidecl = argexp->type->getTypeInfoDeclaration(); |
1178 tidecl->toObjFile(); | 1178 tidecl->toObjFile(); |
1179 assert(tidecl->llvmValue); | 1179 assert(tidecl->llvmValue); |
1181 } | 1181 } |
1182 | 1182 |
1183 const llvm::StructType* vtype = llvm::StructType::get(vtypes); | 1183 const llvm::StructType* vtype = llvm::StructType::get(vtypes); |
1184 llvm::Value* mem = new llvm::AllocaInst(vtype,"_argptr_storage",p->topallocapoint()); | 1184 llvm::Value* mem = new llvm::AllocaInst(vtype,"_argptr_storage",p->topallocapoint()); |
1185 for (unsigned i=0; i<vtype->getNumElements(); ++i) | 1185 for (unsigned i=0; i<vtype->getNumElements(); ++i) |
1186 p->ir->CreateStore(vvalues[i], LLVM_DtoGEPi(mem,0,i,"tmp")); | 1186 p->ir->CreateStore(vvalues[i], DtoGEPi(mem,0,i,"tmp")); |
1187 | 1187 |
1188 //llvm::Constant* typeinfoparam = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(llfnty->getParamType(j))); | 1188 //llvm::Constant* typeinfoparam = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(llfnty->getParamType(j))); |
1189 assert(Type::typeinfo->llvmInitZ); | 1189 assert(Type::typeinfo->llvmInitZ); |
1190 const llvm::Type* typeinfotype = llvm::PointerType::get(Type::typeinfo->llvmInitZ->getType()); | 1190 const llvm::Type* typeinfotype = llvm::PointerType::get(Type::typeinfo->llvmInitZ->getType()); |
1191 Logger::cout() << "typeinfo ptr type: " << *typeinfotype << '\n'; | 1191 Logger::cout() << "typeinfo ptr type: " << *typeinfotype << '\n'; |
1192 const llvm::ArrayType* typeinfoarraytype = llvm::ArrayType::get(typeinfotype,vtype->getNumElements()); | 1192 const llvm::ArrayType* typeinfoarraytype = llvm::ArrayType::get(typeinfotype,vtype->getNumElements()); |
1193 llvm::Value* typeinfomem = new llvm::AllocaInst(typeinfoarraytype,"_arguments_storage",p->topallocapoint()); | 1193 llvm::Value* typeinfomem = new llvm::AllocaInst(typeinfoarraytype,"_arguments_storage",p->topallocapoint()); |
1194 for (unsigned i=0; i<vtype->getNumElements(); ++i) { | 1194 for (unsigned i=0; i<vtype->getNumElements(); ++i) { |
1195 llvm::Value* v = p->ir->CreateBitCast(vtypeinfos[i], typeinfotype, "tmp"); | 1195 llvm::Value* v = p->ir->CreateBitCast(vtypeinfos[i], typeinfotype, "tmp"); |
1196 p->ir->CreateStore(v, LLVM_DtoGEPi(typeinfomem,0,i,"tmp")); | 1196 p->ir->CreateStore(v, DtoGEPi(typeinfomem,0,i,"tmp")); |
1197 } | 1197 } |
1198 | 1198 |
1199 llvm::Value* typeinfoarrayparam = new llvm::AllocaInst(llfnty->getParamType(j)->getContainedType(0),"_arguments_array",p->topallocapoint()); | 1199 llvm::Value* typeinfoarrayparam = new llvm::AllocaInst(llfnty->getParamType(j)->getContainedType(0),"_arguments_array",p->topallocapoint()); |
1200 p->ir->CreateStore(LLVM_DtoConstSize_t(vtype->getNumElements()), LLVM_DtoGEPi(typeinfoarrayparam,0,0,"tmp")); | 1200 p->ir->CreateStore(DtoConstSize_t(vtype->getNumElements()), DtoGEPi(typeinfoarrayparam,0,0,"tmp")); |
1201 llvm::Value* casttypeinfomem = p->ir->CreateBitCast(typeinfomem, llvm::PointerType::get(typeinfotype), "tmp"); | 1201 llvm::Value* casttypeinfomem = p->ir->CreateBitCast(typeinfomem, llvm::PointerType::get(typeinfotype), "tmp"); |
1202 p->ir->CreateStore(casttypeinfomem, LLVM_DtoGEPi(typeinfoarrayparam,0,1,"tmp")); | 1202 p->ir->CreateStore(casttypeinfomem, DtoGEPi(typeinfoarrayparam,0,1,"tmp")); |
1203 | 1203 |
1204 llargs[j] = typeinfoarrayparam;; | 1204 llargs[j] = typeinfoarrayparam;; |
1205 j++; | 1205 j++; |
1206 llargs[j] = p->ir->CreateBitCast(mem, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp"); | 1206 llargs[j] = p->ir->CreateBitCast(mem, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp"); |
1207 j++; | 1207 j++; |
1209 } | 1209 } |
1210 else { | 1210 else { |
1211 Logger::println("doing normal arguments"); | 1211 Logger::println("doing normal arguments"); |
1212 for (int i=0; i<arguments->dim; i++,j++) { | 1212 for (int i=0; i<arguments->dim; i++,j++) { |
1213 Argument* fnarg = Argument::getNth(tf->parameters, i); | 1213 Argument* fnarg = Argument::getNth(tf->parameters, i); |
1214 llargs[j] = LLVM_DtoArgument(llfnty->getParamType(j), fnarg, (Expression*)arguments->data[i]); | 1214 llargs[j] = DtoArgument(llfnty->getParamType(j), fnarg, (Expression*)arguments->data[i]); |
1215 } | 1215 } |
1216 Logger::println("%d params passed", n); | 1216 Logger::println("%d params passed", n); |
1217 for (int i=0; i<n; ++i) { | 1217 for (int i=0; i<n; ++i) { |
1218 Logger::cout() << *llargs[i] << '\n'; | 1218 Logger::cout() << *llargs[i] << '\n'; |
1219 } | 1219 } |
1236 | 1236 |
1237 // set calling convention | 1237 // set calling convention |
1238 if (fn->funcdecl) { | 1238 if (fn->funcdecl) { |
1239 int li = fn->funcdecl->llvmInternal; | 1239 int li = fn->funcdecl->llvmInternal; |
1240 if (li != LLVMintrinsic && li != LLVMva_start && li != LLVMva_intrinsic) { | 1240 if (li != LLVMintrinsic && li != LLVMva_start && li != LLVMva_intrinsic) { |
1241 call->setCallingConv(LLVM_DtoCallingConv(dlink)); | 1241 call->setCallingConv(DtoCallingConv(dlink)); |
1242 } | 1242 } |
1243 } | 1243 } |
1244 else if (delegateCall) { | 1244 else if (delegateCall) { |
1245 call->setCallingConv(LLVM_DtoCallingConv(dlink)); | 1245 call->setCallingConv(DtoCallingConv(dlink)); |
1246 } | 1246 } |
1247 else if (fn->callconv != (unsigned)-1) { | 1247 else if (fn->callconv != (unsigned)-1) { |
1248 call->setCallingConv(fn->callconv); | 1248 call->setCallingConv(fn->callconv); |
1249 } | 1249 } |
1250 | 1250 |
1258 { | 1258 { |
1259 Logger::print("CastExp::toElem: %s | %s\n", toChars(), type->toChars()); | 1259 Logger::print("CastExp::toElem: %s | %s\n", toChars(), type->toChars()); |
1260 LOG_SCOPE; | 1260 LOG_SCOPE; |
1261 elem* e = new elem; | 1261 elem* e = new elem; |
1262 elem* u = e1->toElem(p); | 1262 elem* u = e1->toElem(p); |
1263 const llvm::Type* tolltype = LLVM_DtoType(to); | 1263 const llvm::Type* tolltype = DtoType(to); |
1264 Type* fromtype = LLVM_DtoDType(e1->type); | 1264 Type* fromtype = DtoDType(e1->type); |
1265 Type* totype = LLVM_DtoDType(to); | 1265 Type* totype = DtoDType(to); |
1266 int lsz = fromtype->size(); | 1266 int lsz = fromtype->size(); |
1267 int rsz = totype->size(); | 1267 int rsz = totype->size(); |
1268 | 1268 |
1269 // this makes sure the strange lvalue casts don't screw things up | 1269 // this makes sure the strange lvalue casts don't screw things up |
1270 e->mem = u->mem; | 1270 e->mem = u->mem; |
1341 if (totype->ty == Tpointer) { | 1341 if (totype->ty == Tpointer) { |
1342 Logger::cout() << "to pointer" << '\n'; | 1342 Logger::cout() << "to pointer" << '\n'; |
1343 assert(fromtype->next == totype->next || totype->next->ty == Tvoid); | 1343 assert(fromtype->next == totype->next || totype->next->ty == Tvoid); |
1344 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1344 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1345 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | 1345 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); |
1346 llvm::Value* ptr = LLVM_DtoGEP(u->getValue(),zero,one,"tmp",p->scopebb()); | 1346 llvm::Value* ptr = DtoGEP(u->getValue(),zero,one,"tmp",p->scopebb()); |
1347 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); | 1347 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); |
1348 if (fromtype->next != totype->next) | 1348 if (fromtype->next != totype->next) |
1349 e->val = p->ir->CreateBitCast(e->val, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp"); | 1349 e->val = p->ir->CreateBitCast(e->val, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp"); |
1350 e->type = elem::VAL; | 1350 e->type = elem::VAL; |
1351 } | 1351 } |
1352 else if (totype->ty == Tarray) { | 1352 else if (totype->ty == Tarray) { |
1353 Logger::cout() << "to array" << '\n'; | 1353 Logger::cout() << "to array" << '\n'; |
1354 const llvm::Type* ptrty = LLVM_DtoType(totype->next); | 1354 const llvm::Type* ptrty = DtoType(totype->next); |
1355 if (ptrty == llvm::Type::VoidTy) | 1355 if (ptrty == llvm::Type::VoidTy) |
1356 ptrty = llvm::Type::Int8Ty; | 1356 ptrty = llvm::Type::Int8Ty; |
1357 ptrty = llvm::PointerType::get(ptrty); | 1357 ptrty = llvm::PointerType::get(ptrty); |
1358 | 1358 |
1359 const llvm::Type* ety = LLVM_DtoType(fromtype->next); | 1359 const llvm::Type* ety = DtoType(fromtype->next); |
1360 if (ety == llvm::Type::VoidTy) | 1360 if (ety == llvm::Type::VoidTy) |
1361 ety = llvm::Type::Int8Ty; | 1361 ety = llvm::Type::Int8Ty; |
1362 | 1362 |
1363 if (u->type == elem::SLICE) { | 1363 if (u->type == elem::SLICE) { |
1364 e->mem = new llvm::BitCastInst(u->mem, ptrty, "tmp", p->scopebb()); | 1364 e->mem = new llvm::BitCastInst(u->mem, ptrty, "tmp", p->scopebb()); |
1365 if (fromtype->next->size() == totype->next->size()) | 1365 if (fromtype->next->size() == totype->next->size()) |
1366 e->arg = u->arg; | 1366 e->arg = u->arg; |
1367 else | 1367 else |
1368 e->arg = LLVM_DtoArrayCastLength(u->arg, ety, ptrty->getContainedType(0)); | 1368 e->arg = DtoArrayCastLength(u->arg, ety, ptrty->getContainedType(0)); |
1369 } | 1369 } |
1370 else { | 1370 else { |
1371 llvm::Value* uval = u->getValue(); | 1371 llvm::Value* uval = u->getValue(); |
1372 if (fromtype->ty == Tsarray) { | 1372 if (fromtype->ty == Tsarray) { |
1373 Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; | 1373 Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; |
1374 assert(llvm::isa<llvm::PointerType>(uval->getType())); | 1374 assert(llvm::isa<llvm::PointerType>(uval->getType())); |
1375 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(uval->getType()->getContainedType(0)); | 1375 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(uval->getType()->getContainedType(0)); |
1376 e->arg = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrty->getNumElements(), false); | 1376 e->arg = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false); |
1377 e->arg = LLVM_DtoArrayCastLength(e->arg, ety, ptrty->getContainedType(0)); | 1377 e->arg = DtoArrayCastLength(e->arg, ety, ptrty->getContainedType(0)); |
1378 e->mem = new llvm::BitCastInst(uval, ptrty, "tmp", p->scopebb()); | 1378 e->mem = new llvm::BitCastInst(uval, ptrty, "tmp", p->scopebb()); |
1379 } | 1379 } |
1380 else { | 1380 else { |
1381 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1381 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1382 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | 1382 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); |
1383 e->arg = LLVM_DtoGEP(uval,zero,zero,"tmp",p->scopebb()); | 1383 e->arg = DtoGEP(uval,zero,zero,"tmp",p->scopebb()); |
1384 e->arg = new llvm::LoadInst(e->arg, "tmp", p->scopebb()); | 1384 e->arg = new llvm::LoadInst(e->arg, "tmp", p->scopebb()); |
1385 e->arg = LLVM_DtoArrayCastLength(e->arg, ety, ptrty->getContainedType(0)); | 1385 e->arg = DtoArrayCastLength(e->arg, ety, ptrty->getContainedType(0)); |
1386 | 1386 |
1387 e->mem = LLVM_DtoGEP(uval,zero,one,"tmp",p->scopebb()); | 1387 e->mem = DtoGEP(uval,zero,one,"tmp",p->scopebb()); |
1388 e->mem = new llvm::LoadInst(e->mem, "tmp", p->scopebb()); | 1388 e->mem = new llvm::LoadInst(e->mem, "tmp", p->scopebb()); |
1389 //Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n'; | 1389 //Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n'; |
1390 e->mem = new llvm::BitCastInst(e->mem, ptrty, "tmp", p->scopebb()); | 1390 e->mem = new llvm::BitCastInst(e->mem, ptrty, "tmp", p->scopebb()); |
1391 } | 1391 } |
1392 } | 1392 } |
1436 if (vd->isTypedefDeclaration()) { | 1436 if (vd->isTypedefDeclaration()) { |
1437 e->istypeinfo = true; | 1437 e->istypeinfo = true; |
1438 } | 1438 } |
1439 | 1439 |
1440 assert(vd->llvmValue); | 1440 assert(vd->llvmValue); |
1441 Type* t = LLVM_DtoDType(type); | 1441 Type* t = DtoDType(type); |
1442 Type* tnext = LLVM_DtoDType(t->next); | 1442 Type* tnext = DtoDType(t->next); |
1443 Type* vdtype = LLVM_DtoDType(vd->type); | 1443 Type* vdtype = DtoDType(vd->type); |
1444 | 1444 |
1445 llvm::Value* llvalue = vd->nestedref ? LLVM_DtoNestedVariable(vd) : vd->llvmValue; | 1445 llvm::Value* llvalue = vd->nestedref ? DtoNestedVariable(vd) : vd->llvmValue; |
1446 | 1446 |
1447 if (vdtype->ty == Tstruct && !(t->ty == Tpointer && t->next == vdtype)) { | 1447 if (vdtype->ty == Tstruct && !(t->ty == Tpointer && t->next == vdtype)) { |
1448 Logger::println("struct"); | 1448 Logger::println("struct"); |
1449 TypeStruct* vdt = (TypeStruct*)vdtype; | 1449 TypeStruct* vdt = (TypeStruct*)vdtype; |
1450 assert(vdt->sym); | 1450 assert(vdt->sym); |
1451 e = new elem; | 1451 e = new elem; |
1452 const llvm::Type* llt = LLVM_DtoType(t); | 1452 const llvm::Type* llt = DtoType(t); |
1453 if (offset == 0) { | 1453 if (offset == 0) { |
1454 e->mem = p->ir->CreateBitCast(llvalue, llt, "tmp"); | 1454 e->mem = p->ir->CreateBitCast(llvalue, llt, "tmp"); |
1455 } | 1455 } |
1456 else { | 1456 else { |
1457 std::vector<unsigned> dst; | 1457 std::vector<unsigned> dst; |
1458 e->mem = LLVM_DtoIndexStruct(llvalue,vdt->sym, tnext, offset, dst); | 1458 e->mem = DtoIndexStruct(llvalue,vdt->sym, tnext, offset, dst); |
1459 } | 1459 } |
1460 e->type = elem::VAL; | 1460 e->type = elem::VAL; |
1461 e->field = true; | 1461 e->field = true; |
1462 } | 1462 } |
1463 else if (vdtype->ty == Tsarray) { | 1463 else if (vdtype->ty == Tsarray) { |
1465 e = new elem; | 1465 e = new elem; |
1466 assert(llvalue); | 1466 assert(llvalue); |
1467 e->arg = llvalue; | 1467 e->arg = llvalue; |
1468 e->type = elem::VAL; | 1468 e->type = elem::VAL; |
1469 | 1469 |
1470 const llvm::Type* llt = LLVM_DtoType(t); | 1470 const llvm::Type* llt = DtoType(t); |
1471 llvm::Value* off = 0; | 1471 llvm::Value* off = 0; |
1472 if (offset != 0) { | 1472 if (offset != 0) { |
1473 Logger::println("offset = %d\n", offset); | 1473 Logger::println("offset = %d\n", offset); |
1474 } | 1474 } |
1475 if (llvalue->getType() != llt) { | 1475 if (llvalue->getType() != llt) { |
1476 e->mem = p->ir->CreateBitCast(llvalue, llt, "tmp"); | 1476 e->mem = p->ir->CreateBitCast(llvalue, llt, "tmp"); |
1477 if (offset != 0) | 1477 if (offset != 0) |
1478 e->mem = LLVM_DtoGEPi(e->mem, offset, "tmp"); | 1478 e->mem = DtoGEPi(e->mem, offset, "tmp"); |
1479 } | 1479 } |
1480 else { | 1480 else { |
1481 assert(offset == 0); | 1481 assert(offset == 0); |
1482 e->mem = LLVM_DtoGEPi(llvalue,0,0,"tmp"); | 1482 e->mem = DtoGEPi(llvalue,0,0,"tmp"); |
1483 } | 1483 } |
1484 } | 1484 } |
1485 else if (offset == 0) { | 1485 else if (offset == 0) { |
1486 Logger::println("normal symoff"); | 1486 Logger::println("normal symoff"); |
1487 e = new elem; | 1487 e = new elem; |
1488 e->type = elem::VAL; | 1488 e->type = elem::VAL; |
1489 assert(llvalue); | 1489 assert(llvalue); |
1490 e->mem = llvalue; | 1490 e->mem = llvalue; |
1491 | 1491 |
1492 const llvm::Type* llt = LLVM_DtoType(t); | 1492 const llvm::Type* llt = DtoType(t); |
1493 if (llvalue->getType() != llt) { | 1493 if (llvalue->getType() != llt) { |
1494 e->mem = p->ir->CreateBitCast(e->mem, llt, "tmp"); | 1494 e->mem = p->ir->CreateBitCast(e->mem, llt, "tmp"); |
1495 } | 1495 } |
1496 } | 1496 } |
1497 else { | 1497 else { |
1544 LOG_SCOPE; | 1544 LOG_SCOPE; |
1545 elem* e = new elem; | 1545 elem* e = new elem; |
1546 | 1546 |
1547 elem* l = e1->toElem(p); | 1547 elem* l = e1->toElem(p); |
1548 | 1548 |
1549 Type* t = LLVM_DtoDType(type); | 1549 Type* t = DtoDType(type); |
1550 Type* e1type = LLVM_DtoDType(e1->type); | 1550 Type* e1type = DtoDType(e1->type); |
1551 | 1551 |
1552 Logger::print("e1->type=%s\n", e1type->toChars()); | 1552 Logger::print("e1->type=%s\n", e1type->toChars()); |
1553 | 1553 |
1554 if (VarDeclaration* vd = var->isVarDeclaration()) { | 1554 if (VarDeclaration* vd = var->isVarDeclaration()) { |
1555 llvm::Value* arrptr; | 1555 llvm::Value* arrptr; |
1557 assert(e1type->next->ty == Tstruct); | 1557 assert(e1type->next->ty == Tstruct); |
1558 TypeStruct* ts = (TypeStruct*)e1type->next; | 1558 TypeStruct* ts = (TypeStruct*)e1type->next; |
1559 Logger::println("Struct member offset:%d", vd->offset); | 1559 Logger::println("Struct member offset:%d", vd->offset); |
1560 llvm::Value* src = l->val ? l->val : l->mem; | 1560 llvm::Value* src = l->val ? l->val : l->mem; |
1561 std::vector<unsigned> vdoffsets; | 1561 std::vector<unsigned> vdoffsets; |
1562 arrptr = LLVM_DtoIndexStruct(src, ts->sym, vd->type, vd->offset, vdoffsets); | 1562 arrptr = DtoIndexStruct(src, ts->sym, vd->type, vd->offset, vdoffsets); |
1563 } | 1563 } |
1564 else if (e1->type->ty == Tclass) { | 1564 else if (e1->type->ty == Tclass) { |
1565 TypeClass* tc = (TypeClass*)e1type; | 1565 TypeClass* tc = (TypeClass*)e1type; |
1566 Logger::println("Class member offset: %d", vd->offset); | 1566 Logger::println("Class member offset: %d", vd->offset); |
1567 std::vector<unsigned> vdoffsets(1,0); | 1567 std::vector<unsigned> vdoffsets(1,0); |
1568 tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets); | 1568 tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets); |
1569 llvm::Value* src = l->getValue(); | 1569 llvm::Value* src = l->getValue(); |
1570 Logger::cout() << "src: " << *src << '\n'; | 1570 Logger::cout() << "src: " << *src << '\n'; |
1571 arrptr = LLVM_DtoGEP(src,vdoffsets,"tmp",p->scopebb()); | 1571 arrptr = DtoGEP(src,vdoffsets,"tmp",p->scopebb()); |
1572 } | 1572 } |
1573 else | 1573 else |
1574 assert(0); | 1574 assert(0); |
1575 e->mem = arrptr; | 1575 e->mem = arrptr; |
1576 Logger::cout() << "mem: " << *e->mem << '\n'; | 1576 Logger::cout() << "mem: " << *e->mem << '\n'; |
1591 assert(fdecl->vtblIndex > 0); | 1591 assert(fdecl->vtblIndex > 0); |
1592 assert(e1type->ty == Tclass); | 1592 assert(e1type->ty == Tclass); |
1593 | 1593 |
1594 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1594 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1595 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); | 1595 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); |
1596 funcval = LLVM_DtoGEP(e->arg, zero, zero, "tmp", p->scopebb()); | 1596 funcval = DtoGEP(e->arg, zero, zero, "tmp", p->scopebb()); |
1597 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); | 1597 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
1598 funcval = LLVM_DtoGEP(funcval, zero, vtblidx, toChars(), p->scopebb()); | 1598 funcval = DtoGEP(funcval, zero, vtblidx, toChars(), p->scopebb()); |
1599 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); | 1599 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
1600 assert(funcval->getType() == fdecl->llvmValue->getType()); | 1600 assert(funcval->getType() == fdecl->llvmValue->getType()); |
1601 e->callconv = LLVM_DtoCallingConv(fdecl->linkage); | 1601 e->callconv = DtoCallingConv(fdecl->linkage); |
1602 } | 1602 } |
1603 e->val = funcval; | 1603 e->val = funcval; |
1604 e->type = elem::FUNC; | 1604 e->type = elem::FUNC; |
1605 e->funcdecl = fdecl; | 1605 e->funcdecl = fdecl; |
1606 } | 1606 } |
1655 Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); | 1655 Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); |
1656 LOG_SCOPE; | 1656 LOG_SCOPE; |
1657 elem* e = new elem; | 1657 elem* e = new elem; |
1658 | 1658 |
1659 llvm::Value* sptr; | 1659 llvm::Value* sptr; |
1660 const llvm::Type* llt = LLVM_DtoType(type); | 1660 const llvm::Type* llt = DtoType(type); |
1661 | 1661 |
1662 // temporary struct literal | 1662 // temporary struct literal |
1663 if (!p->topexp() || p->topexp()->e2 != this) | 1663 if (!p->topexp() || p->topexp()->e2 != this) |
1664 { | 1664 { |
1665 sptr = new llvm::AllocaInst(llt,"tmpstructliteral",p->topallocapoint()); | 1665 sptr = new llvm::AllocaInst(llt,"tmpstructliteral",p->topallocapoint()); |
1681 // build the type of the literal | 1681 // build the type of the literal |
1682 std::vector<const llvm::Type*> tys; | 1682 std::vector<const llvm::Type*> tys; |
1683 for (unsigned i=0; i<n; ++i) { | 1683 for (unsigned i=0; i<n; ++i) { |
1684 Expression* vx = (Expression*)elements->data[i]; | 1684 Expression* vx = (Expression*)elements->data[i]; |
1685 if (!vx) continue; | 1685 if (!vx) continue; |
1686 tys.push_back(LLVM_DtoType(vx->type)); | 1686 tys.push_back(DtoType(vx->type)); |
1687 } | 1687 } |
1688 const llvm::StructType* t = llvm::StructType::get(tys); | 1688 const llvm::StructType* t = llvm::StructType::get(tys); |
1689 if (t != llt) { | 1689 if (t != llt) { |
1690 if (gTargetData->getTypeSize(t) != gTargetData->getTypeSize(llt)) { | 1690 if (gTargetData->getTypeSize(t) != gTargetData->getTypeSize(llt)) { |
1691 Logger::cout() << "got size " << gTargetData->getTypeSize(t) << ", expected " << gTargetData->getTypeSize(llt) << '\n'; | 1691 Logger::cout() << "got size " << gTargetData->getTypeSize(t) << ", expected " << gTargetData->getTypeSize(llt) << '\n'; |
1702 { | 1702 { |
1703 Expression* vx = (Expression*)elements->data[i]; | 1703 Expression* vx = (Expression*)elements->data[i]; |
1704 if (!vx) continue; | 1704 if (!vx) continue; |
1705 | 1705 |
1706 Logger::cout() << "getting index " << j << " of " << *sptr << '\n'; | 1706 Logger::cout() << "getting index " << j << " of " << *sptr << '\n'; |
1707 llvm::Value* arrptr = LLVM_DtoGEPi(sptr,0,j,"tmp",p->scopebb()); | 1707 llvm::Value* arrptr = DtoGEPi(sptr,0,j,"tmp",p->scopebb()); |
1708 | 1708 |
1709 p->exps.push_back(IRExp(NULL,vx,arrptr)); | 1709 p->exps.push_back(IRExp(NULL,vx,arrptr)); |
1710 elem* ve = vx->toElem(p); | 1710 elem* ve = vx->toElem(p); |
1711 p->exps.pop_back(); | 1711 p->exps.pop_back(); |
1712 | 1712 |
1713 if (!ve->inplace) { | 1713 if (!ve->inplace) { |
1714 llvm::Value* val = ve->getValue(); | 1714 llvm::Value* val = ve->getValue(); |
1715 Logger::cout() << *val << " | " << *arrptr << '\n'; | 1715 Logger::cout() << *val << " | " << *arrptr << '\n'; |
1716 | 1716 |
1717 Type* vxtype = LLVM_DtoDType(vx->type); | 1717 Type* vxtype = DtoDType(vx->type); |
1718 LLVM_DtoAssign(vxtype, arrptr, val); | 1718 DtoAssign(vxtype, arrptr, val); |
1719 } | 1719 } |
1720 delete ve; | 1720 delete ve; |
1721 | 1721 |
1722 j++; | 1722 j++; |
1723 } | 1723 } |
1741 { | 1741 { |
1742 Expression* vx = (Expression*)elements->data[i]; | 1742 Expression* vx = (Expression*)elements->data[i]; |
1743 vals[i] = vx->toConstElem(p); | 1743 vals[i] = vx->toConstElem(p); |
1744 } | 1744 } |
1745 | 1745 |
1746 assert(LLVM_DtoDType(type)->ty == Tstruct); | 1746 assert(DtoDType(type)->ty == Tstruct); |
1747 const llvm::Type* t = LLVM_DtoType(type); | 1747 const llvm::Type* t = DtoType(type); |
1748 const llvm::StructType* st = llvm::cast<llvm::StructType>(t); | 1748 const llvm::StructType* st = llvm::cast<llvm::StructType>(t); |
1749 return llvm::ConstantStruct::get(st,vals); | 1749 return llvm::ConstantStruct::get(st,vals); |
1750 } | 1750 } |
1751 | 1751 |
1752 ////////////////////////////////////////////////////////////////////////////////////////// | 1752 ////////////////////////////////////////////////////////////////////////////////////////// |
1758 | 1758 |
1759 elem* e = new elem; | 1759 elem* e = new elem; |
1760 | 1760 |
1761 elem* l = e1->toElem(p); | 1761 elem* l = e1->toElem(p); |
1762 | 1762 |
1763 Type* e1type = LLVM_DtoDType(e1->type); | 1763 Type* e1type = DtoDType(e1->type); |
1764 | 1764 |
1765 p->arrays.push_back(l->mem); // if $ is used it must be an array so this is fine. | 1765 p->arrays.push_back(l->mem); // if $ is used it must be an array so this is fine. |
1766 elem* r = e2->toElem(p); | 1766 elem* r = e2->toElem(p); |
1767 p->arrays.pop_back(); | 1767 p->arrays.pop_back(); |
1768 | 1768 |
1772 llvm::Value* arrptr = 0; | 1772 llvm::Value* arrptr = 0; |
1773 if (e1type->ty == Tpointer) { | 1773 if (e1type->ty == Tpointer) { |
1774 arrptr = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); | 1774 arrptr = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
1775 } | 1775 } |
1776 else if (e1type->ty == Tsarray) { | 1776 else if (e1type->ty == Tsarray) { |
1777 arrptr = LLVM_DtoGEP(l->getValue(), zero, r->getValue(),"tmp",p->scopebb()); | 1777 arrptr = DtoGEP(l->getValue(), zero, r->getValue(),"tmp",p->scopebb()); |
1778 } | 1778 } |
1779 else if (e1type->ty == Tarray) { | 1779 else if (e1type->ty == Tarray) { |
1780 arrptr = LLVM_DtoGEP(l->mem,zero,one,"tmp",p->scopebb()); | 1780 arrptr = DtoGEP(l->mem,zero,one,"tmp",p->scopebb()); |
1781 arrptr = new llvm::LoadInst(arrptr,"tmp",p->scopebb()); | 1781 arrptr = new llvm::LoadInst(arrptr,"tmp",p->scopebb()); |
1782 arrptr = new llvm::GetElementPtrInst(arrptr,r->getValue(),"tmp",p->scopebb()); | 1782 arrptr = new llvm::GetElementPtrInst(arrptr,r->getValue(),"tmp",p->scopebb()); |
1783 } | 1783 } |
1784 assert(arrptr); | 1784 assert(arrptr); |
1785 | 1785 |
1797 elem* SliceExp::toElem(IRState* p) | 1797 elem* SliceExp::toElem(IRState* p) |
1798 { | 1798 { |
1799 Logger::print("SliceExp::toElem: %s | %s\n", toChars(), type->toChars()); | 1799 Logger::print("SliceExp::toElem: %s | %s\n", toChars(), type->toChars()); |
1800 LOG_SCOPE; | 1800 LOG_SCOPE; |
1801 | 1801 |
1802 Type* t = LLVM_DtoDType(type); | 1802 Type* t = DtoDType(type); |
1803 assert(t->ty == Tarray); | 1803 assert(t->ty == Tarray); |
1804 | 1804 |
1805 elem* v = e1->toElem(p); | 1805 elem* v = e1->toElem(p); |
1806 Type* e1type = LLVM_DtoDType(e1->type); | 1806 Type* e1type = DtoDType(e1->type); |
1807 | 1807 |
1808 elem* e = new elem; | 1808 elem* e = new elem; |
1809 assert(v->mem); | 1809 assert(v->mem); |
1810 e->type = elem::SLICE; | 1810 e->type = elem::SLICE; |
1811 | 1811 |
1827 | 1827 |
1828 if (e1type->ty == Tpointer) { | 1828 if (e1type->ty == Tpointer) { |
1829 e->mem = v->getValue(); | 1829 e->mem = v->getValue(); |
1830 } | 1830 } |
1831 else if (e1type->ty == Tarray) { | 1831 else if (e1type->ty == Tarray) { |
1832 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); | 1832 llvm::Value* tmp = DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); |
1833 e->mem = new llvm::LoadInst(tmp,"tmp",p->scopebb()); | 1833 e->mem = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
1834 } | 1834 } |
1835 else if (e1type->ty == Tsarray) { | 1835 else if (e1type->ty == Tsarray) { |
1836 e->mem = LLVM_DtoGEP(v->mem,zero,zero,"tmp",p->scopebb()); | 1836 e->mem = DtoGEP(v->mem,zero,zero,"tmp",p->scopebb()); |
1837 } | 1837 } |
1838 else | 1838 else |
1839 assert(e->mem); | 1839 assert(e->mem); |
1840 | 1840 |
1841 llvm::ConstantInt* c = llvm::cast<llvm::ConstantInt>(lo->val); | 1841 llvm::ConstantInt* c = llvm::cast<llvm::ConstantInt>(lo->val); |
1844 } | 1844 } |
1845 } | 1845 } |
1846 else | 1846 else |
1847 { | 1847 { |
1848 if (e1type->ty == Tarray) { | 1848 if (e1type->ty == Tarray) { |
1849 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); | 1849 llvm::Value* tmp = DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); |
1850 tmp = new llvm::LoadInst(tmp,"tmp",p->scopebb()); | 1850 tmp = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
1851 e->mem = new llvm::GetElementPtrInst(tmp,lo->getValue(),"tmp",p->scopebb()); | 1851 e->mem = new llvm::GetElementPtrInst(tmp,lo->getValue(),"tmp",p->scopebb()); |
1852 } | 1852 } |
1853 else if (e1type->ty == Tsarray) { | 1853 else if (e1type->ty == Tsarray) { |
1854 e->mem = LLVM_DtoGEP(v->mem,zero,lo->getValue(),"tmp",p->scopebb()); | 1854 e->mem = DtoGEP(v->mem,zero,lo->getValue(),"tmp",p->scopebb()); |
1855 } | 1855 } |
1856 else if (e1type->ty == Tpointer) { | 1856 else if (e1type->ty == Tpointer) { |
1857 e->mem = new llvm::GetElementPtrInst(v->getValue(),lo->getValue(),"tmp",p->scopebb()); | 1857 e->mem = new llvm::GetElementPtrInst(v->getValue(),lo->getValue(),"tmp",p->scopebb()); |
1858 } | 1858 } |
1859 else { | 1859 else { |
1895 | 1895 |
1896 delete lo; | 1896 delete lo; |
1897 delete up; | 1897 delete up; |
1898 | 1898 |
1899 /* | 1899 /* |
1900 llvm::Value* tmpmem = new llvm::AllocaInst(LLVM_DtoType(t),"tmp",p->topallocapoint()); | 1900 llvm::Value* tmpmem = new llvm::AllocaInst(DtoType(t),"tmp",p->topallocapoint()); |
1901 llvm::Value* ptr = LLVM_DtoGEPi(tmpmem,0,0,"tmp"); | 1901 llvm::Value* ptr = DtoGEPi(tmpmem,0,0,"tmp"); |
1902 p->ir->CreateStore(e->arg, ptr); | 1902 p->ir->CreateStore(e->arg, ptr); |
1903 ptr = LLVM_DtoGEPi(tmpmem,0,1,"tmp"); | 1903 ptr = DtoGEPi(tmpmem,0,1,"tmp"); |
1904 p->ir->CreateStore(e->mem, ptr); | 1904 p->ir->CreateStore(e->mem, ptr); |
1905 e->arg = NULL; | 1905 e->arg = NULL; |
1906 e->mem = tmpmem; | 1906 e->mem = tmpmem; |
1907 */ | 1907 */ |
1908 } | 1908 } |
1927 elem* e = new elem; | 1927 elem* e = new elem; |
1928 | 1928 |
1929 elem* l = e1->toElem(p); | 1929 elem* l = e1->toElem(p); |
1930 elem* r = e2->toElem(p); | 1930 elem* r = e2->toElem(p); |
1931 | 1931 |
1932 Type* t = LLVM_DtoDType(e1->type); | 1932 Type* t = DtoDType(e1->type); |
1933 Type* e2t = LLVM_DtoDType(e2->type); | 1933 Type* e2t = DtoDType(e2->type); |
1934 assert(t == e2t); | 1934 assert(t == e2t); |
1935 | 1935 |
1936 if (t->isintegral() || t->ty == Tpointer) | 1936 if (t->isintegral() || t->ty == Tpointer) |
1937 { | 1937 { |
1938 llvm::ICmpInst::Predicate cmpop; | 1938 llvm::ICmpInst::Predicate cmpop; |
2036 elem* e = new elem; | 2036 elem* e = new elem; |
2037 | 2037 |
2038 elem* l = e1->toElem(p); | 2038 elem* l = e1->toElem(p); |
2039 elem* r = e2->toElem(p); | 2039 elem* r = e2->toElem(p); |
2040 | 2040 |
2041 Type* t = LLVM_DtoDType(e1->type); | 2041 Type* t = DtoDType(e1->type); |
2042 Type* e2t = LLVM_DtoDType(e2->type); | 2042 Type* e2t = DtoDType(e2->type); |
2043 assert(t == e2t); | 2043 assert(t == e2t); |
2044 | 2044 |
2045 if (t->isintegral() || t->ty == Tpointer) | 2045 if (t->isintegral() || t->ty == Tpointer) |
2046 { | 2046 { |
2047 Logger::println("integral or pointer"); | 2047 Logger::println("integral or pointer"); |
2077 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | 2077 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); |
2078 } | 2078 } |
2079 else if (t->ty == Tsarray) | 2079 else if (t->ty == Tsarray) |
2080 { | 2080 { |
2081 Logger::println("static array"); | 2081 Logger::println("static array"); |
2082 e->val = LLVM_DtoStaticArrayCompare(op,l->mem,r->mem); | 2082 e->val = DtoStaticArrayCompare(op,l->mem,r->mem); |
2083 } | 2083 } |
2084 else if (t->ty == Tarray) | 2084 else if (t->ty == Tarray) |
2085 { | 2085 { |
2086 Logger::println("dynamic array"); | 2086 Logger::println("dynamic array"); |
2087 e->val = LLVM_DtoDynArrayCompare(op,l->mem,r->mem); | 2087 e->val = DtoDynArrayCompare(op,l->mem,r->mem); |
2088 } | 2088 } |
2089 else if (t->ty == Tdelegate) | 2089 else if (t->ty == Tdelegate) |
2090 { | 2090 { |
2091 Logger::println("delegate"); | 2091 Logger::println("delegate"); |
2092 e->val = LLVM_DtoCompareDelegate(op,l->mem,r->mem); | 2092 e->val = DtoCompareDelegate(op,l->mem,r->mem); |
2093 } | 2093 } |
2094 else | 2094 else |
2095 { | 2095 { |
2096 assert(0 && "Unsupported EqualExp type"); | 2096 assert(0 && "Unsupported EqualExp type"); |
2097 } | 2097 } |
2120 e->type = elem::VAL; | 2120 e->type = elem::VAL; |
2121 | 2121 |
2122 llvm::Value* val = e->val; | 2122 llvm::Value* val = e->val; |
2123 llvm::Value* post = 0; | 2123 llvm::Value* post = 0; |
2124 | 2124 |
2125 Type* e1type = LLVM_DtoDType(e1->type); | 2125 Type* e1type = DtoDType(e1->type); |
2126 Type* e2type = LLVM_DtoDType(e2->type); | 2126 Type* e2type = DtoDType(e2->type); |
2127 | 2127 |
2128 if (e1type->isintegral()) | 2128 if (e1type->isintegral()) |
2129 { | 2129 { |
2130 assert(e2type->isintegral()); | 2130 assert(e2type->isintegral()); |
2131 llvm::Value* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned()); | 2131 llvm::Value* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned()); |
2137 } | 2137 } |
2138 } | 2138 } |
2139 else if (e1type->ty == Tpointer) | 2139 else if (e1type->ty == Tpointer) |
2140 { | 2140 { |
2141 assert(e2type->isintegral()); | 2141 assert(e2type->isintegral()); |
2142 llvm::Constant* minusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)-1,true); | 2142 llvm::Constant* minusone = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)-1,true); |
2143 llvm::Constant* plusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)1,false); | 2143 llvm::Constant* plusone = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)1,false); |
2144 llvm::Constant* whichone = (op == TOKplusplus) ? plusone : minusone; | 2144 llvm::Constant* whichone = (op == TOKplusplus) ? plusone : minusone; |
2145 post = new llvm::GetElementPtrInst(val, whichone, "tmp", p->scopebb()); | 2145 post = new llvm::GetElementPtrInst(val, whichone, "tmp", p->scopebb()); |
2146 } | 2146 } |
2147 else if (e1type->isfloating()) | 2147 else if (e1type->isfloating()) |
2148 { | 2148 { |
2157 } | 2157 } |
2158 else | 2158 else |
2159 assert(post); | 2159 assert(post); |
2160 | 2160 |
2161 if (l->mem == 0) | 2161 if (l->mem == 0) |
2162 LLVM_DtoGiveArgumentStorage(l); | 2162 DtoGiveArgumentStorage(l); |
2163 new llvm::StoreInst(post,l->mem,p->scopebb()); | 2163 new llvm::StoreInst(post,l->mem,p->scopebb()); |
2164 | 2164 |
2165 delete l; | 2165 delete l; |
2166 delete r; | 2166 delete r; |
2167 | 2167 |
2181 assert(!allocator); | 2181 assert(!allocator); |
2182 | 2182 |
2183 elem* e = new elem; | 2183 elem* e = new elem; |
2184 e->inplace = true; | 2184 e->inplace = true; |
2185 | 2185 |
2186 Type* ntype = LLVM_DtoDType(newtype); | 2186 Type* ntype = DtoDType(newtype); |
2187 | 2187 |
2188 const llvm::Type* t = LLVM_DtoType(ntype); | 2188 const llvm::Type* t = DtoType(ntype); |
2189 | 2189 |
2190 if (onstack) { | 2190 if (onstack) { |
2191 assert(ntype->ty == Tclass); | 2191 assert(ntype->ty == Tclass); |
2192 e->mem = new llvm::AllocaInst(t->getContainedType(0),"tmp",p->topallocapoint()); | 2192 e->mem = new llvm::AllocaInst(t->getContainedType(0),"tmp",p->topallocapoint()); |
2193 } | 2193 } |
2198 else if (ntype->ty == Tarray) { | 2198 else if (ntype->ty == Tarray) { |
2199 assert(arguments); | 2199 assert(arguments); |
2200 if (arguments->dim == 1) { | 2200 if (arguments->dim == 1) { |
2201 elem* sz = ((Expression*)arguments->data[0])->toElem(p); | 2201 elem* sz = ((Expression*)arguments->data[0])->toElem(p); |
2202 llvm::Value* dimval = sz->getValue(); | 2202 llvm::Value* dimval = sz->getValue(); |
2203 Type* nnt = LLVM_DtoDType(ntype->next); | 2203 Type* nnt = DtoDType(ntype->next); |
2204 if (nnt->ty == Tvoid) | 2204 if (nnt->ty == Tvoid) |
2205 nnt = Type::tint8; | 2205 nnt = Type::tint8; |
2206 if (!p->topexp() || p->topexp()->e2 != this) { | 2206 if (!p->topexp() || p->topexp()->e2 != this) { |
2207 const llvm::Type* restype = LLVM_DtoType(type); | 2207 const llvm::Type* restype = DtoType(type); |
2208 Logger::cout() << "restype = " << *restype << '\n'; | 2208 Logger::cout() << "restype = " << *restype << '\n'; |
2209 e->mem = new llvm::AllocaInst(restype,"tmp",p->topallocapoint()); | 2209 e->mem = new llvm::AllocaInst(restype,"tmp",p->topallocapoint()); |
2210 LLVM_DtoNewDynArray(e->mem, dimval, nnt); | 2210 DtoNewDynArray(e->mem, dimval, nnt); |
2211 e->inplace = false; | 2211 e->inplace = false; |
2212 } | 2212 } |
2213 else if (p->topexp() || p->topexp()->e2 != this) { | 2213 else if (p->topexp() || p->topexp()->e2 != this) { |
2214 assert(p->topexp()->v); | 2214 assert(p->topexp()->v); |
2215 e->mem = p->topexp()->v; | 2215 e->mem = p->topexp()->v; |
2216 LLVM_DtoNewDynArray(e->mem, dimval, nnt); | 2216 DtoNewDynArray(e->mem, dimval, nnt); |
2217 } | 2217 } |
2218 else | 2218 else |
2219 assert(0); | 2219 assert(0); |
2220 delete sz; | 2220 delete sz; |
2221 } | 2221 } |
2229 } | 2229 } |
2230 | 2230 |
2231 if (ntype->ty == Tclass) { | 2231 if (ntype->ty == Tclass) { |
2232 // first apply the static initializer | 2232 // first apply the static initializer |
2233 assert(e->mem); | 2233 assert(e->mem); |
2234 LLVM_DtoInitClass((TypeClass*)ntype, e->mem); | 2234 DtoInitClass((TypeClass*)ntype, e->mem); |
2235 | 2235 |
2236 // then call constructor | 2236 // then call constructor |
2237 if (arguments) { | 2237 if (arguments) { |
2238 assert(member); | 2238 assert(member); |
2239 assert(member->llvmValue); | 2239 assert(member->llvmValue); |
2240 llvm::Function* fn = llvm::cast<llvm::Function>(member->llvmValue); | 2240 llvm::Function* fn = llvm::cast<llvm::Function>(member->llvmValue); |
2241 TypeFunction* tf = (TypeFunction*)LLVM_DtoDType(member->type); | 2241 TypeFunction* tf = (TypeFunction*)DtoDType(member->type); |
2242 | 2242 |
2243 std::vector<llvm::Value*> ctorargs; | 2243 std::vector<llvm::Value*> ctorargs; |
2244 ctorargs.push_back(e->mem); | 2244 ctorargs.push_back(e->mem); |
2245 for (size_t i=0; i<arguments->dim; ++i) | 2245 for (size_t i=0; i<arguments->dim; ++i) |
2246 { | 2246 { |
2247 Expression* ex = (Expression*)arguments->data[i]; | 2247 Expression* ex = (Expression*)arguments->data[i]; |
2248 Argument* fnarg = Argument::getNth(tf->parameters, i); | 2248 Argument* fnarg = Argument::getNth(tf->parameters, i); |
2249 llvm::Value* a = LLVM_DtoArgument(fn->getFunctionType()->getParamType(i+1), fnarg, ex); | 2249 llvm::Value* a = DtoArgument(fn->getFunctionType()->getParamType(i+1), fnarg, ex); |
2250 ctorargs.push_back(a); | 2250 ctorargs.push_back(a); |
2251 } | 2251 } |
2252 e->mem = new llvm::CallInst(fn, ctorargs.begin(), ctorargs.end(), "tmp", p->scopebb()); | 2252 e->mem = new llvm::CallInst(fn, ctorargs.begin(), ctorargs.end(), "tmp", p->scopebb()); |
2253 } | 2253 } |
2254 } | 2254 } |
2255 else if (ntype->ty == Tstruct) { | 2255 else if (ntype->ty == Tstruct) { |
2256 TypeStruct* ts = (TypeStruct*)ntype; | 2256 TypeStruct* ts = (TypeStruct*)ntype; |
2257 if (ts->isZeroInit()) { | 2257 if (ts->isZeroInit()) { |
2258 LLVM_DtoStructZeroInit(e->mem); | 2258 DtoStructZeroInit(e->mem); |
2259 } | 2259 } |
2260 else { | 2260 else { |
2261 LLVM_DtoStructCopy(e->mem,ts->llvmInit); | 2261 DtoStructCopy(e->mem,ts->llvmInit); |
2262 } | 2262 } |
2263 } | 2263 } |
2264 | 2264 |
2265 e->type = elem::VAR; | 2265 e->type = elem::VAR; |
2266 | 2266 |
2281 llvm::Value* ldval = 0; | 2281 llvm::Value* ldval = 0; |
2282 | 2282 |
2283 const llvm::Type* t = val->getType(); | 2283 const llvm::Type* t = val->getType(); |
2284 llvm::Constant* z = llvm::Constant::getNullValue(t); | 2284 llvm::Constant* z = llvm::Constant::getNullValue(t); |
2285 | 2285 |
2286 Type* e1type = LLVM_DtoDType(e1->type); | 2286 Type* e1type = DtoDType(e1->type); |
2287 | 2287 |
2288 if (e1type->ty == Tpointer) { | 2288 if (e1type->ty == Tpointer) { |
2289 ldval = v->getValue(); | 2289 ldval = v->getValue(); |
2290 new llvm::FreeInst(ldval, p->scopebb()); | 2290 new llvm::FreeInst(ldval, p->scopebb()); |
2291 | 2291 |
2293 Logger::cout() << *val << '\n'; | 2293 Logger::cout() << *val << '\n'; |
2294 new llvm::StoreInst(z, v->mem, p->scopebb()); | 2294 new llvm::StoreInst(z, v->mem, p->scopebb()); |
2295 } | 2295 } |
2296 else if (e1type->ty == Tclass) { | 2296 else if (e1type->ty == Tclass) { |
2297 TypeClass* tc = (TypeClass*)e1type; | 2297 TypeClass* tc = (TypeClass*)e1type; |
2298 LLVM_DtoCallClassDtors(tc, val); | 2298 DtoCallClassDtors(tc, val); |
2299 | 2299 |
2300 if (v->vardecl && !v->vardecl->onstack) { | 2300 if (v->vardecl && !v->vardecl->onstack) { |
2301 new llvm::FreeInst(val, p->scopebb()); | 2301 new llvm::FreeInst(val, p->scopebb()); |
2302 } | 2302 } |
2303 new llvm::StoreInst(z, v->mem, p->scopebb()); | 2303 new llvm::StoreInst(z, v->mem, p->scopebb()); |
2307 ldval = v->getValue(); | 2307 ldval = v->getValue(); |
2308 | 2308 |
2309 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 2309 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
2310 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | 2310 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); |
2311 | 2311 |
2312 llvm::Value* ptr = LLVM_DtoGEP(ldval,zero,one,"tmp",p->scopebb()); | 2312 llvm::Value* ptr = DtoGEP(ldval,zero,one,"tmp",p->scopebb()); |
2313 ptr = new llvm::LoadInst(ptr,"tmp",p->scopebb()); | 2313 ptr = new llvm::LoadInst(ptr,"tmp",p->scopebb()); |
2314 new llvm::FreeInst(ptr, p->scopebb()); | 2314 new llvm::FreeInst(ptr, p->scopebb()); |
2315 LLVM_DtoNullArray(val); | 2315 DtoNullArray(val); |
2316 } | 2316 } |
2317 else { | 2317 else { |
2318 assert(0); | 2318 assert(0); |
2319 } | 2319 } |
2320 | 2320 |
2340 e->type = elem::ARRAYLEN; | 2340 e->type = elem::ARRAYLEN; |
2341 } | 2341 } |
2342 else | 2342 else |
2343 { | 2343 { |
2344 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 2344 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
2345 llvm::Value* ptr = LLVM_DtoGEP(u->mem,zero,zero,"tmp",p->scopebb()); | 2345 llvm::Value* ptr = DtoGEP(u->mem,zero,zero,"tmp",p->scopebb()); |
2346 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); | 2346 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); |
2347 e->type = elem::VAL; | 2347 e->type = elem::VAL; |
2348 } | 2348 } |
2349 delete u; | 2349 delete u; |
2350 | 2350 |
2360 | 2360 |
2361 elem* u = e1->toElem(p); | 2361 elem* u = e1->toElem(p); |
2362 elem* m = msg ? msg->toElem(p) : NULL; | 2362 elem* m = msg ? msg->toElem(p) : NULL; |
2363 | 2363 |
2364 llvm::Value* loca = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); | 2364 llvm::Value* loca = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); |
2365 LLVM_DtoAssert(u->getValue(), loca, m ? m->val : NULL); | 2365 DtoAssert(u->getValue(), loca, m ? m->val : NULL); |
2366 | 2366 |
2367 delete m; | 2367 delete m; |
2368 delete u; | 2368 delete u; |
2369 | 2369 |
2370 return new elem; | 2370 return new elem; |
2378 LOG_SCOPE; | 2378 LOG_SCOPE; |
2379 | 2379 |
2380 elem* e = new elem; | 2380 elem* e = new elem; |
2381 elem* u = e1->toElem(p); | 2381 elem* u = e1->toElem(p); |
2382 | 2382 |
2383 llvm::Value* b = LLVM_DtoBoolean(u->getValue()); | 2383 llvm::Value* b = DtoBoolean(u->getValue()); |
2384 | 2384 |
2385 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, true); | 2385 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, true); |
2386 e->val = p->ir->CreateICmpEQ(b,zero); | 2386 e->val = p->ir->CreateICmpEQ(b,zero); |
2387 //e->val = new llvm::ICmpInst(llvm::ICmpInst::ICMP_EQ,b,zero,"tmp",p->scopebb()); | 2387 //e->val = new llvm::ICmpInst(llvm::ICmpInst::ICMP_EQ,b,zero,"tmp",p->scopebb()); |
2388 e->type = elem::VAL; | 2388 e->type = elem::VAL; |
2409 | 2409 |
2410 llvm::BasicBlock* oldend = p->scopeend(); | 2410 llvm::BasicBlock* oldend = p->scopeend(); |
2411 llvm::BasicBlock* andand = new llvm::BasicBlock("andand", gIR->topfunc(), oldend); | 2411 llvm::BasicBlock* andand = new llvm::BasicBlock("andand", gIR->topfunc(), oldend); |
2412 llvm::BasicBlock* andandend = new llvm::BasicBlock("andandend", gIR->topfunc(), oldend); | 2412 llvm::BasicBlock* andandend = new llvm::BasicBlock("andandend", gIR->topfunc(), oldend); |
2413 | 2413 |
2414 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue()); | 2414 llvm::Value* ubool = DtoBoolean(u->getValue()); |
2415 new llvm::StoreInst(ubool,resval,p->scopebb()); | 2415 new llvm::StoreInst(ubool,resval,p->scopebb()); |
2416 new llvm::BranchInst(andand,andandend,ubool,p->scopebb()); | 2416 new llvm::BranchInst(andand,andandend,ubool,p->scopebb()); |
2417 | 2417 |
2418 p->scope() = IRScope(andand, andandend); | 2418 p->scope() = IRScope(andand, andandend); |
2419 elem* v = e2->toElem(p); | 2419 elem* v = e2->toElem(p); |
2420 | 2420 |
2421 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue()); | 2421 llvm::Value* vbool = DtoBoolean(v->getValue()); |
2422 llvm::Value* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); | 2422 llvm::Value* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); |
2423 new llvm::StoreInst(uandvbool,resval,p->scopebb()); | 2423 new llvm::StoreInst(uandvbool,resval,p->scopebb()); |
2424 new llvm::BranchInst(andandend,p->scopebb()); | 2424 new llvm::BranchInst(andandend,p->scopebb()); |
2425 | 2425 |
2426 delete u; | 2426 delete u; |
2451 | 2451 |
2452 llvm::BasicBlock* oldend = p->scopeend(); | 2452 llvm::BasicBlock* oldend = p->scopeend(); |
2453 llvm::BasicBlock* oror = new llvm::BasicBlock("oror", gIR->topfunc(), oldend); | 2453 llvm::BasicBlock* oror = new llvm::BasicBlock("oror", gIR->topfunc(), oldend); |
2454 llvm::BasicBlock* ororend = new llvm::BasicBlock("ororend", gIR->topfunc(), oldend); | 2454 llvm::BasicBlock* ororend = new llvm::BasicBlock("ororend", gIR->topfunc(), oldend); |
2455 | 2455 |
2456 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue()); | 2456 llvm::Value* ubool = DtoBoolean(u->getValue()); |
2457 new llvm::StoreInst(ubool,resval,p->scopebb()); | 2457 new llvm::StoreInst(ubool,resval,p->scopebb()); |
2458 new llvm::BranchInst(ororend,oror,ubool,p->scopebb()); | 2458 new llvm::BranchInst(ororend,oror,ubool,p->scopebb()); |
2459 | 2459 |
2460 p->scope() = IRScope(oror, ororend); | 2460 p->scope() = IRScope(oror, ororend); |
2461 elem* v = e2->toElem(p); | 2461 elem* v = e2->toElem(p); |
2462 | 2462 |
2463 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue()); | 2463 llvm::Value* vbool = DtoBoolean(v->getValue()); |
2464 new llvm::StoreInst(vbool,resval,p->scopebb()); | 2464 new llvm::StoreInst(vbool,resval,p->scopebb()); |
2465 new llvm::BranchInst(ororend,p->scopebb()); | 2465 new llvm::BranchInst(ororend,p->scopebb()); |
2466 | 2466 |
2467 delete u; | 2467 delete u; |
2468 delete v; | 2468 delete v; |
2502 assert(uval); \ | 2502 assert(uval); \ |
2503 llvm::Value* vval = v->getValue(); \ | 2503 llvm::Value* vval = v->getValue(); \ |
2504 assert(vval); \ | 2504 assert(vval); \ |
2505 llvm::Value* tmp = llvm::BinaryOperator::create(llvm::Instruction::Y, uval, vval, "tmp", p->scopebb()); \ | 2505 llvm::Value* tmp = llvm::BinaryOperator::create(llvm::Instruction::Y, uval, vval, "tmp", p->scopebb()); \ |
2506 if (u->mem == 0) \ | 2506 if (u->mem == 0) \ |
2507 LLVM_DtoGiveArgumentStorage(u); \ | 2507 DtoGiveArgumentStorage(u); \ |
2508 Logger::cout() << *tmp << '|' << *u->mem << '\n'; \ | 2508 Logger::cout() << *tmp << '|' << *u->mem << '\n'; \ |
2509 new llvm::StoreInst(LLVM_DtoPointedType(u->mem, tmp), u->mem, p->scopebb()); \ | 2509 new llvm::StoreInst(DtoPointedType(u->mem, tmp), u->mem, p->scopebb()); \ |
2510 delete u; \ | 2510 delete u; \ |
2511 delete v; \ | 2511 delete v; \ |
2512 elem* e = new elem; \ | 2512 elem* e = new elem; \ |
2513 e->mem = u->mem; \ | 2513 e->mem = u->mem; \ |
2514 e->type = elem::VAR; \ | 2514 e->type = elem::VAR; \ |
2528 { | 2528 { |
2529 Logger::print("HaltExp::toElem: %s | %s\n", toChars(), type->toChars()); | 2529 Logger::print("HaltExp::toElem: %s | %s\n", toChars(), type->toChars()); |
2530 LOG_SCOPE; | 2530 LOG_SCOPE; |
2531 | 2531 |
2532 llvm::Value* loca = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); | 2532 llvm::Value* loca = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); |
2533 LLVM_DtoAssert(llvm::ConstantInt::getFalse(), loca, NULL); | 2533 DtoAssert(llvm::ConstantInt::getFalse(), loca, NULL); |
2534 | 2534 |
2535 new llvm::UnreachableInst(p->scopebb()); | 2535 new llvm::UnreachableInst(p->scopebb()); |
2536 return 0; | 2536 return 0; |
2537 } | 2537 } |
2538 | 2538 |
2552 const llvm::Type* int8ptrty = llvm::PointerType::get(llvm::Type::Int8Ty); | 2552 const llvm::Type* int8ptrty = llvm::PointerType::get(llvm::Type::Int8Ty); |
2553 | 2553 |
2554 assert(p->topexp() && p->topexp()->e2 == this && p->topexp()->v); | 2554 assert(p->topexp() && p->topexp()->e2 == this && p->topexp()->v); |
2555 llvm::Value* lval = p->topexp()->v; | 2555 llvm::Value* lval = p->topexp()->v; |
2556 | 2556 |
2557 llvm::Value* context = LLVM_DtoGEP(lval,zero,zero,"tmp",p->scopebb()); | 2557 llvm::Value* context = DtoGEP(lval,zero,zero,"tmp",p->scopebb()); |
2558 llvm::Value* castcontext = new llvm::BitCastInst(u->getValue(),int8ptrty,"tmp",p->scopebb()); | 2558 llvm::Value* castcontext = new llvm::BitCastInst(u->getValue(),int8ptrty,"tmp",p->scopebb()); |
2559 new llvm::StoreInst(castcontext, context, p->scopebb()); | 2559 new llvm::StoreInst(castcontext, context, p->scopebb()); |
2560 | 2560 |
2561 llvm::Value* fptr = LLVM_DtoGEP(lval,zero,one,"tmp",p->scopebb()); | 2561 llvm::Value* fptr = DtoGEP(lval,zero,one,"tmp",p->scopebb()); |
2562 | 2562 |
2563 assert(func->llvmValue); | 2563 assert(func->llvmValue); |
2564 llvm::Value* castfptr = new llvm::BitCastInst(func->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); | 2564 llvm::Value* castfptr = new llvm::BitCastInst(func->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); |
2565 new llvm::StoreInst(castfptr, fptr, p->scopebb()); | 2565 new llvm::StoreInst(castfptr, fptr, p->scopebb()); |
2566 | 2566 |
2583 elem* e = new elem; | 2583 elem* e = new elem; |
2584 | 2584 |
2585 llvm::Value* l = u->field ? u->mem : u->getValue(); | 2585 llvm::Value* l = u->field ? u->mem : u->getValue(); |
2586 llvm::Value* r = v->field ? v->mem : v->getValue(); | 2586 llvm::Value* r = v->field ? v->mem : v->getValue(); |
2587 | 2587 |
2588 Type* t1 = LLVM_DtoDType(e1->type); | 2588 Type* t1 = DtoDType(e1->type); |
2589 | 2589 |
2590 if (t1->ty == Tarray) { | 2590 if (t1->ty == Tarray) { |
2591 if (v->type == elem::NUL) { | 2591 if (v->type == elem::NUL) { |
2592 r = NULL; | 2592 r = NULL; |
2593 } | 2593 } |
2594 else { | 2594 else { |
2595 assert(l->getType() == r->getType()); | 2595 assert(l->getType() == r->getType()); |
2596 } | 2596 } |
2597 e->val = LLVM_DtoDynArrayIs(op,l,r); | 2597 e->val = DtoDynArrayIs(op,l,r); |
2598 } | 2598 } |
2599 else { | 2599 else { |
2600 llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE; | 2600 llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE; |
2601 if (t1->ty == Tpointer && v->type == elem::NUL && l->getType() != r->getType()) { | 2601 if (t1->ty == Tpointer && v->type == elem::NUL && l->getType() != r->getType()) { |
2602 r = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(l->getType())); | 2602 r = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(l->getType())); |
2630 elem* CondExp::toElem(IRState* p) | 2630 elem* CondExp::toElem(IRState* p) |
2631 { | 2631 { |
2632 Logger::print("CondExp::toElem: %s | %s\n", toChars(), type->toChars()); | 2632 Logger::print("CondExp::toElem: %s | %s\n", toChars(), type->toChars()); |
2633 LOG_SCOPE; | 2633 LOG_SCOPE; |
2634 | 2634 |
2635 Type* dtype = LLVM_DtoDType(type); | 2635 Type* dtype = DtoDType(type); |
2636 const llvm::Type* resty = LLVM_DtoType(dtype); | 2636 const llvm::Type* resty = DtoType(dtype); |
2637 | 2637 |
2638 // allocate a temporary for the final result. failed to come up with a better way :/ | 2638 // allocate a temporary for the final result. failed to come up with a better way :/ |
2639 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | 2639 llvm::BasicBlock* entryblock = &p->topfunc()->front(); |
2640 llvm::Value* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint()); | 2640 llvm::Value* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint()); |
2641 | 2641 |
2643 llvm::BasicBlock* condtrue = new llvm::BasicBlock("condtrue", gIR->topfunc(), oldend); | 2643 llvm::BasicBlock* condtrue = new llvm::BasicBlock("condtrue", gIR->topfunc(), oldend); |
2644 llvm::BasicBlock* condfalse = new llvm::BasicBlock("condfalse", gIR->topfunc(), oldend); | 2644 llvm::BasicBlock* condfalse = new llvm::BasicBlock("condfalse", gIR->topfunc(), oldend); |
2645 llvm::BasicBlock* condend = new llvm::BasicBlock("condend", gIR->topfunc(), oldend); | 2645 llvm::BasicBlock* condend = new llvm::BasicBlock("condend", gIR->topfunc(), oldend); |
2646 | 2646 |
2647 elem* c = econd->toElem(p); | 2647 elem* c = econd->toElem(p); |
2648 llvm::Value* cond_val = LLVM_DtoBoolean(c->getValue()); | 2648 llvm::Value* cond_val = DtoBoolean(c->getValue()); |
2649 delete c; | 2649 delete c; |
2650 new llvm::BranchInst(condtrue,condfalse,cond_val,p->scopebb()); | 2650 new llvm::BranchInst(condtrue,condfalse,cond_val,p->scopebb()); |
2651 | 2651 |
2652 p->scope() = IRScope(condtrue, condfalse); | 2652 p->scope() = IRScope(condtrue, condfalse); |
2653 elem* u = e1->toElem(p); | 2653 elem* u = e1->toElem(p); |
2654 LLVM_DtoAssign(dtype, resval, u->getValue()); | 2654 DtoAssign(dtype, resval, u->getValue()); |
2655 new llvm::BranchInst(condend,p->scopebb()); | 2655 new llvm::BranchInst(condend,p->scopebb()); |
2656 delete u; | 2656 delete u; |
2657 | 2657 |
2658 p->scope() = IRScope(condfalse, condend); | 2658 p->scope() = IRScope(condfalse, condend); |
2659 elem* v = e2->toElem(p); | 2659 elem* v = e2->toElem(p); |
2660 LLVM_DtoAssign(dtype, resval, v->getValue()); | 2660 DtoAssign(dtype, resval, v->getValue()); |
2661 new llvm::BranchInst(condend,p->scopebb()); | 2661 new llvm::BranchInst(condend,p->scopebb()); |
2662 delete v; | 2662 delete v; |
2663 | 2663 |
2664 p->scope() = IRScope(condend, oldend); | 2664 p->scope() = IRScope(condend, oldend); |
2665 | 2665 |
2699 elem* e = new elem; | 2699 elem* e = new elem; |
2700 elem* l = e1->toElem(p); | 2700 elem* l = e1->toElem(p); |
2701 llvm::Value* val = l->getValue(); | 2701 llvm::Value* val = l->getValue(); |
2702 delete l; | 2702 delete l; |
2703 | 2703 |
2704 Type* t = LLVM_DtoDType(type); | 2704 Type* t = DtoDType(type); |
2705 | 2705 |
2706 llvm::Value* zero = 0; | 2706 llvm::Value* zero = 0; |
2707 if (t->isintegral()) | 2707 if (t->isintegral()) |
2708 zero = llvm::ConstantInt::get(val->getType(), 0, true); | 2708 zero = llvm::ConstantInt::get(val->getType(), 0, true); |
2709 else if (t->isfloating()) { | 2709 else if (t->isfloating()) { |
2728 elem* CatExp::toElem(IRState* p) | 2728 elem* CatExp::toElem(IRState* p) |
2729 { | 2729 { |
2730 Logger::print("CatExp::toElem: %s | %s\n", toChars(), type->toChars()); | 2730 Logger::print("CatExp::toElem: %s | %s\n", toChars(), type->toChars()); |
2731 LOG_SCOPE; | 2731 LOG_SCOPE; |
2732 | 2732 |
2733 Type* t = LLVM_DtoDType(type); | 2733 Type* t = DtoDType(type); |
2734 | 2734 |
2735 bool inplace = false; | 2735 bool inplace = false; |
2736 llvm::Value* dst = 0; | 2736 llvm::Value* dst = 0; |
2737 IRExp* ex = p->topexp(); | 2737 IRExp* ex = p->topexp(); |
2738 if (ex && ex->e2 == this) { | 2738 if (ex && ex->e2 == this) { |
2740 dst = ex->v; | 2740 dst = ex->v; |
2741 inplace = true; | 2741 inplace = true; |
2742 } | 2742 } |
2743 else { | 2743 else { |
2744 assert(t->ty == Tarray); | 2744 assert(t->ty == Tarray); |
2745 const llvm::Type* arrty = LLVM_DtoType(t); | 2745 const llvm::Type* arrty = DtoType(t); |
2746 dst = new llvm::AllocaInst(arrty, "tmpmem", p->topallocapoint()); | 2746 dst = new llvm::AllocaInst(arrty, "tmpmem", p->topallocapoint()); |
2747 } | 2747 } |
2748 | 2748 |
2749 LLVM_DtoCatArrays(dst,e1,e2); | 2749 DtoCatArrays(dst,e1,e2); |
2750 | 2750 |
2751 elem* e = new elem; | 2751 elem* e = new elem; |
2752 e->mem = dst; | 2752 e->mem = dst; |
2753 e->type = elem::VAR; | 2753 e->type = elem::VAR; |
2754 e->inplace = inplace; | 2754 e->inplace = inplace; |
2764 LOG_SCOPE; | 2764 LOG_SCOPE; |
2765 | 2765 |
2766 elem* l = e1->toElem(p); | 2766 elem* l = e1->toElem(p); |
2767 assert(l->mem); | 2767 assert(l->mem); |
2768 | 2768 |
2769 Type* e1type = LLVM_DtoDType(e1->type); | 2769 Type* e1type = DtoDType(e1->type); |
2770 Type* elemtype = LLVM_DtoDType(e1type->next); | 2770 Type* elemtype = DtoDType(e1type->next); |
2771 Type* e2type = LLVM_DtoDType(e2->type); | 2771 Type* e2type = DtoDType(e2->type); |
2772 | 2772 |
2773 if (e2type == elemtype) { | 2773 if (e2type == elemtype) { |
2774 LLVM_DtoCatAssignElement(l->mem,e2); | 2774 DtoCatAssignElement(l->mem,e2); |
2775 } | 2775 } |
2776 else | 2776 else |
2777 assert(0 && "only one element at a time right now"); | 2777 assert(0 && "only one element at a time right now"); |
2778 | 2778 |
2779 return 0; | 2779 return 0; |
2784 elem* ArrayLiteralExp::toElem(IRState* p) | 2784 elem* ArrayLiteralExp::toElem(IRState* p) |
2785 { | 2785 { |
2786 Logger::print("ArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); | 2786 Logger::print("ArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); |
2787 LOG_SCOPE; | 2787 LOG_SCOPE; |
2788 | 2788 |
2789 const llvm::Type* t = LLVM_DtoType(type); | 2789 const llvm::Type* t = DtoType(type); |
2790 Logger::cout() << "array literal has llvm type: " << *t << '\n'; | 2790 Logger::cout() << "array literal has llvm type: " << *t << '\n'; |
2791 | 2791 |
2792 llvm::Value* mem = 0; | 2792 llvm::Value* mem = 0; |
2793 if (!p->topexp() || p->topexp()->e2 != this) { | 2793 if (!p->topexp() || p->topexp()->e2 != this) { |
2794 assert(LLVM_DtoDType(type)->ty == Tsarray); | 2794 assert(DtoDType(type)->ty == Tsarray); |
2795 mem = new llvm::AllocaInst(t,"tmparrayliteral",p->topallocapoint()); | 2795 mem = new llvm::AllocaInst(t,"tmparrayliteral",p->topallocapoint()); |
2796 } | 2796 } |
2797 else if (p->topexp()->e2 == this) { | 2797 else if (p->topexp()->e2 == this) { |
2798 mem = p->topexp()->v; | 2798 mem = p->topexp()->v; |
2799 assert(mem); | 2799 assert(mem); |
2808 assert(0); | 2808 assert(0); |
2809 | 2809 |
2810 for (unsigned i=0; i<elements->dim; ++i) | 2810 for (unsigned i=0; i<elements->dim; ++i) |
2811 { | 2811 { |
2812 Expression* expr = (Expression*)elements->data[i]; | 2812 Expression* expr = (Expression*)elements->data[i]; |
2813 llvm::Value* elemAddr = LLVM_DtoGEPi(mem,0,i,"tmp",p->scopebb()); | 2813 llvm::Value* elemAddr = DtoGEPi(mem,0,i,"tmp",p->scopebb()); |
2814 elem* e = expr->toElem(p); | 2814 elem* e = expr->toElem(p); |
2815 new llvm::StoreInst(e->getValue(), elemAddr, p->scopebb()); | 2815 new llvm::StoreInst(e->getValue(), elemAddr, p->scopebb()); |
2816 } | 2816 } |
2817 | 2817 |
2818 elem* e = new elem; | 2818 elem* e = new elem; |
2828 llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p) | 2828 llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p) |
2829 { | 2829 { |
2830 Logger::print("ArrayLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | 2830 Logger::print("ArrayLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); |
2831 LOG_SCOPE; | 2831 LOG_SCOPE; |
2832 | 2832 |
2833 const llvm::Type* t = LLVM_DtoType(type); | 2833 const llvm::Type* t = DtoType(type); |
2834 Logger::cout() << "array literal has llvm type: " << *t << '\n'; | 2834 Logger::cout() << "array literal has llvm type: " << *t << '\n'; |
2835 assert(llvm::isa<llvm::ArrayType>(t)); | 2835 assert(llvm::isa<llvm::ArrayType>(t)); |
2836 const llvm::ArrayType* arrtype = llvm::cast<llvm::ArrayType>(t); | 2836 const llvm::ArrayType* arrtype = llvm::cast<llvm::ArrayType>(t); |
2837 | 2837 |
2838 assert(arrtype->getNumElements() == elements->dim); | 2838 assert(arrtype->getNumElements() == elements->dim); |
2860 | 2860 |
2861 fd->toObjFile(); | 2861 fd->toObjFile(); |
2862 | 2862 |
2863 llvm::Value* lval = NULL; | 2863 llvm::Value* lval = NULL; |
2864 if (!p->topexp() || p->topexp()->e2 != this) { | 2864 if (!p->topexp() || p->topexp()->e2 != this) { |
2865 const llvm::Type* dgty = LLVM_DtoType(type); | 2865 const llvm::Type* dgty = DtoType(type); |
2866 Logger::cout() << "delegate without explicit storage:" << '\n' << *dgty << '\n'; | 2866 Logger::cout() << "delegate without explicit storage:" << '\n' << *dgty << '\n'; |
2867 lval = new llvm::AllocaInst(dgty,"dgstorage",p->topallocapoint()); | 2867 lval = new llvm::AllocaInst(dgty,"dgstorage",p->topallocapoint()); |
2868 } | 2868 } |
2869 else if (p->topexp()->e2 == this) { | 2869 else if (p->topexp()->e2 == this) { |
2870 lval = p->topexp()->v; | 2870 lval = p->topexp()->v; |
2873 else | 2873 else |
2874 assert(0); | 2874 assert(0); |
2875 | 2875 |
2876 elem* e = new elem; | 2876 elem* e = new elem; |
2877 | 2877 |
2878 llvm::Value* context = LLVM_DtoGEPi(lval,0,0,"tmp",p->scopebb()); | 2878 llvm::Value* context = DtoGEPi(lval,0,0,"tmp",p->scopebb()); |
2879 const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(context->getType()->getContainedType(0)); | 2879 const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(context->getType()->getContainedType(0)); |
2880 llvm::Value* llvmNested = p->func().decl->llvmNested; | 2880 llvm::Value* llvmNested = p->func().decl->llvmNested; |
2881 if (llvmNested == NULL) { | 2881 if (llvmNested == NULL) { |
2882 llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty); | 2882 llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty); |
2883 p->ir->CreateStore(nullcontext, context); | 2883 p->ir->CreateStore(nullcontext, context); |
2885 else { | 2885 else { |
2886 llvm::Value* nestedcontext = p->ir->CreateBitCast(llvmNested, pty, "tmp"); | 2886 llvm::Value* nestedcontext = p->ir->CreateBitCast(llvmNested, pty, "tmp"); |
2887 p->ir->CreateStore(nestedcontext, context); | 2887 p->ir->CreateStore(nestedcontext, context); |
2888 } | 2888 } |
2889 | 2889 |
2890 llvm::Value* fptr = LLVM_DtoGEPi(lval,0,1,"tmp",p->scopebb()); | 2890 llvm::Value* fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb()); |
2891 | 2891 |
2892 assert(fd->llvmValue); | 2892 assert(fd->llvmValue); |
2893 llvm::Value* castfptr = new llvm::BitCastInst(fd->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); | 2893 llvm::Value* castfptr = new llvm::BitCastInst(fd->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); |
2894 new llvm::StoreInst(castfptr, fptr, p->scopebb()); | 2894 new llvm::StoreInst(castfptr, fptr, p->scopebb()); |
2895 | 2895 |