comparison gen/llvmhelpers.cpp @ 585:fbb1a366cfbc

Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 09 Sep 2008 16:49:47 -0700
parents 12bda38ea366
children 1ecb43102d12
comparison
equal deleted inserted replaced
584:c7d7e2282ba3 585:fbb1a366cfbc
358 358
359 // is the nested variable in this scope? 359 // is the nested variable in this scope?
360 if (vdparent == irfunc->decl) 360 if (vdparent == irfunc->decl)
361 { 361 {
362 LLValue* val = vd->ir.getIrValue(); 362 LLValue* val = vd->ir.getIrValue();
363 return new DVarValue(astype, vd, val, true); 363 return new DVarValue(astype, vd, val);
364 } 364 }
365 365
366 // get it from the nested context 366 // get it from the nested context
367 LLValue* ctx = 0; 367 LLValue* ctx = 0;
368 if (irfunc->decl->isMember2()) 368 if (irfunc->decl->isMember2())
379 LLValue* val = DtoBitCast(ctx, getPtrToType(getVoidPtrType())); 379 LLValue* val = DtoBitCast(ctx, getPtrToType(getVoidPtrType()));
380 val = DtoGEPi1(val, vd->ir.irLocal->nestedIndex); 380 val = DtoGEPi1(val, vd->ir.irLocal->nestedIndex);
381 val = DtoLoad(val); 381 val = DtoLoad(val);
382 assert(vd->ir.irLocal->value); 382 assert(vd->ir.irLocal->value);
383 val = DtoBitCast(val, vd->ir.irLocal->value->getType(), vd->toChars()); 383 val = DtoBitCast(val, vd->ir.irLocal->value->getType(), vd->toChars());
384 return new DVarValue(astype, vd, val, true); 384 return new DVarValue(astype, vd, val);
385 } 385 }
386 386
387 LLValue* DtoNestedContext(Loc loc, Dsymbol* sym) 387 LLValue* DtoNestedContext(Loc loc, Dsymbol* sym)
388 { 388 {
389 Logger::println("DtoNestedContext for %s", sym->toPrettyChars()); 389 Logger::println("DtoNestedContext for %s", sym->toPrettyChars());
484 Logger::cout() << "r : " << *r << '\n'; 484 Logger::cout() << "r : " << *r << '\n';
485 r = DtoBitCast(r, l->getType()->getContainedType(0)); 485 r = DtoBitCast(r, l->getType()->getContainedType(0));
486 DtoStore(r, l); 486 DtoStore(r, l);
487 } 487 }
488 else if (t->iscomplex()) { 488 else if (t->iscomplex()) {
489 assert(!lhs->isComplex());
490
491 LLValue* dst; 489 LLValue* dst;
492 if (DLRValue* lr = lhs->isLRValue()) { 490 if (DLRValue* lr = lhs->isLRValue()) {
493 dst = lr->getLVal(); 491 dst = lr->getLVal();
494 rhs = DtoCastComplex(loc, rhs, lr->getLType()); 492 rhs = DtoCastComplex(loc, rhs, lr->getLType());
495 } 493 }
496 else { 494 else {
497 dst = lhs->getRVal(); 495 dst = lhs->getLVal();
498 } 496 }
499 497 DtoStore(rhs->getRVal(), dst);
500 if (DComplexValue* cx = rhs->isComplex())
501 DtoComplexSet(dst, cx->re, cx->im);
502 else
503 DtoComplexAssign(dst, rhs->getRVal());
504 } 498 }
505 else { 499 else {
506 LLValue* l = lhs->getLVal(); 500 LLValue* l = lhs->getLVal();
507 LLValue* r = rhs->getRVal(); 501 LLValue* r = rhs->getRVal();
508 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; 502 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
536 530
537 // complex, needs to be first since complex are also floating 531 // complex, needs to be first since complex are also floating
538 if (basetype->iscomplex()) 532 if (basetype->iscomplex())
539 { 533 {
540 const LLType* basefp = DtoComplexBaseType(basetype); 534 const LLType* basefp = DtoComplexBaseType(basetype);
541 return new DComplexValue(type, LLConstant::getNullValue(basefp), LLConstant::getNullValue(basefp)); 535 LLValue* res = DtoAggrPair(DtoType(type), LLConstant::getNullValue(basefp), LLConstant::getNullValue(basefp));
536 return new DImValue(type, res);
542 } 537 }
543 // integer, floating, pointer and class have no special representation 538 // integer, floating, pointer and class have no special representation
544 else if (basetype->isintegral() || basetype->isfloating() || basety == Tpointer || basety == Tclass) 539 else if (basetype->isintegral() || basetype->isfloating() || basety == Tpointer || basety == Tclass)
545 { 540 {
546 return new DConstValue(type, LLConstant::getNullValue(lltype)); 541 return new DConstValue(type, LLConstant::getNullValue(lltype));
788 LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false)); 783 LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false));
789 gIR->ir->CreateCondBr(cond, initbb, endinitbb); 784 gIR->ir->CreateCondBr(cond, initbb, endinitbb);
790 gIR->scope() = IRScope(initbb,endinitbb); 785 gIR->scope() = IRScope(initbb,endinitbb);
791 DValue* ie = DtoInitializer(gvar, init); 786 DValue* ie = DtoInitializer(gvar, init);
792 787
793 DVarValue dst(t, gvar, true); 788 DVarValue dst(t, gvar);
794 DtoAssign(init->loc, &dst, ie); 789 DtoAssign(init->loc, &dst, ie);
795 790
796 gIR->ir->CreateStore(DtoConstBool(true), gflag); 791 gIR->ir->CreateStore(DtoConstBool(true), gflag);
797 gIR->ir->CreateBr(endinitbb); 792 gIR->ir->CreateBr(endinitbb);
798 gIR->scope() = IRScope(endinitbb,oldend); 793 gIR->scope() = IRScope(endinitbb,oldend);
1175 1170
1176 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n'; 1171 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n';
1177 DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init); 1172 DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init);
1178 } 1173 }
1179 1174
1180 return new DVarValue(vd->type, vd, vd->ir.getIrValue(), true); 1175 return new DVarValue(vd->type, vd, vd->ir.getIrValue());
1181 } 1176 }
1182 // struct declaration 1177 // struct declaration
1183 else if (StructDeclaration* s = declaration->isStructDeclaration()) 1178 else if (StructDeclaration* s = declaration->isStructDeclaration())
1184 { 1179 {
1185 Logger::println("StructDeclaration"); 1180 Logger::println("StructDeclaration");