Mercurial > projects > ldc
comparison gen/toir.cpp @ 92:70d6113eeb8c trunk
[svn r96] Updated to DMD 1.023.
Regular bugfixes.
author | lindquist |
---|---|
date | Thu, 08 Nov 2007 19:13:28 +0100 |
parents | 3f949c6e2e9d |
children | 61615fa85940 |
comparison
equal
deleted
inserted
replaced
91:3f949c6e2e9d | 92:70d6113eeb8c |
---|---|
64 const llvm::Type* lltype = DtoType(vd->type); | 64 const llvm::Type* lltype = DtoType(vd->type); |
65 llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); | 65 llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); |
66 //allocainst->setAlignment(vd->type->alignsize()); // TODO | 66 //allocainst->setAlignment(vd->type->alignsize()); // TODO |
67 vd->llvmValue = allocainst; | 67 vd->llvmValue = allocainst; |
68 } | 68 } |
69 DValue* ie = DtoInitializer(vd->init); | 69 DVarValue* vv = new DVarValue(type, vd->llvmValue, true); |
70 DValue* ie = DtoInitializer(vd->init, vv); | |
70 delete ie; | 71 delete ie; |
71 } | 72 } |
72 | 73 |
73 return new DVarValue(vd, vd->llvmValue, true); | 74 return new DVarValue(vd, vd->llvmValue, true); |
74 } | 75 } |
320 | 321 |
321 DValue* ComplexExp::toElem(IRState* p) | 322 DValue* ComplexExp::toElem(IRState* p) |
322 { | 323 { |
323 Logger::print("ComplexExp::toElem(): %s | %s\n", toChars(), type->toChars()); | 324 Logger::print("ComplexExp::toElem(): %s | %s\n", toChars(), type->toChars()); |
324 LOG_SCOPE; | 325 LOG_SCOPE; |
325 assert(0); | 326 assert(0 && "no complex yet"); |
326 } | 327 } |
327 | 328 |
328 ////////////////////////////////////////////////////////////////////////////////////////// | 329 ////////////////////////////////////////////////////////////////////////////////////////// |
329 | 330 |
330 llvm::Constant* ComplexExp::toConstElem(IRState* p) | 331 llvm::Constant* ComplexExp::toConstElem(IRState* p) |
331 { | 332 { |
332 Logger::print("ComplexExp::toConstElem(): %s | %s\n", toChars(), type->toChars()); | 333 Logger::print("ComplexExp::toConstElem(): %s | %s\n", toChars(), type->toChars()); |
333 LOG_SCOPE; | 334 LOG_SCOPE; |
334 assert(0); | 335 assert(0 && "no complex yet"); |
335 } | 336 } |
336 | 337 |
337 ////////////////////////////////////////////////////////////////////////////////////////// | 338 ////////////////////////////////////////////////////////////////////////////////////////// |
338 | 339 |
339 DValue* StringExp::toElem(IRState* p) | 340 DValue* StringExp::toElem(IRState* p) |
460 p->topexp()->v = l; | 461 p->topexp()->v = l; |
461 DValue* r = e2->toElem(p); | 462 DValue* r = e2->toElem(p); |
462 | 463 |
463 p->exps.pop_back(); | 464 p->exps.pop_back(); |
464 | 465 |
465 if (l->isArrayLen()) | 466 DImValue* im = r->isIm(); |
466 DtoResizeDynArray(l->getLVal(), r->getRVal()); | 467 if (!im || !im->inPlace()) { |
467 else | 468 if (l->isArrayLen()) |
468 DtoAssign(l, r); | 469 DtoResizeDynArray(l->getLVal(), r->getRVal()); |
470 else | |
471 DtoAssign(l, r); | |
472 } | |
473 | |
469 return l; | 474 return l; |
470 | 475 |
471 /* | 476 /* |
472 if (l->type == DValue::ARRAYLEN) | 477 if (l->type == DValue::ARRAYLEN) |
473 { | 478 { |
637 DValue* l = e1->toElem(p); | 642 DValue* l = e1->toElem(p); |
638 DValue* r = e2->toElem(p); | 643 DValue* r = e2->toElem(p); |
639 | 644 |
640 Type* t = DtoDType(type); | 645 Type* t = DtoDType(type); |
641 Type* e1type = DtoDType(e1->type); | 646 Type* e1type = DtoDType(e1->type); |
647 Type* e1next = e1type->next ? DtoDType(e1type->next) : NULL; | |
642 Type* e2type = DtoDType(e2->type); | 648 Type* e2type = DtoDType(e2->type); |
643 | 649 |
644 if (e1type != e2type) { | 650 if (e1type != e2type) { |
645 if (e1type->ty == Tpointer && e1type->next->ty == Tstruct) { | 651 if (e1type->ty == Tpointer && e1next && e1next->ty == Tstruct) { |
652 Logger::println("add to AddrExp of struct"); | |
646 assert(r->isConst()); | 653 assert(r->isConst()); |
647 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c); | 654 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c); |
648 | 655 |
649 TypeStruct* ts = (TypeStruct*)e1type->next; | 656 TypeStruct* ts = (TypeStruct*)e1next; |
650 std::vector<unsigned> offsets; | 657 std::vector<unsigned> offsets; |
651 llvm::Value* v = DtoIndexStruct(l->getRVal(), ts->sym, t->next, cofs->getZExtValue(), offsets); | 658 llvm::Value* v = DtoIndexStruct(l->getRVal(), ts->sym, t->next, cofs->getZExtValue(), offsets); |
652 return new DFieldValue(type, v, true); | 659 return new DFieldValue(type, v, true); |
653 } | 660 } |
654 else if (e1->type->ty == Tpointer) { | 661 else if (e1type->ty == Tpointer) { |
662 Logger::println("add to AddrExp of struct"); | |
655 llvm::Value* v = new llvm::GetElementPtrInst(l->getRVal(), r->getRVal(), "tmp", p->scopebb()); | 663 llvm::Value* v = new llvm::GetElementPtrInst(l->getRVal(), r->getRVal(), "tmp", p->scopebb()); |
656 return new DImValue(type, v); | 664 return new DImValue(type, v); |
657 } | 665 } |
658 assert(0); | 666 assert(0); |
659 } | 667 } |
2665 DValue* ArrayLiteralExp::toElem(IRState* p) | 2673 DValue* ArrayLiteralExp::toElem(IRState* p) |
2666 { | 2674 { |
2667 Logger::print("ArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); | 2675 Logger::print("ArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); |
2668 LOG_SCOPE; | 2676 LOG_SCOPE; |
2669 | 2677 |
2670 const llvm::Type* t = DtoType(type); | 2678 Type* ty = DtoDType(type); |
2679 const llvm::Type* t = DtoType(ty); | |
2671 Logger::cout() << "array literal has llvm type: " << *t << '\n'; | 2680 Logger::cout() << "array literal has llvm type: " << *t << '\n'; |
2672 | 2681 |
2673 llvm::Value* mem = 0; | 2682 llvm::Value* mem = 0; |
2674 if (!p->topexp() || p->topexp()->e2 != this) { | 2683 if (!p->topexp() || p->topexp()->e2 != this) { |
2675 assert(DtoDType(type)->ty == Tsarray); | 2684 assert(DtoDType(type)->ty == Tsarray); |
2676 mem = new llvm::AllocaInst(t,"tmparrayliteral",p->topallocapoint()); | 2685 mem = new llvm::AllocaInst(t,"arrayliteral",p->topallocapoint()); |
2677 } | 2686 } |
2678 else if (p->topexp()->e2 == this) { | 2687 else if (p->topexp()->e2 == this) { |
2679 DValue* tlv = p->topexp()->v; | 2688 DValue* tlv = p->topexp()->v; |
2680 if (DSliceValue* sv = tlv->isSlice()) { | 2689 if (DSliceValue* sv = tlv->isSlice()) { |
2681 assert(sv->len == 0); | 2690 assert(sv->len == 0); |
2686 } | 2695 } |
2687 assert(mem); | 2696 assert(mem); |
2688 if (!llvm::isa<llvm::PointerType>(mem->getType()) || | 2697 if (!llvm::isa<llvm::PointerType>(mem->getType()) || |
2689 !llvm::isa<llvm::ArrayType>(mem->getType()->getContainedType(0))) | 2698 !llvm::isa<llvm::ArrayType>(mem->getType()->getContainedType(0))) |
2690 { | 2699 { |
2691 error("TODO array literals can currently only be used to initialise static arrays"); | 2700 assert(ty->ty == Tarray); |
2692 fatal(); | 2701 // we need to give this array literal storage |
2702 const llvm::ArrayType* arrty = llvm::ArrayType::get(DtoType(ty->next), elements->dim); | |
2703 mem = new llvm::AllocaInst(arrty, "arrayliteral", p->topallocapoint()); | |
2693 } | 2704 } |
2694 } | 2705 } |
2695 else | 2706 else |
2696 assert(0); | 2707 assert(0); |
2697 | 2708 |
2701 llvm::Value* elemAddr = DtoGEPi(mem,0,i,"tmp",p->scopebb()); | 2712 llvm::Value* elemAddr = DtoGEPi(mem,0,i,"tmp",p->scopebb()); |
2702 DValue* e = expr->toElem(p); | 2713 DValue* e = expr->toElem(p); |
2703 new llvm::StoreInst(e->getRVal(), elemAddr, p->scopebb()); | 2714 new llvm::StoreInst(e->getRVal(), elemAddr, p->scopebb()); |
2704 } | 2715 } |
2705 | 2716 |
2706 return new DImValue(type, mem, true); | 2717 if (ty->ty == Tsarray) |
2718 return new DImValue(type, mem, true); | |
2719 else if (ty->ty == Tarray) | |
2720 return new DSliceValue(type, DtoConstSize_t(elements->dim), DtoGEPi(mem,0,0,"tmp")); | |
2721 else { | |
2722 assert(0); | |
2723 return 0; | |
2724 } | |
2707 } | 2725 } |
2708 | 2726 |
2709 ////////////////////////////////////////////////////////////////////////////////////////// | 2727 ////////////////////////////////////////////////////////////////////////////////////////// |
2710 | 2728 |
2711 llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p) | 2729 llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p) |
2895 //STUB(HaltExp); | 2913 //STUB(HaltExp); |
2896 STUB(RemoveExp); | 2914 STUB(RemoveExp); |
2897 //STUB(ArrayLiteralExp); | 2915 //STUB(ArrayLiteralExp); |
2898 STUB(AssocArrayLiteralExp); | 2916 STUB(AssocArrayLiteralExp); |
2899 //STUB(StructLiteralExp); | 2917 //STUB(StructLiteralExp); |
2918 STUB(TupleExp); | |
2900 | 2919 |
2901 #define CONSTSTUB(x) llvm::Constant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); fatal(); return NULL; } | 2920 #define CONSTSTUB(x) llvm::Constant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); fatal(); return NULL; } |
2902 CONSTSTUB(Expression); | 2921 CONSTSTUB(Expression); |
2903 //CONSTSTUB(IntegerExp); | 2922 //CONSTSTUB(IntegerExp); |
2904 //CONSTSTUB(RealExp); | 2923 //CONSTSTUB(RealExp); |