comparison gen/tollvm.cpp @ 365:bfb9d28f045a trunk

[svn r386] Fixed broken DtoBoolean. Some code cleanup.
author lindquist
date Tue, 15 Jul 2008 00:17:03 +0200
parents 8014dbd24605
children d632801b15f0
comparison
equal deleted inserted replaced
364:8014dbd24605 365:bfb9d28f045a
324 return 0; 324 return 0;
325 } 325 }
326 326
327 ////////////////////////////////////////////////////////////////////////////////////////// 327 //////////////////////////////////////////////////////////////////////////////////////////
328 328
329 LLValue* DtoBoolean(DValue* dval)
330 {
331 Type* dtype = dval->getType()->toBasetype();
332 LLValue* val = dval->getRVal();
333 const LLType* t = val->getType();
334
335 if (dtype->isintegral())
336 {
337 if (t == LLType::Int1Ty)
338 return val;
339 else {
340 LLValue* zero = llvm::ConstantInt::get(t, 0, false);
341 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb());
342 }
343 }
344 else if (dtype->iscomplex())
345 {
346 return DtoComplexEquals(TOKnotequal, dval, DtoComplex(dtype, new DNullValue(Type::tint8, llvm::ConstantInt::get(LLType::Int8Ty, 0))));
347 }
348 else if (dtype->isfloating())
349 {
350 LLValue* zero = llvm::Constant::getNullValue(t);
351 return new llvm::FCmpInst(llvm::FCmpInst::FCMP_ONE, val, zero, "tmp", gIR->scopebb());
352 }
353 else if (dtype->ty == Tpointer) {
354 LLValue* zero = llvm::Constant::getNullValue(t);
355 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb());
356 }
357 std::cout << "unsupported -> bool : " << dtype->toChars() << " " << *t << '\n';
358 assert(0);
359 return 0;
360 }
361
362 //////////////////////////////////////////////////////////////////////////////////////////
363
364 const LLType* DtoSize_t() 329 const LLType* DtoSize_t()
365 { 330 {
366 // the type of size_t does not change once set 331 // the type of size_t does not change once set
367 static const LLType* t = NULL; 332 static const LLType* t = NULL;
368 if (t == NULL) 333 if (t == NULL)