comparison gen/arrays.c @ 54:28e99b04a132 trunk

[svn r58] Fixed cond expression resulting in a non-basic type. Fixed identity expression for dynamic arrays. Revamped the system to keep track of lvalues and rvalues and their relations. Typedef declaration now generate the custom typeinfo. Other bugfixes.
author lindquist
date Wed, 24 Oct 2007 01:37:34 +0200
parents 0c77619e803b
children 2c3cd3596187
comparison
equal deleted inserted replaced
53:06ccc817acd4 54:28e99b04a132
98 ptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb()); 98 ptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
99 new llvm::StoreInst(val, ptr, gIR->scopebb()); 99 new llvm::StoreInst(val, ptr, gIR->scopebb());
100 } 100 }
101 else 101 else
102 { 102 {
103 Logger::cout() << "array assignment type dont match: " << *dst->getType() << '\n' << *src->getType() << '\n';
103 if (!llvm::isa<llvm::ArrayType>(src->getType()->getContainedType(0))) 104 if (!llvm::isa<llvm::ArrayType>(src->getType()->getContainedType(0)))
104 { 105 {
105 Logger::cout() << "invalid: " << *src << '\n'; 106 Logger::cout() << "invalid: " << *src << '\n';
106 assert(0); 107 assert(0);
107 } 108 }
108 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(src->getType()->getContainedType(0)); 109 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(src->getType()->getContainedType(0));
109 llvm::Type* dstty = llvm::PointerType::get(arrty->getElementType()); 110 llvm::Type* dstty = llvm::PointerType::get(arrty->getElementType());
110 111
111 llvm::Value* dstlen = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); 112 llvm::Value* dstlen = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
112 llvm::Value* srclen = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrty->getNumElements(), false); 113 llvm::Value* srclen = LLVM_DtoConstSize_t(arrty->getNumElements());
113 new llvm::StoreInst(srclen, dstlen, gIR->scopebb()); 114 new llvm::StoreInst(srclen, dstlen, gIR->scopebb());
114 115
115 llvm::Value* dstptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb()); 116 llvm::Value* dstptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
116 llvm::Value* srcptr = new llvm::BitCastInst(src,dstty,"tmp",gIR->scopebb()); 117 llvm::Value* srcptr = new llvm::BitCastInst(src,dstty,"tmp",gIR->scopebb());
117 new llvm::StoreInst(srcptr, dstptr, gIR->scopebb()); 118 new llvm::StoreInst(srcptr, dstptr, gIR->scopebb());
549 args.push_back(len); 550 args.push_back(len);
550 args.push_back(llvm::ConstantInt::get(LLVM_DtoSize_t(), gTargetData->getTypeSize(elemty), false)); 551 args.push_back(llvm::ConstantInt::get(LLVM_DtoSize_t(), gTargetData->getTypeSize(elemty), false));
551 args.push_back(llvm::ConstantInt::get(LLVM_DtoSize_t(), gTargetData->getTypeSize(newelemty), false)); 552 args.push_back(llvm::ConstantInt::get(LLVM_DtoSize_t(), gTargetData->getTypeSize(newelemty), false));
552 return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb()); 553 return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb());
553 } 554 }
555
556 //////////////////////////////////////////////////////////////////////////////////////////
557 llvm::Value* LLVM_DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
558 {
559 assert(l->getType() == r->getType());
560
561 llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
562
563 llvm::Value* ll = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,0, "tmp"),"tmp");
564 llvm::Value* rl = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,0, "tmp"),"tmp");
565 llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
566
567 llvm::Value* lp = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,1, "tmp"),"tmp");
568 llvm::Value* rp = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,1, "tmp"),"tmp");
569 llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
570
571 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
572 if (op == TOKnotidentity)
573 return gIR->ir->CreateNot(b,"tmp");
574 else
575 return b;
576 }