comparison gen/tollvm.cpp @ 719:7261ff0f95ff

Implemented first class delegates. closes #101
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 22 Oct 2008 21:50:08 +0200
parents 30b42a283c8e
children 55f6c2e454d7
comparison
equal deleted inserted replaced
718:72ee105be27b 719:7261ff0f95ff
23 23
24 bool DtoIsPassedByRef(Type* type) 24 bool DtoIsPassedByRef(Type* type)
25 { 25 {
26 Type* typ = type->toBasetype(); 26 Type* typ = type->toBasetype();
27 TY t = typ->ty; 27 TY t = typ->ty;
28 return (t == Tstruct || t == Tdelegate || t == Tsarray); 28 return (t == Tstruct || t == Tsarray);
29 } 29 }
30 30
31 bool DtoIsReturnedInArg(Type* type) 31 bool DtoIsReturnedInArg(Type* type)
32 { 32 {
33 Type* typ = type->toBasetype(); 33 Type* typ = type->toBasetype();
34 TY t = typ->ty; 34 TY t = typ->ty;
35 return (t == Tstruct || t == Tdelegate || t == Tsarray); 35 return (t == Tstruct || t == Tsarray);
36 } 36 }
37 37
38 unsigned DtoShouldExtend(Type* type) 38 unsigned DtoShouldExtend(Type* type)
39 { 39 {
40 type = type->toBasetype(); 40 type = type->toBasetype();
219 219
220 ////////////////////////////////////////////////////////////////////////////////////////// 220 //////////////////////////////////////////////////////////////////////////////////////////
221 221
222 const LLStructType* DtoDelegateType(Type* t) 222 const LLStructType* DtoDelegateType(Type* t)
223 { 223 {
224 assert(t->ty == Tdelegate);
224 const LLType* i8ptr = getVoidPtrType(); 225 const LLType* i8ptr = getVoidPtrType();
225 const LLType* func = DtoFunctionType(t->next, NULL, i8ptr); 226 const LLType* func = DtoFunctionType(t->next, NULL, i8ptr);
226 const LLType* funcptr = getPtrToType(func); 227 const LLType* funcptr = getPtrToType(func);
227 return LLStructType::get(i8ptr, funcptr, 0); 228 return LLStructType::get(i8ptr, funcptr, 0);
228 } 229 }
233 { 234 {
234 Logger::println("Doing delegate equality"); 235 Logger::println("Doing delegate equality");
235 llvm::Value *b1, *b2; 236 llvm::Value *b1, *b2;
236 if (rhs == NULL) 237 if (rhs == NULL)
237 { 238 {
238 LLValue* l = DtoLoad(DtoGEPi(lhs,0,0)); 239 rhs = LLConstant::getNullValue(lhs->getType());
239 LLValue* r = llvm::Constant::getNullValue(l->getType()); 240 }
240 b1 = gIR->ir->CreateICmp(llvm::ICmpInst::ICMP_EQ,l,r,"tmp"); 241
241 l = DtoLoad(DtoGEPi(lhs,0,1)); 242 LLValue* l = gIR->ir->CreateExtractValue(lhs, 0);
242 r = llvm::Constant::getNullValue(l->getType()); 243 LLValue* r = gIR->ir->CreateExtractValue(rhs, 0);
243 b2 = gIR->ir->CreateICmp(llvm::ICmpInst::ICMP_EQ,l,r,"tmp"); 244 b1 = gIR->ir->CreateICmp(llvm::ICmpInst::ICMP_EQ,l,r,"tmp");
244 } 245
245 else 246 l = gIR->ir->CreateExtractValue(lhs, 1);
246 { 247 r = gIR->ir->CreateExtractValue(rhs, 1);
247 LLValue* l = DtoLoad(DtoGEPi(lhs,0,0)); 248 b2 = gIR->ir->CreateICmp(llvm::ICmpInst::ICMP_EQ,l,r,"tmp");
248 LLValue* r = DtoLoad(DtoGEPi(rhs,0,0)); 249
249 b1 = gIR->ir->CreateICmp(llvm::ICmpInst::ICMP_EQ,l,r,"tmp");
250 l = DtoLoad(DtoGEPi(lhs,0,1));
251 r = DtoLoad(DtoGEPi(rhs,0,1));
252 b2 = gIR->ir->CreateICmp(llvm::ICmpInst::ICMP_EQ,l,r,"tmp");
253 }
254 LLValue* b = gIR->ir->CreateAnd(b1,b2,"tmp"); 250 LLValue* b = gIR->ir->CreateAnd(b1,b2,"tmp");
251
255 if (op == TOKnotequal || op == TOKnotidentity) 252 if (op == TOKnotequal || op == TOKnotidentity)
256 return gIR->ir->CreateNot(b,"tmp"); 253 return gIR->ir->CreateNot(b,"tmp");
254
257 return b; 255 return b;
258 } 256 }
259 257
260 ////////////////////////////////////////////////////////////////////////////////////////// 258 //////////////////////////////////////////////////////////////////////////////////////////
261 259
555 553
556 ////////////////////////////////////////////////////////////////////////////////////////// 554 //////////////////////////////////////////////////////////////////////////////////////////
557 555
558 LLValue* DtoLoad(LLValue* src, const char* name) 556 LLValue* DtoLoad(LLValue* src, const char* name)
559 { 557 {
560 if (Logger::enabled()) 558 // if (Logger::enabled())
561 Logger::cout() << "loading " << *src << '\n'; 559 // Logger::cout() << "loading " << *src << '\n';
562 LLValue* ld = gIR->ir->CreateLoad(src, name ? name : "tmp"); 560 LLValue* ld = gIR->ir->CreateLoad(src, name ? name : "tmp");
563 //ld->setVolatile(gIR->func()->inVolatile); 561 //ld->setVolatile(gIR->func()->inVolatile);
564 return ld; 562 return ld;
565 } 563 }
566 564
567 void DtoStore(LLValue* src, LLValue* dst) 565 void DtoStore(LLValue* src, LLValue* dst)
568 { 566 {
569 if (Logger::enabled()) 567 // if (Logger::enabled())
570 Logger::cout() << "storing " << *src << " into " << *dst << '\n'; 568 // Logger::cout() << "storing " << *src << " into " << *dst << '\n';
571 LLValue* st = gIR->ir->CreateStore(src,dst); 569 LLValue* st = gIR->ir->CreateStore(src,dst);
572 //st->setVolatile(gIR->func()->inVolatile); 570 //st->setVolatile(gIR->func()->inVolatile);
573 } 571 }
574 572
575 ////////////////////////////////////////////////////////////////////////////////////////// 573 //////////////////////////////////////////////////////////////////////////////////////////